Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable additional instrumentation sources to be defined in "buster-istanbul" config section #20

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ You will need to handle this yourself. Defaults to `true`.
This can be helpful if your sources include non-js files that needed to be excluded, such as .html or .json files.
Consult [node-glob](https://github.com/isaacs/node-glob) for more information on globs.

`sources` is an array of glob paths that will be instrumented in addition to paths supplied in global sources. This
allows paths to be instrumented, but not automatically loaded. Note: This only has effect in a node environment

Write your buster test as usual.

Example project: [buster-istanbul-demo](https://github.com/kates/buster-istanbul-demo)
Expand Down
27 changes: 22 additions & 5 deletions lib/buster-istanbul.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,32 @@ var setup = {
coverage.hookRequire();
if (instrument === false) return;
group.on('load:sources', function(rs){
var rootPath = rs.rootPath
rs.forEach(function(resource){
var resourcePath = resource.path.replace(/\//, '');
var excluded = isExcluded(resourcePath, excludes);
var rootPath = rs.rootPath,
additional = group.config['buster-istanbul'].sources;

if (Array.isArray(additional)) {
additional.forEach(processAdditional);
}
rs.forEach(processResource);
function processAdditional(a) {
glob(a, function (er, files) {
if (er) {
throw er;
} else {
files.forEach(processResource);
}
});
}
function processResource(resource) {
if (typeof resource === 'object') {
resource = resource.path;
}
var resourcePath = resource.replace(/^\//, '');
var excluded = isExcluded(resourcePath, excludes);
if (!excluded) {
coverage.addInstrumentCandidate(path.join(rootPath, resourcePath));
}
});
}
});
},

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "buster-istanbul",
"description": "buster extension for istanbul code coverage.",
"version": "0.1.15",
"version": "0.1.16",
"homepage": "https://github.com/englishtown/buster-istanbul",
"author": {
"name": "kates",
Expand Down