From 60c869f5b1f03a4b570da358ca82566bb3dc4ba9 Mon Sep 17 00:00:00 2001 From: Bruno Jouhier Date: Mon, 1 Feb 2016 18:01:21 +0100 Subject: [PATCH 1/2] allow coverage instrumentation of multiple files --- lib/coverage.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/coverage.js b/lib/coverage.js index 7e81135..28cc635 100644 --- a/lib/coverage.js +++ b/lib/coverage.js @@ -54,7 +54,9 @@ exports.instrument = function(options) { var matcher, instrumenter; matcher = function (file) { - return file === options.code.path; + if (typeof options.coverage === 'string') return file.indexOf(options.coverage) === 0; + else if (options.coverage instanceof RegExp) return options.coverage.test(file); + else return file === options.code.path; } instrumenter = new istanbul.Instrumenter(); istanbul.hook.hookRequire(matcher, instrumenter.instrumentSync.bind(instrumenter)); From b53a7eeaa21cdbc4964ca93c4d551257f79fff93 Mon Sep 17 00:00:00 2001 From: Bruno Jouhier Date: Tue, 2 Feb 2016 11:42:31 +0100 Subject: [PATCH 2/2] use options.coverage.files + allow array of strings or regexps --- lib/coverage.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/coverage.js b/lib/coverage.js index 28cc635..3858960 100644 --- a/lib/coverage.js +++ b/lib/coverage.js @@ -54,9 +54,17 @@ exports.instrument = function(options) { var matcher, instrumenter; matcher = function (file) { - if (typeof options.coverage === 'string') return file.indexOf(options.coverage) === 0; - else if (options.coverage instanceof RegExp) return options.coverage.test(file); - else return file === options.code.path; + var files = options.coverage.files; + if (files) { + files = Array.isArray(files) ? files : [files]; + return files.some(function(f) { + if (typeof f === 'string') return file.indexOf(f) === 0; + else if (f instanceof RegExp) return f.test(file); + else throw new Error("invalid entry in options.coverage.files: " + typeof f); + }); + } else { + return file === options.code.path; + } } instrumenter = new istanbul.Instrumenter(); istanbul.hook.hookRequire(matcher, instrumenter.instrumentSync.bind(instrumenter));