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

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 slugger_1 = __nccwpck_require__(3328);
function getReport(results) {
const badge = getBadge(results);
const runsSummary = results.map(getRunSummary).join('\n\n');
const suites = results
.flatMap(tr => tr.suites)
.map((ts, i) => getSuiteSummary(ts, i))
.join('\n');
const suitesSection = `# Test Suites\n\n${suites}`;
return [runsSummary, suitesSection].join('\n\n');
return [badge, runsSummary, suitesSection].join('\n\n');
}
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) {
core.info('Generating check run summary');
const time = `${(tr.time / 1000).toFixed(3)}s`;