Skip to content

Commit

Permalink
Remove duplicate text of top level test name
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Dorner committed Nov 29, 2020
1 parent 04a8489 commit 198c3d1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 25 deletions.
17 changes: 8 additions & 9 deletions __tests__/__snapshots__/jest-junit.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -73,42 +73,41 @@ Received: false
"title": "Test Failed: 'Timeout test' [__tests__\\\\second.test.js]",
},
],
"summary": "# jest tests ❌
**6** tests were completed in **1.360s** with **1** passed, **1** skipped and **4** failed.
"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 |
## Test Suites
# Test Suites
### <a id=\\"user-content-ts-0-tests-main-test-js\\" href=\\"#ts-0-tests-main-test-js\\">__tests__\\\\main.test.js</a>
## <a id=\\"user-content-ts-0-tests-main-test-js\\" href=\\"#ts-0-tests-main-test-js\\">__tests__\\\\main.test.js</a>
#### Test 1
### Test 1
| Result | Test | Time |
| :---: | :--- | ---: |
| ✔️ | Passing test | 1ms |
#### Test 1 Test 1.1
### Test 1 Test 1.1
| Result | Test | Time |
| :---: | :--- | ---: |
| | Failing test | 2ms |
| | Exception in target unit | 0ms |
#### Test 2
### Test 2
| Result | Test | Time |
| :---: | :--- | ---: |
| | Exception in test | 0ms |
### <a id=\\"user-content-ts-1-tests-second-test-js\\" href=\\"#ts-1-tests-second-test-js\\">__tests__\\\\second.test.js</a>
## <a id=\\"user-content-ts-1-tests-second-test-js\\" href=\\"#ts-1-tests-second-test-js\\">__tests__\\\\second.test.js</a>
| Result | Test | Time |
| :---: | :--- | ---: |
| | Timeout test | 4ms |
| ✖️ | Skipped test | 0ms |
",
"title": "jest tests",
"title": "jest tests",
}
`;
15 changes: 7 additions & 8 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

13 changes: 6 additions & 7 deletions src/parsers/jest-junit/jest-junit-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ export async function parseJestJunit(content: string, options: ParseOptions): Pr
})) as JunitReport
const testsuites = junit.testsuites
const success = !(testsuites.$?.failures > 0 || testsuites.$?.errors > 0)
const icon = success ? Icon.success : Icon.fail

return {
success,
output: {
title: junit.testsuites.$.name,
title: `${junit.testsuites.$.name} ${icon}`,
summary: getSummary(success, junit),
annotations: options.annotations ? getAnnotations(junit, options.workDir, options.trackedFiles) : undefined
}
Expand All @@ -27,14 +28,12 @@ export async function parseJestJunit(content: string, options: ParseOptions): Pr
function getSummary(success: boolean, junit: JunitReport): string {
const stats = junit.testsuites.$

const icon = success ? Icon.success : Icon.fail
const time = `${stats.time.toFixed(3)}s`

const skipped = getSkippedCount(junit.testsuites)
const failed = stats.errors + stats.failures
const passed = stats.tests - failed - skipped

const heading = `# ${stats.name} ${icon}`
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) => {
Expand All @@ -56,9 +55,9 @@ function getSummary(success: boolean, junit: JunitReport): string {
)

const suites = junit.testsuites?.testsuite?.map((ts, i) => getSuiteSummary(ts, i)).join('\n')
const suitesSection = `## Test Suites\n\n${suites}`
const suitesSection = `# Test Suites\n\n${suites}`

return `${heading}\n${headingLine}\n${summary}\n${suitesSection}`
return `${headingLine}\n${summary}\n${suitesSection}`
}

function getSkippedCount(suites: TestSuites): number {
Expand All @@ -81,7 +80,7 @@ function getSuiteSummary(suite: TestSuite, index: number): string {

const content = groups
.map(grp => {
const header = grp.describe !== '' ? `#### ${grp.describe}\n\n` : ''
const header = grp.describe !== '' ? `### ${grp.describe}\n\n` : ''
const tests = table(
['Result', 'Test', 'Time'],
[Align.Center, Align.Left, Align.Right],
Expand All @@ -100,7 +99,7 @@ function getSuiteSummary(suite: TestSuite, index: number): string {
const tsName = suite.$.name
const tsSlug = makeSuiteSlug(index, tsName)
const tsNameLink = `<a id="${tsSlug.id}" href="${tsSlug.link}">${tsName}</a>`
return `### ${tsNameLink} ${icon}\n\n${content}`
return `## ${tsNameLink} ${icon}\n\n${content}`
}

function getTestCaseIcon(test: TestCase): string {
Expand Down

0 comments on commit 198c3d1

Please sign in to comment.