From f5000504ba22abe35ea0faffd150b6644ff57d99 Mon Sep 17 00:00:00 2001 From: AliakseiLiasnitski <40150869+AliakseiLiasnitski@users.noreply.github.com> Date: Mon, 29 Apr 2024 11:55:11 +0300 Subject: [PATCH] EPMRPP-89652 || Report the last error log to the test description for Vitest agent (#16) --- CHANGELOG.md | 1 + README.md | 1 + src/models/configs.ts | 1 + src/reporter.ts | 8 ++++++++ 4 files changed, 11 insertions(+) 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..0545a11 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, }; @@ -183,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,