-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add unified coverage maps, and fix issue when using coverage without …
…instrumentation
- Loading branch information
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}; |