mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-15 13:57:09 +01:00
Merge eb2310cec8 into bc8c29617e
This commit is contained in:
commit
88f10e9226
6 changed files with 38 additions and 35 deletions
|
|
@ -119,6 +119,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'
|
||||
|
|
|
|||
15
dist/index.js
generated
vendored
15
dist/index.js
generated
vendored
|
|
@ -425,6 +425,7 @@ class TestReporter {
|
|||
});
|
||||
core.info('Summary content:');
|
||||
core.info(summary);
|
||||
core.setOutput('summary', summary);
|
||||
core.summary.addRaw(`# ${shortSummary}`);
|
||||
await core.summary.addRaw(summary).write();
|
||||
}
|
||||
|
|
@ -965,7 +966,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 [];
|
||||
}
|
||||
|
|
@ -981,7 +983,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);
|
||||
|
|
@ -1098,7 +1100,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);
|
||||
}
|
||||
|
|
@ -1146,9 +1151,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');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -194,6 +194,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 {
|
||||
|
|
@ -278,4 +279,4 @@ class TestReporter {
|
|||
}
|
||||
}
|
||||
|
||||
main()
|
||||
main()
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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<TestRunResult> {
|
||||
const events = await this.getGolangTestEvents(path, content)
|
||||
|
|
@ -24,13 +24,16 @@ export class GolangJsonParser implements TestParser {
|
|||
}
|
||||
|
||||
private async getGolangTestEvents(path: string, content: string): Promise<GoTestEvent[]> {
|
||||
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')
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue