mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-16 22:37:09 +01:00
Support parsing multiple reports
This commit is contained in:
parent
659bb4fff3
commit
c48c07640f
15 changed files with 219 additions and 74 deletions
|
|
@ -28,7 +28,7 @@ import {
|
|||
} from '../../report/test-results'
|
||||
|
||||
class TestRun {
|
||||
constructor(readonly suites: TestSuite[], readonly success: boolean, readonly time: number) {}
|
||||
constructor(readonly path: string, readonly suites: TestSuite[], readonly success: boolean, readonly time: number) {}
|
||||
}
|
||||
|
||||
class TestSuite {
|
||||
|
|
@ -69,20 +69,22 @@ class TestCase {
|
|||
}
|
||||
|
||||
export async function parseDartJson(files: FileContent[], options: ParseOptions): Promise<TestResult> {
|
||||
const testRun = getTestRun(files[0].content)
|
||||
const icon = testRun.success ? Icon.success : Icon.fail
|
||||
const testRuns = files.map(f => getTestRun(f.path, f.content))
|
||||
const testRunsResults = testRuns.map(getTestRunResult)
|
||||
const success = testRuns.every(tr => tr.success)
|
||||
const icon = success ? Icon.success : Icon.fail
|
||||
|
||||
return {
|
||||
success: testRun.success,
|
||||
success,
|
||||
output: {
|
||||
title: `${options.name.trim()} ${icon}`,
|
||||
summary: getReport(getTestRunResult(testRun)),
|
||||
annotations: options.annotations ? getAnnotations(testRun, options.workDir, options.trackedFiles) : undefined
|
||||
summary: getReport(testRunsResults),
|
||||
annotations: options.annotations ? getAnnotations(testRuns, options.workDir, options.trackedFiles) : undefined
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getTestRun(content: string): TestRun {
|
||||
function getTestRun(path: string, content: string): TestRun {
|
||||
const lines = content.split(/\n\r?/g).filter(line => line !== '')
|
||||
const events = lines.map(str => JSON.parse(str)) as ReportEvent[]
|
||||
|
||||
|
|
@ -112,7 +114,7 @@ function getTestRun(content: string): TestRun {
|
|||
}
|
||||
}
|
||||
|
||||
return new TestRun(Object.values(suites), success, totalTime)
|
||||
return new TestRun(path, Object.values(suites), success, totalTime)
|
||||
}
|
||||
|
||||
function getTestRunResult(tr: TestRun): TestRunResult {
|
||||
|
|
@ -120,7 +122,7 @@ function getTestRunResult(tr: TestRun): TestRunResult {
|
|||
return new TestSuiteResult(s.suite.path, getGroups(s))
|
||||
})
|
||||
|
||||
return new TestRunResult(suites, tr.time)
|
||||
return new TestRunResult(tr.path, suites, tr.time)
|
||||
}
|
||||
|
||||
function getGroups(suite: TestSuite): TestGroupResult[] {
|
||||
|
|
@ -134,15 +136,17 @@ function getGroups(suite: TestSuite): TestGroupResult[] {
|
|||
})
|
||||
}
|
||||
|
||||
function getAnnotations(tr: TestRun, workDir: string, trackedFiles: string[]): Annotation[] {
|
||||
function getAnnotations(testRuns: TestRun[], workDir: string, trackedFiles: string[]): Annotation[] {
|
||||
const annotations: Annotation[] = []
|
||||
for (const suite of tr.suites) {
|
||||
for (const group of Object.values(suite.groups)) {
|
||||
for (const test of group.tests) {
|
||||
if (test.error) {
|
||||
const err = getAnnotation(test, suite, workDir, trackedFiles)
|
||||
if (err !== null) {
|
||||
annotations.push(err)
|
||||
for (const tr of testRuns) {
|
||||
for (const suite of tr.suites) {
|
||||
for (const group of Object.values(suite.groups)) {
|
||||
for (const test of group.tests) {
|
||||
if (test.error) {
|
||||
const err = getAnnotation(test, suite, workDir, trackedFiles)
|
||||
if (err !== null) {
|
||||
annotations.push(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,26 +42,37 @@ class Test {
|
|||
}
|
||||
|
||||
export async function parseDotnetTrx(files: FileContent[], options: ParseOptions): Promise<TestResult> {
|
||||
const trx = (await parseStringPromise(files[0].content, {
|
||||
attrValueProcessors: [parseAttribute]
|
||||
})) as TrxReport
|
||||
const testRuns: TestRunResult[] = []
|
||||
const testClasses: TestClass[] = []
|
||||
|
||||
const testClasses = getTestClasses(trx)
|
||||
const testRun = getTestRunResult(trx, testClasses)
|
||||
const success = testRun.result === 'success'
|
||||
for (const file of files) {
|
||||
const trx = await getTrxReport(file.content)
|
||||
const tc = getTestClasses(trx)
|
||||
const tr = getTestRunResult(file.path, trx, tc)
|
||||
testRuns.push(tr)
|
||||
testClasses.push(...tc)
|
||||
}
|
||||
|
||||
const success = testRuns.every(tr => tr.result === 'success')
|
||||
const icon = success ? Icon.success : Icon.fail
|
||||
|
||||
return {
|
||||
success,
|
||||
output: {
|
||||
title: `${options.name.trim()} ${icon}`,
|
||||
summary: getReport(testRun),
|
||||
summary: getReport(testRuns),
|
||||
annotations: options.annotations ? getAnnotations(testClasses, options.workDir, options.trackedFiles) : undefined
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getTestRunResult(trx: TrxReport, testClasses: TestClass[]): TestRunResult {
|
||||
async function getTrxReport(content: string): Promise<TrxReport> {
|
||||
return (await parseStringPromise(content, {
|
||||
attrValueProcessors: [parseAttribute]
|
||||
})) as TrxReport
|
||||
}
|
||||
|
||||
function getTestRunResult(path: string, trx: TrxReport, testClasses: TestClass[]): TestRunResult {
|
||||
const times = trx.TestRun.Times[0].$
|
||||
const totalTime = times.finish.getTime() - times.start.getTime()
|
||||
|
||||
|
|
@ -71,7 +82,7 @@ function getTestRunResult(trx: TrxReport, testClasses: TestClass[]): TestRunResu
|
|||
return new TestSuiteResult(tc.name, [group])
|
||||
})
|
||||
|
||||
return new TestRunResult(suites, totalTime)
|
||||
return new TestRunResult(path, suites, totalTime)
|
||||
}
|
||||
|
||||
function getTestClasses(trx: TrxReport): TestClass[] {
|
||||
|
|
|
|||
|
|
@ -16,24 +16,36 @@ import {
|
|||
import getReport from '../../report/get-report'
|
||||
|
||||
export async function parseJestJunit(files: FileContent[], options: ParseOptions): Promise<TestResult> {
|
||||
const junit = (await parseStringPromise(files[0].content, {
|
||||
attrValueProcessors: [parseAttribute]
|
||||
})) as JunitReport
|
||||
const testsuites = junit.testsuites
|
||||
const success = !(testsuites.$?.failures > 0 || testsuites.$?.errors > 0)
|
||||
const junit: JunitReport[] = []
|
||||
const testRuns: TestRunResult[] = []
|
||||
|
||||
for (const file of files) {
|
||||
const ju = await getJunitReport(file.content)
|
||||
const tr = getTestRunResult(file.path, ju)
|
||||
junit.push(ju)
|
||||
testRuns.push(tr)
|
||||
}
|
||||
|
||||
const success = testRuns.every(tr => tr.result === 'success')
|
||||
const icon = success ? Icon.success : Icon.fail
|
||||
|
||||
return {
|
||||
success,
|
||||
output: {
|
||||
title: `${options.name.trim()} ${icon}`,
|
||||
summary: getSummary(junit),
|
||||
summary: getReport(testRuns),
|
||||
annotations: options.annotations ? getAnnotations(junit, options.workDir, options.trackedFiles) : undefined
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getSummary(junit: JunitReport): string {
|
||||
async function getJunitReport(content: string): Promise<JunitReport> {
|
||||
return (await parseStringPromise(content, {
|
||||
attrValueProcessors: [parseAttribute]
|
||||
})) as JunitReport
|
||||
}
|
||||
|
||||
function getTestRunResult(path: string, junit: JunitReport): TestRunResult {
|
||||
const suites = junit.testsuites.testsuite.map(ts => {
|
||||
const name = ts.$.name.trim()
|
||||
const time = ts.$.time * 1000
|
||||
|
|
@ -42,8 +54,7 @@ function getSummary(junit: JunitReport): string {
|
|||
})
|
||||
|
||||
const time = junit.testsuites.$.time * 1000
|
||||
const tr = new TestRunResult(suites, time)
|
||||
return getReport(tr)
|
||||
return new TestRunResult(path, suites, time)
|
||||
}
|
||||
|
||||
function getGroups(suite: TestSuite): TestGroupResult[] {
|
||||
|
|
@ -74,26 +85,28 @@ function getTestCaseResult(test: TestCase): TestExecutionResult {
|
|||
return 'success'
|
||||
}
|
||||
|
||||
function getAnnotations(junit: JunitReport, workDir: string, trackedFiles: string[]): Annotation[] {
|
||||
function getAnnotations(junitReports: JunitReport[], workDir: string, trackedFiles: string[]): Annotation[] {
|
||||
const annotations: Annotation[] = []
|
||||
for (const suite of junit.testsuites.testsuite) {
|
||||
for (const tc of suite.testcase) {
|
||||
if (!tc.failure) {
|
||||
continue
|
||||
}
|
||||
for (const ex of tc.failure) {
|
||||
const src = exceptionThrowSource(ex, workDir, trackedFiles)
|
||||
if (src === null) {
|
||||
for (const junit of junitReports) {
|
||||
for (const suite of junit.testsuites.testsuite) {
|
||||
for (const tc of suite.testcase) {
|
||||
if (!tc.failure) {
|
||||
continue
|
||||
}
|
||||
annotations.push({
|
||||
annotation_level: 'failure',
|
||||
start_line: src.line,
|
||||
end_line: src.line,
|
||||
path: src.file,
|
||||
message: fixEol(ex),
|
||||
title: `[${suite.$.name}] ${tc.$.name.trim()}`
|
||||
})
|
||||
for (const ex of tc.failure) {
|
||||
const src = exceptionThrowSource(ex, workDir, trackedFiles)
|
||||
if (src === null) {
|
||||
continue
|
||||
}
|
||||
annotations.push({
|
||||
annotation_level: 'failure',
|
||||
start_line: src.line,
|
||||
end_line: src.line,
|
||||
path: src.file,
|
||||
message: fixEol(ex),
|
||||
title: `[${suite.$.name}] ${tc.$.name.trim()}`
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue