Skip to content

Commit

Permalink
Support turning of node_modules default exclude via flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Eddie Leffler committed Aug 24, 2018
1 parent 829e658 commit f6e6bf6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/test-exclude/index.js
Expand Up @@ -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]
Expand All @@ -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/**')
}

Expand Down
15 changes: 15 additions & 0 deletions packages/test-exclude/test/test-exclude.js
Expand Up @@ -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']
Expand Down

0 comments on commit f6e6bf6

Please sign in to comment.