generate coverage stubs for files that are not run

This commit is contained in:
Florian Dold 2016-11-14 00:10:55 +01:00
parent be5917c97b
commit 8b855c969d

View File

@ -138,19 +138,33 @@ if (argv["coverage"]) {
driver.executeScript(script); driver.executeScript(script);
driver.wait(untilTestOver); driver.wait(untilTestOver);
/**
* Instrument and get a coverage stub for all
* files we don't have coverage for, so they show
* up in the report.
*/
function augmentCoverage(cov) { function augmentCoverage(cov) {
for (let file of globSync(projectRoot + "/src/**/*.js")) { for (let file of globSync(projectRoot + "/src/**/*.js")) {
let suffix = file.substring(0, projectRoot.lenth);
if (/.*\/vendor\/.*/.test(suffix)) {
continue;
}
if (/.*\/taler-emscripten-lib.js/.test(suffix)) {
continue;
}
if (file in cov) { if (file in cov) {
continue; continue;
} }
cov[file] = { let instrumenter = new (require("istanbul").Instrumenter)();
"path":file, let source = fs.readFileSync(file, "utf-8");
"s":{"1":0}, let instrumentedSrc = instrumenter.instrumentSync(source, file);
"b":{}, let covStubRE = /\{.*"path".*"fnMap".*"statementMap".*"branchMap".*\}/g;
"f":{}, let covStubMatch = covStubRE.exec(instrumentedSrc);
"fnMap":{},
"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":1,"column":0}}}, if (covStubMatch !== null) {
"branchMap":{} let covStub = JSON.parse(covStubMatch[0]);
cov[file] = covStub;
} }
} }
} }