-
Notifications
You must be signed in to change notification settings - Fork 3
/
cover.js
37 lines (34 loc) · 1.33 KB
/
cover.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
const libCoverage = require('istanbul-lib-coverage');
const {writeFileSync} = require('fs');
const {relative, resolve} = require('path');
module.exports = function(coverage) {
const coverageMap = libCoverage.createCoverageMap();
Object.entries(coverage).forEach(([path, counts]) => {
const statements = Object.entries(counts);
coverageMap.addFileCoverage(libCoverage.createFileCoverage({
path,
statementMap: Object.fromEntries(statements.map(([statement], index) => {
const [startLine, startColumn, endLine, endColumn] = statement.split(' ').map(Number);
return [index, {
start: {
line: startLine,
column: startColumn - 1
},
end: {
line: endLine,
column: endColumn - 1
}
}];
})),
s: Object.fromEntries(statements.map(([, count], index) => [index, count])),
fnMap: {},
branchMap: {},
f: {},
b: {}
}));
});
writeFileSync(
resolve(`.nyc_output/${relative('.', require.main.filename).trim().replace(/[^a-zA-Z0-9._-]+/g, '-')}.sql.json`),
JSON.stringify(coverageMap.toJSON())
);
};