From e547f77a446d96f2a58266418d91697a82905462 Mon Sep 17 00:00:00 2001 From: kobenguyent Date: Thu, 21 Dec 2023 11:42:18 +0100 Subject: [PATCH 1/3] fix: handle joi schema object --- lib/actor.js | 3 ++- lib/command/workers/runTests.js | 5 +++++ lib/step.js | 3 ++- lib/utils.js | 13 +++++++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/actor.js b/lib/actor.js index 5b4332b68..3083f65e4 100644 --- a/lib/actor.js +++ b/lib/actor.js @@ -6,6 +6,7 @@ const recorder = require('./recorder'); const event = require('./event'); const store = require('./store'); const output = require('./output'); +const { serializeStepArgs } = require('./utils'); /** * @interface @@ -117,8 +118,8 @@ module.exports = function (obj = {}) { }; function recordStep(step, args) { + if (args && args.length > 0) args = serializeStepArgs(args); step.status = 'queued'; - step.setArguments(args); // run async before step hooks event.emit(event.step.before, step); diff --git a/lib/command/workers/runTests.js b/lib/command/workers/runTests.js index d444b183f..6b49b3a89 100644 --- a/lib/command/workers/runTests.js +++ b/lib/command/workers/runTests.js @@ -12,6 +12,7 @@ const event = require('../../event'); const container = require('../../container'); const { getConfig } = require('../utils'); const { tryOrDefault, deepMerge } = require('../../utils'); +const { serializeStepArgs } = require('../../utils'); // eslint-disable-next-line no-unused-vars let stdout = ''; @@ -159,6 +160,10 @@ function initializeListeners() { } function simplifyStep(step, err = null) { + if (step.args) { + step.args = serializeStepArgs(step.args); + } + step = { ...step }; if (step.startTime && !step.duration) { diff --git a/lib/step.js b/lib/step.js index f57dc2dc8..f96877b9a 100644 --- a/lib/step.js +++ b/lib/step.js @@ -3,6 +3,7 @@ const store = require('./store'); const Secret = require('./secret'); const event = require('./event'); +const { serializeStepArgs } = require('./utils'); const STACK_LINE = 4; @@ -104,7 +105,7 @@ class Step { /** @param {Array<*>} args */ setArguments(args) { - this.args = args; + this.args = serializeStepArgs(args); } /** diff --git a/lib/utils.js b/lib/utils.js index 4cfaeecb1..bcbd71af1 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -476,3 +476,16 @@ module.exports.printObjectProperties = (obj) => { module.exports.normalizeSpacesInString = (string) => { return string.replace(/\s+/g, ' '); }; + +module.exports.serializeStepArgs = function (stepArgs) { + const _res = stepArgs.map(item => { + if (item) { + if (item && item._secret) return '*****'; + if (item.type === 'object' && item.$_root) return 'Joi schema'; + if (typeof item === 'object') return JSON.stringify(item); + } + return item; + }); + + return _res; +}; From c6e6602d5fdb338a4c3995aa128c2227fb5bfc96 Mon Sep 17 00:00:00 2001 From: kobenguyent Date: Fri, 22 Dec 2023 17:54:30 +0100 Subject: [PATCH 2/3] fix: joi args in step when running with workers --- lib/actor.js | 2 -- lib/command/workers/runTests.js | 15 +++++++++------ lib/step.js | 3 +-- lib/utils.js | 13 ------------- 4 files changed, 10 insertions(+), 23 deletions(-) diff --git a/lib/actor.js b/lib/actor.js index 3083f65e4..d1fa12d18 100644 --- a/lib/actor.js +++ b/lib/actor.js @@ -6,7 +6,6 @@ const recorder = require('./recorder'); const event = require('./event'); const store = require('./store'); const output = require('./output'); -const { serializeStepArgs } = require('./utils'); /** * @interface @@ -118,7 +117,6 @@ module.exports = function (obj = {}) { }; function recordStep(step, args) { - if (args && args.length > 0) args = serializeStepArgs(args); step.status = 'queued'; // run async before step hooks diff --git a/lib/command/workers/runTests.js b/lib/command/workers/runTests.js index 6b49b3a89..a2ea9e409 100644 --- a/lib/command/workers/runTests.js +++ b/lib/command/workers/runTests.js @@ -12,7 +12,6 @@ const event = require('../../event'); const container = require('../../container'); const { getConfig } = require('../utils'); const { tryOrDefault, deepMerge } = require('../../utils'); -const { serializeStepArgs } = require('../../utils'); // eslint-disable-next-line no-unused-vars let stdout = ''; @@ -142,11 +141,19 @@ function initializeListeners() { const _steps = []; for (step of steps) { + const _args = []; + + if (step.args) { + for (const arg of step.args) { + arg && arg.$_root ? _args.push(JSON.stringify(arg).slice(0, 300)) : _args.push(arg); + } + } + _steps.push({ actor: step.actor, name: step.name, status: step.status, - args: step.args, + agrs: _args, startedAt: step.startedAt, startTime: step.startTime, endTime: step.endTime, @@ -160,10 +167,6 @@ function initializeListeners() { } function simplifyStep(step, err = null) { - if (step.args) { - step.args = serializeStepArgs(step.args); - } - step = { ...step }; if (step.startTime && !step.duration) { diff --git a/lib/step.js b/lib/step.js index f96877b9a..f57dc2dc8 100644 --- a/lib/step.js +++ b/lib/step.js @@ -3,7 +3,6 @@ const store = require('./store'); const Secret = require('./secret'); const event = require('./event'); -const { serializeStepArgs } = require('./utils'); const STACK_LINE = 4; @@ -105,7 +104,7 @@ class Step { /** @param {Array<*>} args */ setArguments(args) { - this.args = serializeStepArgs(args); + this.args = args; } /** diff --git a/lib/utils.js b/lib/utils.js index bcbd71af1..4cfaeecb1 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -476,16 +476,3 @@ module.exports.printObjectProperties = (obj) => { module.exports.normalizeSpacesInString = (string) => { return string.replace(/\s+/g, ' '); }; - -module.exports.serializeStepArgs = function (stepArgs) { - const _res = stepArgs.map(item => { - if (item) { - if (item && item._secret) return '*****'; - if (item.type === 'object' && item.$_root) return 'Joi schema'; - if (typeof item === 'object') return JSON.stringify(item); - } - return item; - }); - - return _res; -}; From 440e441efbfdf2cdf31061f847c4ab86776adaac Mon Sep 17 00:00:00 2001 From: kobenguyent Date: Fri, 22 Dec 2023 17:58:12 +0100 Subject: [PATCH 3/3] fix: joi args in step when running with workers --- lib/actor.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/actor.js b/lib/actor.js index d1fa12d18..5b4332b68 100644 --- a/lib/actor.js +++ b/lib/actor.js @@ -118,6 +118,7 @@ module.exports = function (obj = {}) { function recordStep(step, args) { step.status = 'queued'; + step.setArguments(args); // run async before step hooks event.emit(event.step.before, step);