Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support turning off node_modules default exclude via flag #213

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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