Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support reporting coverage for tests
If `coverage` options is set, template files will be instrumented before execution (can be enabled per-technology). If templates are built with source map, there is an option to show coverage for original files. There is also an option to filter out some sources from report. By default, all content of `node_modules` and `libs` will be omitted.
- Loading branch information
Sergey Tatarintsev
committed
Nov 27, 2014
1 parent
4f49c91
commit 640985c
Showing
9 changed files
with
294 additions
and
19 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,81 @@ | ||
var _ = require('lodash'), | ||
inherit = require('inherit'); | ||
|
||
module.exports = inherit({ | ||
__constructor: function () { | ||
this._indices = { | ||
}; | ||
this.coverage = { | ||
}; | ||
}, | ||
|
||
addStatement: function (start, end, counter) { | ||
var sourceName = start.source, | ||
sourceObj = this._getFileObject(sourceName), | ||
idx = this._indices[sourceName].s++; | ||
sourceObj.statementMap[idx] = { | ||
start: getLocation(start), | ||
end: getLocation(end) | ||
}; | ||
sourceObj.s[idx] = counter; | ||
}, | ||
|
||
addFunction: function (name, start, end, counter) { | ||
var sourceName = start.source, | ||
sourceObj = this._getFileObject(sourceName), | ||
idx = this._indices[sourceName].f++; | ||
sourceObj.fnMap[idx] = { | ||
name: name, | ||
line: start.line, | ||
loc: { | ||
start: getLocation(start), | ||
end: getLocation(end) | ||
} | ||
}; | ||
|
||
sourceObj.f[idx] = counter; | ||
}, | ||
|
||
addBranch: function (type, locations, counter) { | ||
var sourceName = locations[0].start.source, | ||
sourceObj = this._getFileObject(sourceName), | ||
idx = this._indices[sourceName].b++; | ||
sourceObj.branchMap[idx] = { | ||
line: locations[0].start.line, | ||
type: type, | ||
locations: locations.map(function (loc) { | ||
return { | ||
start: getLocation(loc.start), | ||
end: getLocation(loc.end) | ||
}; | ||
}) | ||
}; | ||
sourceObj.b[idx] = counter; | ||
}, | ||
|
||
_getFileObject: function (sourceName) { | ||
var fileObject = this.coverage[sourceName]; | ||
if (!fileObject) { | ||
fileObject = this.coverage[sourceName] = { | ||
path: sourceName, | ||
s: {}, | ||
b: {}, | ||
f: {}, | ||
statementMap: {}, | ||
fnMap: {}, | ||
branchMap: {} | ||
}; | ||
|
||
this._indices[sourceName] = { | ||
s: 1, | ||
b: 1, | ||
f: 1 | ||
}; | ||
} | ||
return fileObject; | ||
} | ||
}); | ||
|
||
function getLocation(soureMapLocation) { | ||
return _.pick(soureMapLocation, 'line', 'column'); | ||
} |
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
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
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
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,15 @@ | ||
var Instrumenter = require('istanbul').Instrumenter, | ||
fs = require('vow-fs'); | ||
|
||
module.exports = require('enb/lib/build-flow').create() | ||
.name('istanbul') | ||
.target('target', '?.instrumented.js') | ||
.useSourceFilename('source', '?.js') | ||
.builder(function (source) { | ||
return fs.read(source, 'utf8') | ||
.then(function (content) { | ||
var instrumenter = new Instrumenter(); | ||
return instrumenter.instrumentSync(content, source); | ||
}); | ||
}) | ||
.createTech(); |
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
Oops, something went wrong.