Remove duplicate text of top level test name

This commit is contained in:
Michal Dorner 2020-11-29 20:50:52 +01:00
parent 04a8489550
commit 198c3d1af3
No known key found for this signature in database
GPG key ID: 9EEE04B48DA36786
4 changed files with 22 additions and 25 deletions

View file

@ -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
dist/index.js generated vendored
View file

@ -115,10 +115,11 @@ async function parseJestJunit(content, options) {
}));
const testsuites = junit.testsuites;
const success = !(((_a = testsuites.$) === null || _a === void 0 ? void 0 : _a.failures) > 0 || ((_b = testsuites.$) === null || _b === void 0 ? void 0 : _b.errors) > 0);
const icon = success ? markdown_utils_1.Icon.success : markdown_utils_1.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
}
@ -128,12 +129,10 @@ exports.parseJestJunit = parseJestJunit;
function getSummary(success, junit) {
var _a, _b;
const stats = junit.testsuites.$;
const icon = success ? markdown_utils_1.Icon.success : markdown_utils_1.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) => {
const skip = ts.$.skipped;
@ -148,8 +147,8 @@ function getSummary(success, junit) {
});
const summary = markdown_utils_1.table(['Result', 'Suite', 'Tests', 'Time', `Passed ${markdown_utils_1.Icon.success}`, `Failed ${markdown_utils_1.Icon.fail}`, `Skipped ${markdown_utils_1.Icon.skip}`], [markdown_utils_1.Align.Center, markdown_utils_1.Align.Left, markdown_utils_1.Align.Right, markdown_utils_1.Align.Right, markdown_utils_1.Align.Right, markdown_utils_1.Align.Right, markdown_utils_1.Align.Right], ...suitesSummary);
const suites = (_b = (_a = junit.testsuites) === null || _a === void 0 ? void 0 : _a.testsuite) === null || _b === void 0 ? void 0 : _b.map((ts, i) => getSuiteSummary(ts, i)).join('\n');
const suitesSection = `## Test Suites\n\n${suites}`;
return `${heading}\n${headingLine}\n${summary}\n${suitesSection}`;
const suitesSection = `# Test Suites\n\n${suites}`;
return `${headingLine}\n${summary}\n${suitesSection}`;
}
function getSkippedCount(suites) {
return suites.testsuite.reduce((sum, suite) => sum + suite.$.skipped, 0);
@ -169,7 +168,7 @@ function getSuiteSummary(suite, index) {
}
const content = groups
.map(grp => {
const header = grp.describe !== '' ? `#### ${grp.describe}\n\n` : '';
const header = grp.describe !== '' ? `### ${grp.describe}\n\n` : '';
const tests = markdown_utils_1.table(['Result', 'Test', 'Time'], [markdown_utils_1.Align.Center, markdown_utils_1.Align.Left, markdown_utils_1.Align.Right], ...grp.tests.map(tc => {
const name = tc.$.name;
const time = `${Math.round(tc.$.time * 1000)}ms`;
@ -182,7 +181,7 @@ function getSuiteSummary(suite, index) {
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) {
if (test.failure)
@ -213,7 +212,7 @@ function getAnnotations(junit, workDir, trackedFiles) {
end_line: src.line,
path: src.file,
message: ex,
title: `Test Failed: ${tc.$.name}`
title: `Test Failed: '${tc.$.name}' [${suite.$.name}]`
});
}
}

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View file

@ -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
}
@ -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) => {
@ -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 {
@ -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],
@ -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 {