-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathreportCoverage.js
More file actions
28 lines (25 loc) · 870 Bytes
/
reportCoverage.js
File metadata and controls
28 lines (25 loc) · 870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const fs = require('fs');
const path = require('path');
const url = require('url');
const coverageDir = path.join(__dirname, 'coverage');
let total = 0;
let covered = 0;
for (const file of fs.readdirSync(coverageDir)) {
if (!file.endsWith('.json')) continue;
const data = JSON.parse(fs.readFileSync(path.join(coverageDir, file)));
for (const result of data.result) {
if (!result.url.startsWith('file://')) continue;
const filePath = url.fileURLToPath(result.url);
if (!filePath.startsWith(__dirname) || !filePath.endsWith('Ity.js')) continue;
for (const fn of result.functions) {
total++;
if (fn.ranges.some(r => r.count > 0)) covered++;
}
}
}
const pct = total === 0 ? 0 : (covered / total) * 100;
console.log(`Coverage: ${pct.toFixed(2)}%`);
if (pct < 100) {
console.error('Coverage below 100%');
process.exitCode = 1;
}