Skip to content

Commit

Permalink
fix: some improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
kobenguyent committed Dec 21, 2023
1 parent e5b872a commit 00e9015
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ module.exports = (config) => {
stepArr.push(step);
});

event.dispatcher.on(event.step.passed, (step, err) => {
event.dispatcher.on(event.step.passed, (step) => {
stepArr.push(step);
});

Expand Down Expand Up @@ -199,20 +199,26 @@ module.exports = (config) => {
for (step of test.testSteps) {
// typo would be fixed by https://github.com/codeceptjs/CodeceptJS/pull/4077
const stepArgs = step.agrs ? step.agrs : step.args;

// if arg is typeof Secret, mask its value, if arg is an object, stringify it, otherwise leave it as it is
const stepTitle = stepArgs ? `[STEP] - ${step.actor} ${step.name} ${JSON.stringify(stepArgs.map(item => item && item._secret ? '*****' : (typeof item === 'object') ? JSON.stringify(item) : item).join(' '))}` : `[STEP] - ${step.actor} ${step.name}`;
let stepTitle = stepArgs ? `[STEP] - ${step.actor} ${step.name} ${JSON.stringify(stepArgs.map(item => item && item._secret ? '*****' : (typeof item === 'object') ? JSON.stringify(item) : item).join(' '))}` : `[STEP] - ${step.actor} ${step.name}`;

// reportportal accepts the step name with length less than 1025
if (stepTitle.length > 1024) {
stepTitle = stepTitle.slice(0, 124);
}

const stepObj = await startTestItem(launchObj.tempId, stepTitle, rp_STEP, test.testTempId);
stepObj.status = step.status || rp_PASSED;
await finishStepItem(stepObj);

if (stepObj.status === 'failed' && step.err) {
await sendLogToRP({ tempId: stepObj.tempId, level: 'ERROR', message: `[FAILED STEP] - ${(step.err.stack ? step.err.stack : JSON.stringify(step.err))}` });
await sendLogToRP({
tempId: stepObj.tempId, level: 'debug', message: 'Last seen screenshot', screenshotData: await attachScreenshot(`${clearString(test.testTitle)}.failed.png`),
});
} else if (stepObj.status === 'failed' && step.helper.currentRunningTest.err) {
await sendLogToRP({ tempId: stepObj.tempId, level: 'ERROR', message: `[FAILED STEP] - ${step.helper.currentRunningTest.err}` });
} else if (stepObj.status === 'failed' && step.test.err) {
await sendLogToRP({ tempId: stepObj.tempId, level: 'ERROR', message: `[FAILED STEP] - ${step.test.err}` });
}

if (helper) {
await sendLogToRP({
tempId: stepObj.tempId, level: 'debug', message: 'Last seen screenshot', screenshotData: await attachScreenshot(`${clearString(test.testTitle)}.failed.png`),
});
Expand Down

0 comments on commit 00e9015

Please sign in to comment.