Skip to content

Commit

Permalink
add unified coverage maps, and fix issue when using coverage without …
Browse files Browse the repository at this point in the history
…instrumentation
  • Loading branch information
jsievert authored and indexzero committed Aug 21, 2011
1 parent 3a2f697 commit 3b9acac
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions lib/vows/coverage/report-json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
var sys = require('sys'),
fs = require('fs'),
file = require('./file');

this.name = 'coverage-report-json';

this.report = function (coverageMap) {
var output = {
meta: {
"generator": "vowsjs",
"generated": new Date().toString(),
"instrumentation": "node-jscoverage",
"file-version": "1.0"
},
files: [ ],
coverage: [ ]
};


for (var filename in coverageMap) {
if (coverageMap.hasOwnProperty(filename)) {
var data = file.coverage(filename, coverageMap[filename]);

var coverage = {
file: filename,
coverage: data.coverage.toFixed(2),
hits: data.hits,
misses: data.misses,
sloc: data.sloc,
source: { }
};

for (var i = 0; i < data.source.length; i++) {
coverage.source[i + 1] = {
line: data.source[i].line,
coverage: data.source[i].coverage
};
}

output.coverage.push(coverage);

output.files.push(filename);
}
}

try {
out = fs.openSync("coverage.json", "w");
fs.writeSync(out, JSON.stringify(output));
fs.close(out);
} catch (error) {
sys.print("Error: Unable to write to file coverage.json\n");
return;
}
};

0 comments on commit 3b9acac

Please sign in to comment.