From d41808b478193ecd54d56183894dd3fd8fcf06a7 Mon Sep 17 00:00:00 2001 From: dboriichuk Date: Tue, 15 Oct 2024 12:08:17 +0300 Subject: [PATCH 1/4] Include stack trace into summary --- src/main.ts | 5 +++-- src/report/get-report.ts | 14 +++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main.ts b/src/main.ts index 732d839..4d81413 100644 --- a/src/main.ts +++ b/src/main.ts @@ -54,6 +54,7 @@ class TestReporter { readonly workDirInput = core.getInput('working-directory', {required: false}) readonly onlySummary = core.getInput('only-summary', {required: false}) === 'true' readonly outputTo = core.getInput('output-to', {required: false}) + readonly stackTraceInSummary = this.outputTo === 'step-summary' ? true : false readonly token = core.getInput('token', {required: true}) readonly slugPrefix: string = '' readonly octokit: InstanceType @@ -205,8 +206,8 @@ class TestReporter { } core.info('Creating report summary') - const {listSuites, listTests, onlySummary, slugPrefix} = this - const summary = getReport(results, {listSuites, listTests, baseUrl, slugPrefix, onlySummary}) + const {listSuites, listTests, onlySummary, slugPrefix, stackTraceInSummary} = this + const summary = getReport(results, {listSuites, listTests, baseUrl, slugPrefix, onlySummary, stackTraceInSummary}) core.info('Creating annotations') const annotations = getAnnotations(results, this.maxAnnotations) diff --git a/src/report/get-report.ts b/src/report/get-report.ts index fb90f01..7ae6d06 100644 --- a/src/report/get-report.ts +++ b/src/report/get-report.ts @@ -12,6 +12,7 @@ export interface ReportOptions { slugPrefix: string baseUrl: string onlySummary: boolean + stackTraceInSummary: boolean } const defaultOptions: ReportOptions = { @@ -19,7 +20,8 @@ const defaultOptions: ReportOptions = { listTests: 'all', slugPrefix: '', baseUrl: '', - onlySummary: false + onlySummary: false, + stackTraceInSummary: false } export function getReport(results: TestRunResult[], options: ReportOptions = defaultOptions): string { @@ -239,8 +241,14 @@ function getTestsReport(ts: TestSuiteResult, runIndex: number, suiteIndex: numbe const result = getResultIcon(tc.result) sections.push(`${space}${result} ${tc.name}`) if (tc.error) { - const lines = (tc.error.message ?? getFirstNonEmptyLine(tc.error.details)?.trim()) - ?.split(/\r?\n/g) + let errorData = '' + if (options.stackTraceInSummary) { + errorData = tc.error.details ?? '' + } else { + errorData = tc.error.message ?? getFirstNonEmptyLine(tc.error.details)?.trim() ?? '' + } + const lines = errorData + .split(/\r?\n/g) .map(l => '\t' + l) if (lines) { sections.push(...lines) From 1d2517c9e31d3345f21cd3e6954f3f02adef021d Mon Sep 17 00:00:00 2001 From: dboriichuk Date: Tue, 15 Oct 2024 12:30:13 +0300 Subject: [PATCH 2/4] fix linter --- src/report/get-report.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/report/get-report.ts b/src/report/get-report.ts index 7ae6d06..d38506c 100644 --- a/src/report/get-report.ts +++ b/src/report/get-report.ts @@ -247,9 +247,7 @@ function getTestsReport(ts: TestSuiteResult, runIndex: number, suiteIndex: numbe } else { errorData = tc.error.message ?? getFirstNonEmptyLine(tc.error.details)?.trim() ?? '' } - const lines = errorData - .split(/\r?\n/g) - .map(l => '\t' + l) + const lines = errorData.split(/\r?\n/g).map(l => '\t' + l) if (lines) { sections.push(...lines) } From d62f883d09dadbbc462b9c9dcfd01da56946d4f8 Mon Sep 17 00:00:00 2001 From: dboriichuk Date: Tue, 15 Oct 2024 12:31:12 +0300 Subject: [PATCH 3/4] fix test --- __tests__/dotnet-trx.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/__tests__/dotnet-trx.test.ts b/__tests__/dotnet-trx.test.ts index c10b997..d480d22 100644 --- a/__tests__/dotnet-trx.test.ts +++ b/__tests__/dotnet-trx.test.ts @@ -65,7 +65,8 @@ describe('dotnet-trx tests', () => { listTests: 'failed', onlySummary: false, slugPrefix: '', - baseUrl: '' + baseUrl: '', + stackTraceInSummary: true } const report = getReport([result], reportOptions) fs.mkdirSync(path.dirname(outputPath), {recursive: true}) From 24c169929207fed5c72405125f057bee043c5e9d Mon Sep 17 00:00:00 2001 From: dboriichuk Date: Tue, 15 Oct 2024 12:32:50 +0300 Subject: [PATCH 4/4] do not include stack trace in test --- __tests__/dotnet-trx.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__tests__/dotnet-trx.test.ts b/__tests__/dotnet-trx.test.ts index d480d22..ba225c4 100644 --- a/__tests__/dotnet-trx.test.ts +++ b/__tests__/dotnet-trx.test.ts @@ -66,7 +66,7 @@ describe('dotnet-trx tests', () => { onlySummary: false, slugPrefix: '', baseUrl: '', - stackTraceInSummary: true + stackTraceInSummary: false } const report = getReport([result], reportOptions) fs.mkdirSync(path.dirname(outputPath), {recursive: true})