Skip to content

Commit

Permalink
Summarize coverage data for HTML report.
Browse files Browse the repository at this point in the history
  • Loading branch information
reid committed Apr 6, 2012
1 parent 6aa9673 commit 93dbc61
Showing 1 changed file with 40 additions and 18 deletions.
58 changes: 40 additions & 18 deletions lib/vows/coverage/report-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ function getCoverageClass( data ) {
return coverageClass;
}
this.report = function (coverageMap) {
var out, head, foot;
var out, head, foot,
files = [], summary = {
hits: 0,
misses: 0,
sloc: 0
};

try {
out = fs.openSync("coverage.html", "w");
Expand All @@ -30,25 +35,42 @@ this.report = function (coverageMap) {
for (var filename in coverageMap) {
if (coverageMap.hasOwnProperty(filename)) {
var data = file.coverage(filename, coverageMap[filename]);
var coverageClass= getCoverageClass( data );
fs.writeSync(out, "<h2>" + filename + "</h2>\n");
fs.writeSync(out, '<span class="coverage '+ coverageClass+'">' + "[ hits: " + data.hits);
fs.writeSync(out, ", misses: " + data.misses + ", sloc: " + data.sloc);
fs.writeSync(out, ", coverage: " + data.coverage.toFixed(2) + "% ]" + "</span> <a href='#' onclick='expando(this)'>[+]</a>\n");
fs.writeSync(out, "<ol class='collapsed'>\n");

for (var i = 0; i < data.source.length; i++) {
fs.writeSync(out, ' <li class="code ');
fs.writeSync(out, (data.source[i].coverage === 0 ? 'uncovered' : 'covered'));
fs.writeSync(out, '" coverage="' + data.source[i].coverage + '">');
fs.writeSync(out, data.source[i].line + "</li>\n");
}

fs.writeSync(out, "</ol>\n");
fs.writeSync(out, "<hr/>\n");
data.filename = filename;
files.push(data);
summary.hits += data.hits;
summary.misses += data.misses;
summary.sloc += data.sloc;
}
}


summary.coverage = (summary.hits / summary.sloc) * 100;

fs.writeSync(out, "<h2>All Files</h2>\n");

var coverageClass= getCoverageClass( summary );
fs.writeSync(out, '<span class="coverage ' + coverageClass + '">' + '[ hits: ' + summary.hits +
', misses: ' + summary.misses + ', sloc: ' + summary.sloc + ', coverage: ' +
summary.coverage.toFixed(2) + '%]</span>\n<hr/>\n');

files.forEach(function (data) {
var coverageClass= getCoverageClass( data );
fs.writeSync(out, "<h2>" + data.filename + "</h2>\n");
fs.writeSync(out, '<span class="coverage '+ coverageClass+'">' + "[ hits: " + data.hits);
fs.writeSync(out, ", misses: " + data.misses + ", sloc: " + data.sloc);
fs.writeSync(out, ", coverage: " + data.coverage.toFixed(2) + "% ]" + "</span> <a href='#' onclick='expando(this)'>[+]</a>\n");
fs.writeSync(out, "<ol class='collapsed'>\n");

for (var i = 0; i < data.source.length; i++) {
fs.writeSync(out, ' <li class="code ');
fs.writeSync(out, (data.source[i].coverage === 0 ? 'uncovered' : 'covered'));
fs.writeSync(out, '" coverage="' + data.source[i].coverage + '">');
fs.writeSync(out, data.source[i].line + "</li>\n");
}

fs.writeSync(out, "</ol>\n");
fs.writeSync(out, "<hr/>\n");
});

fs.writeSync(out, foot);
fs.close(out);
};

0 comments on commit 93dbc61

Please sign in to comment.