diff --git a/packages/test-exclude/index.js b/packages/test-exclude/index.js index 2dc89144..2ec5480b 100644 --- a/packages/test-exclude/index.js +++ b/packages/test-exclude/index.js @@ -11,7 +11,8 @@ function TestExclude (opts) { relativePath: true, configKey: null, // the key to load config from in package.json. configPath: null, // optionally override requireMainFilename. - configFound: false + configFound: false, + excludeNodeModules: true }, opts) if (typeof this.include === 'string') this.include = [this.include] @@ -31,7 +32,7 @@ function TestExclude (opts) { this.include = false } - if (this.exclude.indexOf('**/node_modules/**') === -1) { + if (this.excludeNodeModules && this.exclude.indexOf('**/node_modules/**') === -1) { this.exclude.push('**/node_modules/**') } diff --git a/packages/test-exclude/test/test-exclude.js b/packages/test-exclude/test/test-exclude.js index 9496edc7..ae0831c3 100644 --- a/packages/test-exclude/test/test-exclude.js +++ b/packages/test-exclude/test/test-exclude.js @@ -86,6 +86,21 @@ describe('testExclude', function () { e.shouldInstrument('src/foo.js').should.equal(true) }) + it('allows node_modules default exclusion glob to be turned off, if excludeNodeModules === false', function () { + const e = exclude({ + excludeNodeModules: false, + exclude: [ + 'node_modules/**', + '**/__test__/**' + ] + }) + e.shouldInstrument('node_modules/cat.js').should.equal(false) + e.shouldInstrument('./banana/node_modules/cat.js').should.equal(true) + e.shouldInstrument('./banana/node_modules/__test__/cat.test.js').should.equal(false) + e.shouldInstrument('./banana/node_modules/__test__/cat-test.js').should.equal(false) + e.shouldInstrument('./banana/node_modules/__test__/cat.js').should.equal(false) + }) + it('allows negated exclude patterns', function () { const e = exclude({ exclude: ['foo/**', '!foo/bar.js']