From b7e16cdf704bdf4935cfbc9f4a5eb228002fbc3a Mon Sep 17 00:00:00 2001 From: Eddie Date: Tue, 2 Apr 2019 11:52:19 -0600 Subject: [PATCH] feat: Support turning off node_modules default exclude via flag (#912) --- index.js | 1 + lib/config-util.js | 6 ++++++ test/src/nyc-tap.js | 14 ++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/index.js b/index.js index a0a7431af..638b50015 100755 --- a/index.js +++ b/index.js @@ -58,6 +58,7 @@ function NYC (config) { cwd: this.cwd, include: config.include, exclude: config.exclude, + excludeNodeModules: config.excludeNodeModules !== false, extension: this.extensions }) diff --git a/lib/config-util.js b/lib/config-util.js index 71d492a73..ef0e7a435 100644 --- a/lib/config-util.js +++ b/lib/config-util.js @@ -89,6 +89,12 @@ Config.buildYargs = function (cwd) { description: 'should exclude logic be performed after the source-map remaps filenames?', global: false }) + .option('exclude-node-modules', { + default: true, + type: 'boolean', + describe: 'whether or not to exclude all node_module folders (i.e. **/node_modules/**) by default', + global: false + }) .option('include', { alias: 'n', default: [], diff --git a/test/src/nyc-tap.js b/test/src/nyc-tap.js index 9cf644c40..3e60a12fb 100644 --- a/test/src/nyc-tap.js +++ b/test/src/nyc-tap.js @@ -123,6 +123,20 @@ describe('nyc', function () { nyc.exclude.shouldInstrument('/cwd/foo/bar/__tests__/foo.js', './__tests__/foo.js').should.equal(false) }) + it('should allow turning off default node_modules exclude', function () { + var nyc = new NYC(configUtil.buildYargs('/cwd').parse([ + '--exclude-node-modules', 'false', + '--exclude=**/__tests__/**', + '--exclude=node_modules/**' + ])) + // For this test, only excluding root node_modules. Local node_modules are allowed, but we + // still exclude matching items inside of local node_modules. + nyc.exclude.shouldInstrument('/cwd/foo', 'foo').should.equal(true) + nyc.exclude.shouldInstrument('/cwd/node_modules/bar', 'node_modules/bar').should.equal(false) + nyc.exclude.shouldInstrument('/cwd/foo/node_modules/bar', 'foo/node_modules/bar').should.equal(true) + nyc.exclude.shouldInstrument('/cwd/foo/node_modules/bar/__tests__/baz.js', 'foo/node_modules/bar/__tests__/baz.js').should.equal(false) + }) + it('should exclude appropriately with config.exclude', function () { var nyc = new NYC(configUtil.buildYargs(fixtures).parse())