Skip to content

Commit b0d6832

Browse files
committed
Merge pull request #125 from Sage/directory-coverage
allow coverage instrumentation of multiple files
2 parents f6981b3 + b53a7ee commit b0d6832

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

lib/coverage.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,17 @@ exports.instrument = function(options) {
5454
var matcher, instrumenter;
5555

5656
matcher = function (file) {
57-
return file === options.code.path;
57+
var files = options.coverage.files;
58+
if (files) {
59+
files = Array.isArray(files) ? files : [files];
60+
return files.some(function(f) {
61+
if (typeof f === 'string') return file.indexOf(f) === 0;
62+
else if (f instanceof RegExp) return f.test(file);
63+
else throw new Error("invalid entry in options.coverage.files: " + typeof f);
64+
});
65+
} else {
66+
return file === options.code.path;
67+
}
5868
}
5969
instrumenter = new istanbul.Instrumenter();
6070
istanbul.hook.hookRequire(matcher, instrumenter.instrumentSync.bind(instrumenter));

0 commit comments

Comments
 (0)