-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (31 loc) · 915 Bytes
/
index.js
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
29
30
31
32
33
34
35
36
37
#!/usr/bin/env node
const fs = require('fs');
const Coverage = require('./lib/coverage');
const parse = require('./lib/parse');
const split = require('./lib/split');
const files = process.argv.slice(2);
const failures = [];
const results = new Coverage();
files.forEach(name => {
let file;
try {
file = fs.readFileSync(name, { encoding: 'utf-8' });
if (!file) return;
split(file).forEach(part => parse(results, part));
} catch (e) {
failures.push(`Failed to process '${name}'. ${e.message}`);
}
});
results.forEach(coverage => {
const info = coverage.uncover().serialise();
if (info.length) console.log(info);
if (coverage.errors.length) {
process.exitCode = -1;
console.error(`Failed to process '${coverage.name}':`);
console.error(' ' + coverage.errors.join('\n '));
}
});
if (failures.length) {
process.exitCode = -1;
console.error(failures.join('\n'));
}