Skip to content

Commit 3484063

Browse files
committed
chore: keep coverage output minimal and readable
1 parent 8440060 commit 3484063

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ core
4040
node_modules
4141
.expo
4242
.idea
43+
coverage/

scripts/coverage-human-report.mjs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { readFileSync } from 'node:fs';
2+
import path from 'node:path';
3+
4+
const summaryPath = path.resolve(process.cwd(), 'coverage', 'coverage-summary.json');
5+
6+
function formatPercent(value) {
7+
return `${Number(value).toFixed(2)}%`;
8+
}
9+
10+
function printBlock(title, metrics) {
11+
console.log(`\n${title}`);
12+
console.log(`- Statement coverage: ${formatPercent(metrics.statements.pct)}`);
13+
console.log(`- Branch coverage (if/switch): ${formatPercent(metrics.branches.pct)}`);
14+
console.log(`- Function coverage: ${formatPercent(metrics.functions.pct)}`);
15+
console.log(`- Line coverage: ${formatPercent(metrics.lines.pct)}`);
16+
}
17+
18+
try {
19+
const raw = readFileSync(summaryPath, 'utf-8');
20+
const summary = JSON.parse(raw);
21+
const total = summary.total;
22+
23+
console.log('\n=== Coverage Summary ===');
24+
printBlock('Whole project', total);
25+
26+
console.log('\nCore logic details:');
27+
Object.entries(summary)
28+
.filter(([key]) => key !== 'total')
29+
.forEach(([file, metrics]) => {
30+
printBlock(file, metrics);
31+
});
32+
33+
console.log('\nVitest table legend:');
34+
console.log('- % Stmts = statement coverage');
35+
console.log('- % Branch = branch coverage (if/else/switch)');
36+
console.log('- % Funcs = function coverage');
37+
console.log('- % Lines = line coverage');
38+
} catch (error) {
39+
console.error('Failed to read coverage-summary.json.');
40+
console.error(error instanceof Error ? error.message : String(error));
41+
process.exit(1);
42+
}

0 commit comments

Comments
 (0)