diff --git a/action.yml b/action.yml index 7777d56..a3fce85 100644 --- a/action.yml +++ b/action.yml @@ -111,6 +111,8 @@ outputs: description: Check run URL url_html: description: Check run URL HTML + summary: + description: The raw generated summary runs: using: 'node20' main: 'dist/index.js' diff --git a/dist/index.js b/dist/index.js index 10200e5..e13250d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -419,6 +419,7 @@ class TestReporter { }); core.info('Summary content:'); core.info(summary); + core.setOutput('summary', summary); core.summary.addRaw(`# ${shortSummary}`); await core.summary.addRaw(summary).write(); } @@ -958,7 +959,8 @@ class DotnetTrxParser { } } getTestClasses(trx) { - if (trx.TestRun.TestDefinitions === undefined || trx.TestRun.Results === undefined || + if (trx.TestRun.TestDefinitions === undefined || + trx.TestRun.Results === undefined || !trx.TestRun.TestDefinitions.some(td => td.UnitTest && Array.isArray(td.UnitTest))) { return []; } @@ -974,7 +976,7 @@ class DotnetTrxParser { })); const testClasses = {}; for (const r of unitTestsResults) { - const className = r.test.TestMethod[0].$.className ?? "Unclassified"; + const className = r.test.TestMethod[0].$.className ?? 'Unclassified'; let tc = testClasses[className]; if (tc === undefined) { tc = new TestClass(className); @@ -1091,7 +1093,10 @@ class GolangJsonParser { return this.getTestRunResult(path, events); } async getGolangTestEvents(path, content) { - return content.trim().split('\n').map((line, index) => { + return content + .trim() + .split('\n') + .map((line, index) => { try { return JSON.parse(line); } @@ -1139,9 +1144,7 @@ class GolangJsonParser { suite.groups.push(group); } const lastEvent = eventGroup.at(-1); - const result = lastEvent.Action === 'pass' ? 'success' - : lastEvent.Action === 'skip' ? 'skipped' - : 'failed'; + const result = lastEvent.Action === 'pass' ? 'success' : lastEvent.Action === 'skip' ? 'skipped' : 'failed'; if (lastEvent.Elapsed === undefined) { throw new Error('missing elapsed on final test event'); } diff --git a/src/main.ts b/src/main.ts index 57137ab..42ca481 100644 --- a/src/main.ts +++ b/src/main.ts @@ -187,6 +187,7 @@ class TestReporter { core.info('Summary content:') core.info(summary) + core.setOutput('summary', summary) core.summary.addRaw(`# ${shortSummary}`) await core.summary.addRaw(summary).write() } else { @@ -270,4 +271,4 @@ class TestReporter { } } -main() +main() \ No newline at end of file diff --git a/src/parsers/dotnet-trx/dotnet-trx-parser.ts b/src/parsers/dotnet-trx/dotnet-trx-parser.ts index 48a383f..4425224 100644 --- a/src/parsers/dotnet-trx/dotnet-trx-parser.ts +++ b/src/parsers/dotnet-trx/dotnet-trx-parser.ts @@ -62,8 +62,11 @@ export class DotnetTrxParser implements TestParser { } private getTestClasses(trx: TrxReport): TestClass[] { - if (trx.TestRun.TestDefinitions === undefined || trx.TestRun.Results === undefined || - !trx.TestRun.TestDefinitions.some(td => td.UnitTest && Array.isArray(td.UnitTest))) { + if ( + trx.TestRun.TestDefinitions === undefined || + trx.TestRun.Results === undefined || + !trx.TestRun.TestDefinitions.some(td => td.UnitTest && Array.isArray(td.UnitTest)) + ) { return [] } @@ -81,7 +84,7 @@ export class DotnetTrxParser implements TestParser { const testClasses: {[name: string]: TestClass} = {} for (const r of unitTestsResults) { - const className = r.test.TestMethod[0].$.className ?? "Unclassified" + const className = r.test.TestMethod[0].$.className ?? 'Unclassified' let tc = testClasses[className] if (tc === undefined) { tc = new TestClass(className) diff --git a/src/parsers/golang-json/golang-json-parser.ts b/src/parsers/golang-json/golang-json-parser.ts index bc20821..8a72231 100644 --- a/src/parsers/golang-json/golang-json-parser.ts +++ b/src/parsers/golang-json/golang-json-parser.ts @@ -1,8 +1,8 @@ -import { ParseOptions, TestParser } from '../../test-parser' +import {ParseOptions, TestParser} from '../../test-parser' -import { GoTestEvent } from './golang-json-types' -import { getExceptionSource } from '../../utils/node-utils' -import { getBasePath, normalizeFilePath } from '../../utils/path-utils' +import {GoTestEvent} from './golang-json-types' +import {getExceptionSource} from '../../utils/node-utils' +import {getBasePath, normalizeFilePath} from '../../utils/path-utils' import { TestExecutionResult, @@ -16,7 +16,7 @@ import { export class GolangJsonParser implements TestParser { assumedWorkDir: string | undefined - constructor(readonly options: ParseOptions) { } + constructor(readonly options: ParseOptions) {} async parse(path: string, content: string): Promise { const events = await this.getGolangTestEvents(path, content) @@ -24,13 +24,16 @@ export class GolangJsonParser implements TestParser { } private async getGolangTestEvents(path: string, content: string): Promise { - return content.trim().split('\n').map((line, index) => { - try { - return JSON.parse(line) as GoTestEvent - } catch (e) { - throw new Error(`Invalid JSON at ${path} line ${index + 1}\n\n${e}`) - } - }) + return content + .trim() + .split('\n') + .map((line, index) => { + try { + return JSON.parse(line) as GoTestEvent + } catch (e) { + throw new Error(`Invalid JSON at ${path} line ${index + 1}\n\n${e}`) + } + }) } private getTestRunResult(path: string, events: GoTestEvent[]): TestRunResult { @@ -65,7 +68,7 @@ export class GolangJsonParser implements TestParser { let groupName: string | null let rest: string[] - [groupName, ...rest] = event.Test.split('/') + ;[groupName, ...rest] = event.Test.split('/') let testName = rest.join('/') if (!testName) { testName = groupName @@ -80,9 +83,8 @@ export class GolangJsonParser implements TestParser { const lastEvent = eventGroup.at(-1)! - const result: TestExecutionResult = lastEvent.Action === 'pass' ? 'success' - : lastEvent.Action === 'skip' ? 'skipped' - : 'failed' + const result: TestExecutionResult = + lastEvent.Action === 'pass' ? 'success' : lastEvent.Action === 'skip' ? 'skipped' : 'failed' if (lastEvent.Elapsed === undefined) { throw new Error('missing elapsed on final test event') } diff --git a/src/parsers/golang-json/golang-json-types.ts b/src/parsers/golang-json/golang-json-types.ts index f27fa86..d714dfe 100644 --- a/src/parsers/golang-json/golang-json-types.ts +++ b/src/parsers/golang-json/golang-json-types.ts @@ -1,12 +1,4 @@ -export type GoTestAction = 'start' - | 'run' - | 'pause' - | 'cont' - | 'pass' - | 'bench' - | 'fail' - | 'output' - | 'skip' +export type GoTestAction = 'start' | 'run' | 'pause' | 'cont' | 'pass' | 'bench' | 'fail' | 'output' | 'skip' export type GoTestEvent = { Time: string