Add summary badge to report

This commit is contained in:
Michal Dorner 2021-01-24 18:11:59 +01:00
parent 92cb68e21e
commit 42eb11a3c8
No known key found for this signature in database
GPG key ID: 9EEE04B48DA36786
9 changed files with 60 additions and 6 deletions

View file

@ -1,3 +1,5 @@
![Tests failed](https://img.shields.io/badge/tests-1%20passed%2C%201%20skipped%2C%204%20failed-critical)
### fixtures/dart-json.json ### fixtures/dart-json.json
**6** tests were completed in **3.760s** with **1** passed, **1** skipped and **4** failed. **6** tests were completed in **3.760s** with **1** passed, **1** skipped and **4** failed.

View file

@ -1,3 +1,5 @@
![Tests failed](https://img.shields.io/badge/tests-3%20passed%2C%201%20skipped%2C%203%20failed-critical)
### fixtures/dotnet-trx.trx ### fixtures/dotnet-trx.trx
**7** tests were completed in **1.061s** with **3** passed, **1** skipped and **3** failed. **7** tests were completed in **1.061s** with **3** passed, **1** skipped and **3** failed.

View file

@ -1,3 +1,5 @@
![Tests failed](https://img.shields.io/badge/tests-1%20passed%2C%201%20skipped%2C%204%20failed-critical)
### fixtures/jest-junit.xml ### fixtures/jest-junit.xml
**6** tests were completed in **1.360s** with **1** passed, **1** skipped and **4** failed. **6** tests were completed in **1.360s** with **1** passed, **1** skipped and **4** failed.

View file

@ -52,7 +52,9 @@ dart:isolate _RawReceivePortImpl._handleMessage
"title": "[test\\\\second_test.dart] Timeout test", "title": "[test\\\\second_test.dart] Timeout test",
}, },
], ],
"summary": "### fixtures/dart-json.json "summary": "![Tests failed](https://img.shields.io/badge/tests-1%20passed%2C%201%20skipped%2C%204%20failed-critical)
### fixtures/dart-json.json
**6** tests were completed in **3.760s** with **1** passed, **1** skipped and **4** failed. **6** tests were completed in **3.760s** with **1** passed, **1** skipped and **4** failed.

View file

@ -30,7 +30,9 @@ Actual: 2",
"title": "[DotnetTests.XUnitTests.CalculatorTests] Failing_Test", "title": "[DotnetTests.XUnitTests.CalculatorTests] Failing_Test",
}, },
], ],
"summary": "### fixtures/dotnet-trx.trx "summary": "![Tests failed](https://img.shields.io/badge/tests-3%20passed%2C%201%20skipped%2C%203%20failed-critical)
### fixtures/dotnet-trx.trx
**7** tests were completed in **1.061s** with **3** passed, **1** skipped and **3** failed. **7** tests were completed in **1.061s** with **3** passed, **1** skipped and **3** failed.

View file

@ -73,7 +73,9 @@ Received: false
"title": "[__tests__\\\\second.test.js] Timeout test", "title": "[__tests__\\\\second.test.js] Timeout test",
}, },
], ],
"summary": "### fixtures/jest-junit.xml "summary": "![Tests failed](https://img.shields.io/badge/tests-1%20passed%2C%201%20skipped%2C%204%20failed-critical)
### fixtures/jest-junit.xml
**6** tests were completed in **1.360s** with **1** passed, **1** skipped and **4** failed. **6** tests were completed in **1.360s** with **1** passed, **1** skipped and **4** failed.

22
dist/index.js generated vendored
View file

@ -750,15 +750,35 @@ const core = __importStar(__nccwpck_require__(2186));
const markdown_utils_1 = __nccwpck_require__(6482); const markdown_utils_1 = __nccwpck_require__(6482);
const slugger_1 = __nccwpck_require__(3328); const slugger_1 = __nccwpck_require__(3328);
function getReport(results) { function getReport(results) {
const badge = getBadge(results);
const runsSummary = results.map(getRunSummary).join('\n\n'); const runsSummary = results.map(getRunSummary).join('\n\n');
const suites = results const suites = results
.flatMap(tr => tr.suites) .flatMap(tr => tr.suites)
.map((ts, i) => getSuiteSummary(ts, i)) .map((ts, i) => getSuiteSummary(ts, i))
.join('\n'); .join('\n');
const suitesSection = `# Test Suites\n\n${suites}`; const suitesSection = `# Test Suites\n\n${suites}`;
return [runsSummary, suitesSection].join('\n\n'); return [badge, runsSummary, suitesSection].join('\n\n');
} }
exports.default = getReport; exports.default = getReport;
function getBadge(results) {
const passed = results.reduce((sum, tr) => sum + tr.passed, 0);
const skipped = results.reduce((sum, tr) => sum + tr.skipped, 0);
const failed = results.reduce((sum, tr) => sum + tr.failed, 0);
const passedText = passed > 0 ? `${passed} passed` : null;
const skippedText = skipped > 0 ? `${skipped} skipped` : null;
const failedText = failed > 0 ? `${failed} failed` : null;
const message = [passedText, skippedText, failedText].filter(s => s != null).join(', ') || 'none';
let color = 'success';
if (failed > 0) {
color = 'critical';
}
else if (passed === 0 && failed === 0) {
color = 'yellow';
}
const uri = encodeURIComponent(`tests-${message}-${color}`);
const text = failed > 0 ? 'Tests failed' : 'Tests passed successfully';
return `![${text}](https://img.shields.io/badge/${uri})`;
}
function getRunSummary(tr) { function getRunSummary(tr) {
core.info('Generating check run summary'); core.info('Generating check run summary');
const time = `${(tr.time / 1000).toFixed(3)}s`; const time = `${(tr.time / 1000).toFixed(3)}s`;

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View file

@ -4,6 +4,7 @@ import {Align, Icon, link, table} from '../utils/markdown-utils'
import {slug} from '../utils/slugger' import {slug} from '../utils/slugger'
export default function getReport(results: TestRunResult[]): string { export default function getReport(results: TestRunResult[]): string {
const badge = getBadge(results)
const runsSummary = results.map(getRunSummary).join('\n\n') const runsSummary = results.map(getRunSummary).join('\n\n')
const suites = results const suites = results
.flatMap(tr => tr.suites) .flatMap(tr => tr.suites)
@ -11,7 +12,28 @@ export default function getReport(results: TestRunResult[]): string {
.join('\n') .join('\n')
const suitesSection = `# Test Suites\n\n${suites}` const suitesSection = `# Test Suites\n\n${suites}`
return [runsSummary, suitesSection].join('\n\n') return [badge, runsSummary, suitesSection].join('\n\n')
}
function getBadge(results: TestRunResult[]): string {
const passed = results.reduce((sum, tr) => sum + tr.passed, 0)
const skipped = results.reduce((sum, tr) => sum + tr.skipped, 0)
const failed = results.reduce((sum, tr) => sum + tr.failed, 0)
const passedText = passed > 0 ? `${passed} passed` : null
const skippedText = skipped > 0 ? `${skipped} skipped` : null
const failedText = failed > 0 ? `${failed} failed` : null
const message = [passedText, skippedText, failedText].filter(s => s != null).join(', ') || 'none'
let color = 'success'
if (failed > 0) {
color = 'critical'
} else if (passed === 0 && failed === 0) {
color = 'yellow'
}
const uri = encodeURIComponent(`tests-${message}-${color}`)
const text = failed > 0 ? 'Tests failed' : 'Tests passed successfully'
return `![${text}](https://img.shields.io/badge/${uri})`
} }
function getRunSummary(tr: TestRunResult): string { function getRunSummary(tr: TestRunResult): string {