Skip to content

Commit

Permalink
feat: Support turning off node_modules default exclude via flag (#912)
Browse files Browse the repository at this point in the history
  • Loading branch information
hershmire authored and coreyfarrell committed Apr 2, 2019
1 parent 3eb0e37 commit b7e16cd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.js
Expand Up @@ -58,6 +58,7 @@ function NYC (config) {
cwd: this.cwd,
include: config.include,
exclude: config.exclude,
excludeNodeModules: config.excludeNodeModules !== false,
extension: this.extensions
})

Expand Down
6 changes: 6 additions & 0 deletions lib/config-util.js
Expand Up @@ -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: [],
Expand Down
14 changes: 14 additions & 0 deletions test/src/nyc-tap.js
Expand Up @@ -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())

Expand Down

0 comments on commit b7e16cd

Please sign in to comment.