Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
Fix stats processing
Browse files Browse the repository at this point in the history
When some file was included in several tests coverage was calculated
separately for every case and report file was overwritten by the latest
iteration.

Closes #72
  • Loading branch information
scf2k authored and Sergey Tatarintsev committed Oct 21, 2014
1 parent a478e96 commit f1557e5
Showing 1 changed file with 70 additions and 44 deletions.
114 changes: 70 additions & 44 deletions lib/coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = inherit({
this.stats = [];
this.byfile = {};
this.covDir = path.resolve(this.config.projectRoot, 'gemini-coverage');
this.out = {};
},

addStats: function(stats) {
Expand Down Expand Up @@ -49,12 +50,13 @@ module.exports = inherit({
return qfs.read(path.join(__dirname, 'coverage.hbs'));
})
.then(function(tmpl) {
var reports = [];

return q.all(Object.keys(_this.byfile).map(function(file) {
return _this.processFile(file, tmpl, reports);
return _this.processFile(file);
}))
.then(function() {
return _this.makeReports(tmpl);
})
.then(function(reports) {
return prepareOutputStats(reports);
})
.then(function(stats) {
Expand All @@ -67,7 +69,7 @@ module.exports = inherit({
});
},

processFile: function(file, tmpl, reports) {
processFile: function(file, tmpl) {
var _this = this,
cssRelPath = file.replace(this.config.rootUrl, '').replace(/^\//, ''),
cssPath = path.resolve(this.config.sourceRoot, cssRelPath);
Expand All @@ -89,7 +91,7 @@ module.exports = inherit({
fileContent += '';
var lines = fileContent.split(/\r?\n/g),
ctx = {media: 0},
out = {};
out = _this.out;

for (var r = 0; r < ast.stylesheet.rules.length; r++) {
_this.processRule(
Expand All @@ -103,33 +105,6 @@ module.exports = inherit({
},
ctx);
}

return q.all(Object.keys(out).map(function(src) {
if (_this.fileExcluded(src)) {
return;
}

var reportFile = src.replace(/\//g, '_') + '.html',
reportPath = path.join(_this.covDir, reportFile);

return _this.makeReport(
{
file: path.resolve(_this.config.sourceRoot, src),
url: url.resolve(_this.config.rootUrl, src)
},
reportPath,
{
data: out[src],
tmpl: tmpl
})
.then(function(rulesStat) {
reports.push({
source: src,
report: reportFile,
stat: rulesStat
});
});
}));
});
},

Expand Down Expand Up @@ -214,22 +189,73 @@ module.exports = inherit({
path.relative(this.config.sourceRoot, path.resolve(opts.docDir, sourceStart.source)) :
opts.file.replace(this.config.rootUrl, '').replace(/^\//, '');

(opts.out[src] = opts.out[src] || []).push({
start: {
line: sourceStart.line,
column: sourceStart.column
},
end: {
line: sourceEnd.line,
column: sourceEnd.column
},
type: cls
});
var blocks = (opts.out[src] = opts.out[src] || {}),
posKey = sourceStart.line + ':' + sourceStart.column + ':' + sourceEnd.line + ':' + sourceEnd.column,
block = blocks[posKey];

if (block) {
var types = {
'none': 0,
'partial': 1,
'covered': 2
};

if (types[cls] > types[block.type]) {
block.type = cls;
}
} else {
blocks[posKey] = {
start: {
line: sourceStart.line,
column: sourceStart.column
},
end: {
line: sourceEnd.line,
column: sourceEnd.column
},
type: cls
};
}
},

makeReports: function(tmpl) {
var _this = this,
reports = [];

return q.all(Object.keys(this.out).map(function(src) {
if (_this.fileExcluded(src)) {
return;
}

var reportFile = src.replace(/\//g, '_') + '.html',
reportPath = path.join(_this.covDir, reportFile);

return _this.makeReport(
{
file: path.resolve(_this.config.sourceRoot, src),
url: url.resolve(_this.config.rootUrl, src)
},
reportPath,
{
data: _this.out[src],
tmpl: tmpl
})
.then(function(rulesStat) {
reports.push({
source: src,
report: reportFile,
stat: rulesStat
});
});
}))
.thenResolve(reports);
},

makeReport: function(source, dest, opts) {
var _this = this,
data = opts.data,
data = Object.keys(opts.data).map(function(key) {
return opts.data[key];
}),
url = source.url,
file = source.file,
coveredCount = 0,
Expand Down

0 comments on commit f1557e5

Please sign in to comment.