Skip to content

Commit

Permalink
jest-junit - use milliseconds for test suites times
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Dorner committed Jan 6, 2021
1 parent 9b620ef commit e169ffb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions __tests__/__snapshots__/jest-junit.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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
## <a id=\\"user-content-ts-0-tests-main-test-js\\" href=\\"#ts-0-tests-main-test-js\\">__tests__\\\\main.test.js</a>
Expand Down
15 changes: 9 additions & 6 deletions src/parsers/jest-junit/jest-junit-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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]
})
Expand All @@ -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) {
Expand Down

0 comments on commit e169ffb

Please sign in to comment.