Skip to content

Commit

Permalink
feat: Support turning of node_modules default exclude via flag (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
hershmire authored and coreyfarrell committed Mar 4, 2019
1 parent 2b747cf commit 9b4b34c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/test-exclude/index.js
Expand Up @@ -14,7 +14,8 @@ class TestExclude {
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
);
Expand All @@ -41,7 +42,10 @@ class TestExclude {
this.include = false;
}

if (!this.exclude.includes('**/node_modules/**')) {
if (
this.excludeNodeModules &&
!this.exclude.includes('**/node_modules/**')
) {
this.exclude.push('**/node_modules/**');
}

Expand Down
19 changes: 19 additions & 0 deletions packages/test-exclude/test/test-exclude.js
Expand Up @@ -131,6 +131,25 @@ 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']
Expand Down

0 comments on commit 9b4b34c

Please sign in to comment.