mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-16 14:27:10 +01:00
Refactoring: parsers share markdown report generation
This commit is contained in:
parent
64b8f12bbc
commit
4e2ae7493f
4 changed files with 219 additions and 189 deletions
|
|
@ -1,8 +1,8 @@
|
||||||
import {Annotation, ParseOptions, TestResult} from '../parser-types'
|
import {Annotation, ParseOptions, TestResult} from '../parser-types'
|
||||||
|
|
||||||
|
import getReport from '../../report/get-report'
|
||||||
import {normalizeFilePath} from '../../utils/file-utils'
|
import {normalizeFilePath} from '../../utils/file-utils'
|
||||||
import {Align, Icon, link, table} from '../../utils/markdown-utils'
|
import {Icon} from '../../utils/markdown-utils'
|
||||||
import {slug} from '../../utils/slugger'
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
ReportEvent,
|
ReportEvent,
|
||||||
|
|
@ -19,60 +19,26 @@ import {
|
||||||
isDoneEvent
|
isDoneEvent
|
||||||
} from './dart-json-types'
|
} from './dart-json-types'
|
||||||
|
|
||||||
|
import {
|
||||||
|
TestExecutionResult,
|
||||||
|
TestRunResult,
|
||||||
|
TestSuiteResult,
|
||||||
|
TestGroupResult,
|
||||||
|
TestCaseResult
|
||||||
|
} from '../../report/test-results'
|
||||||
|
|
||||||
class TestRun {
|
class TestRun {
|
||||||
constructor(readonly suites: TestSuite[], readonly success: boolean, readonly time: number) {}
|
constructor(readonly suites: TestSuite[], readonly success: boolean, readonly time: number) {}
|
||||||
get count(): number {
|
|
||||||
return Object.values(this.suites).reduce((sum, g) => sum + g.count, 0)
|
|
||||||
}
|
|
||||||
get passed(): number {
|
|
||||||
return Object.values(this.suites).reduce((sum, g) => sum + g.passed, 0)
|
|
||||||
}
|
|
||||||
get failed(): number {
|
|
||||||
return Object.values(this.suites).reduce((sum, g) => sum + g.failed, 0)
|
|
||||||
}
|
|
||||||
get skipped(): number {
|
|
||||||
return Object.values(this.suites).reduce((sum, g) => sum + g.skipped, 0)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class TestSuite {
|
class TestSuite {
|
||||||
constructor(readonly suite: Suite) {}
|
constructor(readonly suite: Suite) {}
|
||||||
groups: {[id: number]: TestGroup} = {}
|
readonly groups: {[id: number]: TestGroup} = {}
|
||||||
get count(): number {
|
|
||||||
return Object.values(this.groups).reduce((sum, g) => sum + g.count, 0)
|
|
||||||
}
|
|
||||||
get passed(): number {
|
|
||||||
return Object.values(this.groups).reduce((sum, g) => sum + g.passed, 0)
|
|
||||||
}
|
|
||||||
get failed(): number {
|
|
||||||
return Object.values(this.groups).reduce((sum, g) => sum + g.failed, 0)
|
|
||||||
}
|
|
||||||
get skipped(): number {
|
|
||||||
return Object.values(this.groups).reduce((sum, g) => sum + g.skipped, 0)
|
|
||||||
}
|
|
||||||
get time(): number {
|
|
||||||
return Object.values(this.groups).reduce((sum, g) => sum + g.time, 0)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class TestGroup {
|
class TestGroup {
|
||||||
constructor(readonly group: Group) {}
|
constructor(readonly group: Group) {}
|
||||||
tests: TestCase[] = []
|
readonly tests: TestCase[] = []
|
||||||
get count(): number {
|
|
||||||
return this.tests.length
|
|
||||||
}
|
|
||||||
get passed(): number {
|
|
||||||
return this.tests.reduce((sum, t) => (t.isPassed ? sum + 1 : sum), 0)
|
|
||||||
}
|
|
||||||
get failed(): number {
|
|
||||||
return this.tests.reduce((sum, t) => (t.isFailed ? sum + 1 : sum), 0)
|
|
||||||
}
|
|
||||||
get skipped(): number {
|
|
||||||
return this.tests.reduce((sum, t) => (t.isSkipped ? sum + 1 : sum), 0)
|
|
||||||
}
|
|
||||||
get time(): number {
|
|
||||||
return this.tests.reduce((sum, t) => sum + t.time, 0)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class TestCase {
|
class TestCase {
|
||||||
|
|
@ -82,15 +48,21 @@ class TestCase {
|
||||||
readonly groupId: number
|
readonly groupId: number
|
||||||
testDone?: TestDoneEvent
|
testDone?: TestDoneEvent
|
||||||
error?: ErrorEvent
|
error?: ErrorEvent
|
||||||
get isPassed(): boolean {
|
get result(): TestExecutionResult {
|
||||||
return this.testDone?.result === 'success' && !this.testDone?.skipped
|
if (this.testDone?.skipped) {
|
||||||
}
|
return 'skipped'
|
||||||
get isFailed(): boolean {
|
}
|
||||||
return this.testDone?.result !== 'success'
|
if (this.testDone?.result === 'success') {
|
||||||
}
|
return 'success'
|
||||||
get isSkipped(): boolean {
|
}
|
||||||
return this.testDone?.skipped === true
|
|
||||||
|
if (this.testDone?.result === 'error' || this.testDone?.result === 'failure') {
|
||||||
|
return 'failed'
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
get time(): number {
|
get time(): number {
|
||||||
return this.testDone !== undefined ? this.testDone.time - this.testStart.time : 0
|
return this.testDone !== undefined ? this.testDone.time - this.testStart.time : 0
|
||||||
}
|
}
|
||||||
|
|
@ -104,7 +76,7 @@ export async function parseDartJson(content: string, options: ParseOptions): Pro
|
||||||
success: testRun.success,
|
success: testRun.success,
|
||||||
output: {
|
output: {
|
||||||
title: `${options.name.trim()} ${icon}`,
|
title: `${options.name.trim()} ${icon}`,
|
||||||
summary: getSummary(testRun),
|
summary: getReport(getTestRunResult(testRun)),
|
||||||
annotations: options.annotations ? getAnnotations(testRun, options.workDir, options.trackedFiles) : undefined
|
annotations: options.annotations ? getAnnotations(testRun, options.workDir, options.trackedFiles) : undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -143,72 +115,23 @@ function getTestRun(content: string): TestRun {
|
||||||
return new TestRun(Object.values(suites), success, totalTime)
|
return new TestRun(Object.values(suites), success, totalTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSummary(tr: TestRun): string {
|
function getTestRunResult(tr: TestRun): TestRunResult {
|
||||||
const time = `${(tr.time / 1000).toFixed(3)}s`
|
const suites = tr.suites.map(s => {
|
||||||
const headingLine = `**${tr.count}** tests were completed in **${time}** with **${tr.passed}** passed, **${tr.skipped}** skipped and **${tr.failed}** failed.`
|
return new TestSuiteResult(s.suite.path, getGroups(s))
|
||||||
|
|
||||||
const suitesSummary = tr.suites.map((s, i) => {
|
|
||||||
const icon = s.failed === 0 ? Icon.success : Icon.fail
|
|
||||||
const tsTime = `${s.time}ms`
|
|
||||||
const tsName = s.suite.path
|
|
||||||
const tsAddr = makeSuiteSlug(i, tsName).link
|
|
||||||
const tsNameLink = link(tsName, tsAddr)
|
|
||||||
return [icon, tsNameLink, s.count, tsTime, s.passed, s.failed, s.skipped]
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const summary = table(
|
return new TestRunResult(suites, tr.time)
|
||||||
['Result', 'Suite', 'Tests', 'Time', `Passed ${Icon.success}`, `Failed ${Icon.fail}`, `Skipped ${Icon.skip}`],
|
|
||||||
[Align.Center, Align.Left, Align.Right, Align.Right, Align.Right, Align.Right, Align.Right],
|
|
||||||
...suitesSummary
|
|
||||||
)
|
|
||||||
|
|
||||||
const suites = tr.suites.map((ts, i) => getSuiteSummary(ts, i)).join('\n')
|
|
||||||
const suitesSection = `# Test Suites\n\n${suites}`
|
|
||||||
|
|
||||||
return `${headingLine}\n${summary}\n${suitesSection}`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSuiteSummary(ts: TestSuite, index: number): string {
|
function getGroups(suite: TestSuite): TestGroupResult[] {
|
||||||
const icon = ts.failed === 0 ? Icon.success : Icon.fail
|
const groups = Object.values(suite.groups).filter(grp => grp.tests.length > 0)
|
||||||
|
|
||||||
const groups = Object.values(ts.groups)
|
|
||||||
groups.sort((a, b) => (a.group.line ?? 0) - (b.group.line ?? 0))
|
groups.sort((a, b) => (a.group.line ?? 0) - (b.group.line ?? 0))
|
||||||
|
|
||||||
const content = groups
|
return groups.map(group => {
|
||||||
.filter(grp => grp.count > 0)
|
group.tests.sort((a, b) => (a.testStart.test.line ?? 0) - (b.testStart.test.line ?? 0))
|
||||||
.map(grp => {
|
const tests = group.tests.map(t => new TestCaseResult(t.testStart.test.name, t.result, t.time))
|
||||||
const header = grp.group.name !== null ? `### ${grp.group.name}\n\n` : ''
|
return new TestGroupResult(group.group.name, tests)
|
||||||
grp.tests.sort((a, b) => (a.testStart.test.line ?? 0) - (b.testStart.test.line ?? 0))
|
})
|
||||||
const tests = table(
|
|
||||||
['Result', 'Test', 'Time'],
|
|
||||||
[Align.Center, Align.Left, Align.Right],
|
|
||||||
...grp.tests.map(tc => {
|
|
||||||
const name = tc.testStart.test.name
|
|
||||||
const time = `${tc.time}ms`
|
|
||||||
const result = getTestCaseIcon(tc)
|
|
||||||
return [result, name, time]
|
|
||||||
})
|
|
||||||
)
|
|
||||||
|
|
||||||
return `${header}${tests}\n`
|
|
||||||
})
|
|
||||||
.join('\n')
|
|
||||||
|
|
||||||
const tsName = ts.suite.path
|
|
||||||
const tsSlug = makeSuiteSlug(index, tsName)
|
|
||||||
const tsNameLink = `<a id="${tsSlug.id}" href="${tsSlug.link}">${tsName}</a>`
|
|
||||||
return `## ${tsNameLink} ${icon}\n\n${content}`
|
|
||||||
}
|
|
||||||
|
|
||||||
function makeSuiteSlug(index: number, name: string): {id: string; link: string} {
|
|
||||||
// use "ts-$index-" as prefix to avoid slug conflicts after escaping the paths
|
|
||||||
return slug(`ts-${index}-${name}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
function getTestCaseIcon(test: TestCase): string {
|
|
||||||
if (test.isFailed) return Icon.fail
|
|
||||||
if (test.isSkipped) return Icon.skip
|
|
||||||
return Icon.success
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAnnotations(tr: TestRun, workDir: string, trackedFiles: string[]): Annotation[] {
|
function getAnnotations(tr: TestRun, workDir: string, trackedFiles: string[]): Annotation[] {
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,20 @@
|
||||||
import {Annotation, ParseOptions, TestResult} from '../parser-types'
|
import {Annotation, ParseOptions, TestResult} from '../parser-types'
|
||||||
import {parseStringPromise} from 'xml2js'
|
import {parseStringPromise} from 'xml2js'
|
||||||
|
|
||||||
import {JunitReport, TestCase, TestSuite, TestSuites} from './jest-junit-types'
|
import {JunitReport, TestCase, TestSuite} from './jest-junit-types'
|
||||||
import {Align, Icon, link, table} from '../../utils/markdown-utils'
|
import {Icon} from '../../utils/markdown-utils'
|
||||||
import {normalizeFilePath} from '../../utils/file-utils'
|
import {normalizeFilePath} from '../../utils/file-utils'
|
||||||
import {slug} from '../../utils/slugger'
|
|
||||||
import {parseAttribute} from '../../utils/xml-utils'
|
import {parseAttribute} from '../../utils/xml-utils'
|
||||||
|
|
||||||
|
import {
|
||||||
|
TestExecutionResult,
|
||||||
|
TestRunResult,
|
||||||
|
TestSuiteResult,
|
||||||
|
TestGroupResult,
|
||||||
|
TestCaseResult
|
||||||
|
} from '../../report/test-results'
|
||||||
|
import getReport from '../../report/get-report'
|
||||||
|
|
||||||
export async function parseJestJunit(content: string, options: ParseOptions): Promise<TestResult> {
|
export async function parseJestJunit(content: string, options: ParseOptions): Promise<TestResult> {
|
||||||
const junit = (await parseStringPromise(content, {
|
const junit = (await parseStringPromise(content, {
|
||||||
attrValueProcessors: [parseAttribute]
|
attrValueProcessors: [parseAttribute]
|
||||||
|
|
@ -26,47 +34,19 @@ export async function parseJestJunit(content: string, options: ParseOptions): Pr
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSummary(junit: JunitReport): string {
|
function getSummary(junit: JunitReport): string {
|
||||||
const stats = junit.testsuites.$
|
const suites = junit.testsuites.testsuite.map(ts => {
|
||||||
|
const name = ts.$.name.trim()
|
||||||
const time = `${stats.time.toFixed(3)}s`
|
const time = ts.$.time * 1000
|
||||||
const skipped = getSkippedCount(junit.testsuites)
|
const sr = new TestSuiteResult(name, getGroups(ts), time)
|
||||||
const failed = stats.errors + stats.failures
|
return sr
|
||||||
const passed = stats.tests - failed - skipped
|
|
||||||
|
|
||||||
const headingLine = `**${stats.tests}** tests were completed in **${time}** with **${passed}** passed, **${skipped}** skipped and **${failed}** failed.`
|
|
||||||
|
|
||||||
const suitesSummary = junit.testsuites.testsuite.map((ts, i) => {
|
|
||||||
const skip = ts.$.skipped
|
|
||||||
const fail = ts.$.errors + ts.$.failures
|
|
||||||
const pass = ts.$.tests - fail - skip
|
|
||||||
const tm = formatTime(ts.$.time)
|
|
||||||
const result = fail === 0 ? Icon.success : Icon.fail
|
|
||||||
const tsName = ts.$.name.trim()
|
|
||||||
const tsAddr = makeSuiteSlug(i, tsName).link
|
|
||||||
const tsNameLink = link(tsName, tsAddr)
|
|
||||||
return [result, tsNameLink, ts.$.tests, tm, pass, fail, skip]
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const summary = table(
|
const time = junit.testsuites.$.time * 1000
|
||||||
['Result', 'Suite', 'Tests', 'Time', `Passed ${Icon.success}`, `Failed ${Icon.fail}`, `Skipped ${Icon.skip}`],
|
const tr = new TestRunResult(suites, time)
|
||||||
[Align.Center, Align.Left, Align.Right, Align.Right, Align.Right, Align.Right, Align.Right],
|
return getReport(tr)
|
||||||
...suitesSummary
|
|
||||||
)
|
|
||||||
|
|
||||||
const suites = junit.testsuites?.testsuite?.map((ts, i) => getSuiteSummary(ts, i)).join('\n')
|
|
||||||
const suitesSection = `# Test Suites\n\n${suites}`
|
|
||||||
|
|
||||||
return `${headingLine}\n${summary}\n${suitesSection}`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSkippedCount(suites: TestSuites): number {
|
function getGroups(suite: TestSuite): TestGroupResult[] {
|
||||||
return suites.testsuite.reduce((sum, suite) => sum + suite.$.skipped, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
function getSuiteSummary(suite: TestSuite, index: number): string {
|
|
||||||
const success = !(suite.$?.failures > 0 || suite.$?.errors > 0)
|
|
||||||
const icon = success ? Icon.success : Icon.fail
|
|
||||||
|
|
||||||
const groups: {describe: string; tests: TestCase[]}[] = []
|
const groups: {describe: string; tests: TestCase[]}[] = []
|
||||||
for (const tc of suite.testcase) {
|
for (const tc of suite.testcase) {
|
||||||
let grp = groups.find(g => g.describe === tc.$.classname)
|
let grp = groups.find(g => g.describe === tc.$.classname)
|
||||||
|
|
@ -77,43 +57,21 @@ function getSuiteSummary(suite: TestSuite, index: number): string {
|
||||||
grp.tests.push(tc)
|
grp.tests.push(tc)
|
||||||
}
|
}
|
||||||
|
|
||||||
const content = groups
|
return groups.map(grp => {
|
||||||
.map(grp => {
|
const tests = grp.tests.map(tc => {
|
||||||
const header = grp.describe !== '' ? `### ${grp.describe.trim()}\n\n` : ''
|
const name = tc.$.name.trim()
|
||||||
const tests = table(
|
const result = getTestCaseResult(tc)
|
||||||
['Result', 'Test', 'Time'],
|
const time = tc.$.time * 1000
|
||||||
[Align.Center, Align.Left, Align.Right],
|
return new TestCaseResult(name, result, time)
|
||||||
...grp.tests.map(tc => {
|
|
||||||
const name = tc.$.name.trim()
|
|
||||||
const time = formatTime(tc.$.time)
|
|
||||||
const result = getTestCaseIcon(tc)
|
|
||||||
return [result, name, time]
|
|
||||||
})
|
|
||||||
)
|
|
||||||
|
|
||||||
return `${header}${tests}\n`
|
|
||||||
})
|
})
|
||||||
.join('\n')
|
return new TestGroupResult(grp.describe, tests)
|
||||||
|
})
|
||||||
const tsName = suite.$.name.trim()
|
|
||||||
const tsSlug = makeSuiteSlug(index, tsName)
|
|
||||||
const tsNameLink = `<a id="${tsSlug.id}" href="${tsSlug.link}">${tsName}</a>`
|
|
||||||
return `## ${tsNameLink} ${icon}\n\n${content}`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTestCaseIcon(test: TestCase): string {
|
function getTestCaseResult(test: TestCase): TestExecutionResult {
|
||||||
if (test.failure) return Icon.fail
|
if (test.failure) return 'failed'
|
||||||
if (test.skipped) return Icon.skip
|
if (test.skipped) return 'skipped'
|
||||||
return Icon.success
|
return 'success'
|
||||||
}
|
|
||||||
|
|
||||||
function makeSuiteSlug(index: number, name: string): {id: string; link: string} {
|
|
||||||
// use "ts-$index-" as prefix to avoid slug conflicts after escaping the paths
|
|
||||||
return slug(`ts-${index}-${name}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatTime(sec: number): string {
|
|
||||||
return `${Math.round(sec * 1000)}ms`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAnnotations(junit: JunitReport, workDir: string, trackedFiles: string[]): Annotation[] {
|
function getAnnotations(junit: JunitReport, workDir: string, trackedFiles: string[]): Annotation[] {
|
||||||
|
|
|
||||||
72
src/report/get-report.ts
Normal file
72
src/report/get-report.ts
Normal file
|
|
@ -0,0 +1,72 @@
|
||||||
|
import {TestExecutionResult, TestRunResult, TestSuiteResult} from './test-results'
|
||||||
|
import {Align, Icon, link, table} from '../utils/markdown-utils'
|
||||||
|
import {slug} from '../utils/slugger'
|
||||||
|
|
||||||
|
export default function getReport(tr: TestRunResult): string {
|
||||||
|
const time = `${(tr.time / 1000).toFixed(3)}s`
|
||||||
|
const headingLine = `**${tr.tests}** tests were completed in **${time}** with **${tr.passed}** passed, **${tr.skipped}** skipped and **${tr.failed}** failed.`
|
||||||
|
|
||||||
|
const suitesSummary = tr.suites.map((s, i) => {
|
||||||
|
const icon = getResultIcon(s.result)
|
||||||
|
const tsTime = `${s.time}ms`
|
||||||
|
const tsName = s.name
|
||||||
|
const tsAddr = makeSuiteSlug(i, tsName).link
|
||||||
|
const tsNameLink = link(tsName, tsAddr)
|
||||||
|
return [icon, tsNameLink, s.tests, tsTime, s.passed, s.failed, s.skipped]
|
||||||
|
})
|
||||||
|
|
||||||
|
const summary = table(
|
||||||
|
['Result', 'Suite', 'Tests', 'Time', `Passed ${Icon.success}`, `Failed ${Icon.fail}`, `Skipped ${Icon.skip}`],
|
||||||
|
[Align.Center, Align.Left, Align.Right, Align.Right, Align.Right, Align.Right, Align.Right],
|
||||||
|
...suitesSummary
|
||||||
|
)
|
||||||
|
|
||||||
|
const suites = tr.suites.map((ts, i) => getSuiteSummary(ts, i)).join('\n')
|
||||||
|
const suitesSection = `# Test Suites\n\n${suites}`
|
||||||
|
|
||||||
|
return `${headingLine}\n${summary}\n${suitesSection}`
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSuiteSummary(ts: TestSuiteResult, index: number): string {
|
||||||
|
const icon = getResultIcon(ts.result)
|
||||||
|
const content = ts.groups
|
||||||
|
.map(grp => {
|
||||||
|
const header = grp.name ? `### ${grp.name}\n\n` : ''
|
||||||
|
const tests = table(
|
||||||
|
['Result', 'Test', 'Time'],
|
||||||
|
[Align.Center, Align.Left, Align.Right],
|
||||||
|
...grp.tests.map(tc => {
|
||||||
|
const name = tc.name
|
||||||
|
const time = `${tc.time}ms`
|
||||||
|
const result = getResultIcon(tc.result)
|
||||||
|
return [result, name, time]
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
return `${header}${tests}\n`
|
||||||
|
})
|
||||||
|
.join('\n')
|
||||||
|
|
||||||
|
const tsName = ts.name
|
||||||
|
const tsSlug = makeSuiteSlug(index, tsName)
|
||||||
|
const tsNameLink = `<a id="${tsSlug.id}" href="${tsSlug.link}">${tsName}</a>`
|
||||||
|
return `## ${tsNameLink} ${icon}\n\n${content}`
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeSuiteSlug(index: number, name: string): {id: string; link: string} {
|
||||||
|
// use "ts-$index-" as prefix to avoid slug conflicts after escaping the paths
|
||||||
|
return slug(`ts-${index}-${name}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
function getResultIcon(result: TestExecutionResult): string {
|
||||||
|
switch (result) {
|
||||||
|
case 'success':
|
||||||
|
return Icon.success
|
||||||
|
case 'skipped':
|
||||||
|
return Icon.skip
|
||||||
|
case 'failed':
|
||||||
|
return Icon.fail
|
||||||
|
default:
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
}
|
||||||
77
src/report/test-results.ts
Normal file
77
src/report/test-results.ts
Normal file
|
|
@ -0,0 +1,77 @@
|
||||||
|
export class TestRunResult {
|
||||||
|
constructor(readonly suites: TestSuiteResult[], private totalTime?: number) {}
|
||||||
|
|
||||||
|
get tests(): number {
|
||||||
|
return this.suites.reduce((sum, g) => sum + g.tests, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
get passed(): number {
|
||||||
|
return this.suites.reduce((sum, g) => sum + g.passed, 0)
|
||||||
|
}
|
||||||
|
get failed(): number {
|
||||||
|
return this.suites.reduce((sum, g) => sum + g.failed, 0)
|
||||||
|
}
|
||||||
|
get skipped(): number {
|
||||||
|
return this.suites.reduce((sum, g) => sum + g.skipped, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
get time(): number {
|
||||||
|
return this.totalTime ?? this.suites.reduce((sum, g) => sum + g.time, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
get result(): TestExecutionResult {
|
||||||
|
return this.suites.some(t => t.result === 'failed') ? 'failed' : 'success'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class TestSuiteResult {
|
||||||
|
constructor(readonly name: string, readonly groups: TestGroupResult[], private totalTime?: number) {}
|
||||||
|
|
||||||
|
get tests(): number {
|
||||||
|
return this.groups.reduce((sum, g) => sum + g.tests.length, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
get passed(): number {
|
||||||
|
return this.groups.reduce((sum, g) => sum + g.passed, 0)
|
||||||
|
}
|
||||||
|
get failed(): number {
|
||||||
|
return this.groups.reduce((sum, g) => sum + g.failed, 0)
|
||||||
|
}
|
||||||
|
get skipped(): number {
|
||||||
|
return this.groups.reduce((sum, g) => sum + g.skipped, 0)
|
||||||
|
}
|
||||||
|
get time(): number {
|
||||||
|
return this.totalTime ?? this.groups.reduce((sum, g) => sum + g.time, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
get result(): TestExecutionResult {
|
||||||
|
return this.groups.some(t => t.result === 'failed') ? 'failed' : 'success'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class TestGroupResult {
|
||||||
|
constructor(readonly name: string | undefined, readonly tests: TestCaseResult[]) {}
|
||||||
|
|
||||||
|
get passed(): number {
|
||||||
|
return this.tests.reduce((sum, t) => (t.result === 'success' ? sum + 1 : sum), 0)
|
||||||
|
}
|
||||||
|
get failed(): number {
|
||||||
|
return this.tests.reduce((sum, t) => (t.result === 'failed' ? sum + 1 : sum), 0)
|
||||||
|
}
|
||||||
|
get skipped(): number {
|
||||||
|
return this.tests.reduce((sum, t) => (t.result === 'skipped' ? sum + 1 : sum), 0)
|
||||||
|
}
|
||||||
|
get time(): number {
|
||||||
|
return this.tests.reduce((sum, t) => sum + t.time, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
get result(): TestExecutionResult {
|
||||||
|
return this.tests.some(t => t.result === 'failed') ? 'failed' : 'success'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class TestCaseResult {
|
||||||
|
constructor(readonly name: string, readonly result: TestExecutionResult, readonly time: number) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
export type TestExecutionResult = 'success' | 'skipped' | 'failed' | undefined
|
||||||
Loading…
Add table
Add a link
Reference in a new issue