From 47d1d403b5774ce38b9a4655ba77f24555c9e23c Mon Sep 17 00:00:00 2001 From: AliakseiLiasnitski Date: Sat, 6 Apr 2024 15:47:03 +0300 Subject: [PATCH 1/3] EPMRPP-89652 || Report the last error log to the test description for Vitest agent --- CHANGELOG.md | 1 + README.md | 1 + src/models/configs.ts | 1 + src/reporter.ts | 8 +++++++- 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e421edf..bd31837 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ### Added - ReportingApi with attachment support +- `extendTestDescriptionWithLastError` option to the RP config to be able to toggle the last error log attaching to the test description. ## [5.0.0] - 2024-02-15 ### Added diff --git a/README.md b/README.md index cb6d8e7..9930975 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,7 @@ The full list of available options presented below. | restClientConfig | Optional | Not set | The object with `agent` property for configure [http(s)](https://nodejs.org/api/https.html#https_https_request_url_options_callback) client, may contain other client options eg. [`timeout`](https://github.com/reportportal/client-javascript#timeout-30000ms-on-axios-requests).
Visit [client-javascript](https://github.com/reportportal/client-javascript) for more details. | | launchUuidPrint | Optional | false | Whether to print the current launch UUID. | | launchUuidPrintOutput | Optional | 'STDOUT' | Launch UUID printing output. Possible values: 'STDOUT', 'STDERR'. Works only if `launchUuidPrint` set to `true`. | +| extendTestDescriptionWithLastError | Optional | true | If set to `true` the latest error log will be attached to the test case description. | The following options can be overridden using ENVIRONMENT variables: diff --git a/src/models/configs.ts b/src/models/configs.ts index 2e37334..c1c4301 100644 --- a/src/models/configs.ts +++ b/src/models/configs.ts @@ -48,4 +48,5 @@ export interface ReportPortalConfig extends ClientConfig { // agent specific options skippedIssue?: boolean; + extendTestDescriptionWithLastError?: boolean; } diff --git a/src/reporter.ts b/src/reporter.ts index d4de89e..35dc307 100644 --- a/src/reporter.ts +++ b/src/reporter.ts @@ -70,6 +70,7 @@ export class RPReporter implements Reporter { constructor(config: ReportPortalConfig) { this.config = { + extendTestDescriptionWithLastError: true, ...config, launchId: process.env.RP_LAUNCH_ID || config.launchId, }; @@ -207,7 +208,7 @@ export class RPReporter implements Reporter { }; if (taskResult) { - const { state, startTime, duration } = taskResult; + const { state, startTime, duration, errors } = taskResult; switch (state) { case TASK_STATUS.pass: @@ -223,6 +224,11 @@ export class RPReporter implements Reporter { default: break; } + + if (errors?.length && this.config.extendTestDescriptionWithLastError) { + const { stack } = taskResult.errors[0]; + finishTestItemObj.description = (finishTestItemObj.description || '').concat(`\n\`\`\`error\n${stack}\n\`\`\``); + } } return finishTestItemObj; From f71d054ce796f430405cdd82cd3ce88c39d463cc Mon Sep 17 00:00:00 2001 From: AliakseiLiasnitski Date: Sat, 6 Apr 2024 15:51:43 +0300 Subject: [PATCH 2/3] EPMRPP-89652 || Fix lint errors --- src/reporter.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/reporter.ts b/src/reporter.ts index 35dc307..4e7e551 100644 --- a/src/reporter.ts +++ b/src/reporter.ts @@ -227,7 +227,9 @@ export class RPReporter implements Reporter { if (errors?.length && this.config.extendTestDescriptionWithLastError) { const { stack } = taskResult.errors[0]; - finishTestItemObj.description = (finishTestItemObj.description || '').concat(`\n\`\`\`error\n${stack}\n\`\`\``); + finishTestItemObj.description = (finishTestItemObj.description || '').concat( + `\n\`\`\`error\n${stack}\n\`\`\``, + ); } } From c4b5bb9608313e9b297b605fbbd02de2ce5860a8 Mon Sep 17 00:00:00 2001 From: AliakseiLiasnitski Date: Fri, 19 Apr 2024 15:25:10 +0300 Subject: [PATCH 3/3] RPP_89652 || move update description logic from getFinishTestItemObj to onTaskUpdate --- src/reporter.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/reporter.ts b/src/reporter.ts index 4e7e551..0545a11 100644 --- a/src/reporter.ts +++ b/src/reporter.ts @@ -184,6 +184,13 @@ export class RPReporter implements Reporter { if (taskResult?.errors?.length) { const error = taskResult.errors[0]; + + if (this.config.extendTestDescriptionWithLastError) { + finishTestItemObj.description = (finishTestItemObj.description || '').concat( + `\n\`\`\`error\n${error.stack}\n\`\`\``, + ); + } + const logRq: LogRQ = { time: finishTestItemObj.endTime, level: LOG_LEVELS.ERROR, @@ -208,7 +215,7 @@ export class RPReporter implements Reporter { }; if (taskResult) { - const { state, startTime, duration, errors } = taskResult; + const { state, startTime, duration } = taskResult; switch (state) { case TASK_STATUS.pass: @@ -224,13 +231,6 @@ export class RPReporter implements Reporter { default: break; } - - if (errors?.length && this.config.extendTestDescriptionWithLastError) { - const { stack } = taskResult.errors[0]; - finishTestItemObj.description = (finishTestItemObj.description || '').concat( - `\n\`\`\`error\n${stack}\n\`\`\``, - ); - } } return finishTestItemObj;