diff --git a/__tests__/__snapshots__/jest-junit.test.ts.snap b/__tests__/__snapshots__/jest-junit.test.ts.snap index bf4dd24..bf8ec9b 100644 --- a/__tests__/__snapshots__/jest-junit.test.ts.snap +++ b/__tests__/__snapshots__/jest-junit.test.ts.snap @@ -76,8 +76,8 @@ Received: false "summary": "**6** tests were completed in **1.360s** with **1** passed, **1** skipped and **4** failed. | Result | Suite | Tests | Time | Passed ✔️ | Failed ❌ | Skipped ✖️ | | :---: | :--- | ---: | ---: | ---: | ---: | ---: | -| ❌ | [__tests__\\\\main.test.js](#ts-0-tests-main-test-js) | 4 | 0.486s | 1 | 3 | 0 | -| ❌ | [__tests__\\\\second.test.js](#ts-1-tests-second-test-js) | 2 | 0.082s | 0 | 1 | 1 | +| ❌ | [__tests__\\\\main.test.js](#ts-0-tests-main-test-js) | 4 | 486ms | 1 | 3 | 0 | +| ❌ | [__tests__\\\\second.test.js](#ts-1-tests-second-test-js) | 2 | 82ms | 0 | 1 | 1 | # Test Suites ## __tests__\\\\main.test.js ❌ diff --git a/src/parsers/jest-junit/jest-junit-parser.ts b/src/parsers/jest-junit/jest-junit-parser.ts index 6986d31..3cf1eb1 100644 --- a/src/parsers/jest-junit/jest-junit-parser.ts +++ b/src/parsers/jest-junit/jest-junit-parser.ts @@ -19,17 +19,16 @@ export async function parseJestJunit(content: string, options: ParseOptions): Pr success, output: { title: `${junit.testsuites.$.name.trim()} ${icon}`, - summary: getSummary(success, junit), + summary: getSummary(junit), annotations: options.annotations ? getAnnotations(junit, options.workDir, options.trackedFiles) : undefined } } } -function getSummary(success: boolean, junit: JunitReport): string { +function getSummary(junit: JunitReport): string { const stats = junit.testsuites.$ const time = `${stats.time.toFixed(3)}s` - const skipped = getSkippedCount(junit.testsuites) const failed = stats.errors + stats.failures const passed = stats.tests - failed - skipped @@ -40,8 +39,8 @@ function getSummary(success: boolean, junit: JunitReport): string { const skip = ts.$.skipped const fail = ts.$.errors + ts.$.failures const pass = ts.$.tests - fail - skip - const tm = `${ts.$.time.toFixed(3)}s` - const result = success ? Icon.success : Icon.fail + 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) @@ -86,7 +85,7 @@ function getSuiteSummary(suite: TestSuite, index: number): string { [Align.Center, Align.Left, Align.Right], ...grp.tests.map(tc => { const name = tc.$.name.trim() - const time = `${Math.round(tc.$.time * 1000)}ms` + const time = formatTime(tc.$.time) const result = getTestCaseIcon(tc) return [result, name, time] }) @@ -113,6 +112,10 @@ function makeSuiteSlug(index: number, name: string): {id: string; link: string} 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[] { const annotations: Annotation[] = [] for (const suite of junit.testsuites.testsuite) {