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 #912

Merged
merged 3 commits into from Apr 2, 2019
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
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