Skip to content

Commit

Permalink
feat: Support turning off node_modules default exclude via flag (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
hershmire authored and coreyfarrell committed May 16, 2019
1 parent a12cf16 commit a314f06
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -31,6 +31,7 @@ build/Release

# Dependency directories
node_modules
!fixtures/node_modules
jspm_packages

# Optional npm cache directory
Expand Down
4 changes: 4 additions & 0 deletions fixtures/node_modules/should-cover.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions fixtures/node_modules/should-not-cover.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/index.js
Expand Up @@ -30,7 +30,9 @@ function makeShouldSkip () {
// nyc was configured in a parent process (keep these settings).
config = {
include: nycConfig.include,
exclude: nycConfig.exclude
exclude: nycConfig.exclude,
// Make sure this is true unless explicitly set to `false`. `undefined` is still `true`.
excludeNodeModules: nycConfig.excludeNodeModules !== false
}
} else {
// fallback to loading config from key in package.json.
Expand Down
26 changes: 26 additions & 0 deletions test/babel-plugin-istanbul.js
Expand Up @@ -30,6 +30,32 @@ describe('babel-plugin-istanbul', function () {
result.code.should.not.match(/statementMap/)
})

context('local node_modules', function () {
it('should instrument file if shouldSkip returns false', function () {
var result = babel.transformFileSync('./fixtures/node_modules/should-cover.js', {
plugins: [
[makeVisitor({ types: babel.types }), {
excludeNodeModules: false,
exclude: ['node_modules/**'],
include: ['fixtures/node_modules/should-cover.js']
}]
]
})
result.code.should.match(/statementMap/)
})

it('should not instrument file if shouldSkip returns true', function () {
var result = babel.transformFileSync('./fixtures/node_modules/should-not-cover.js', {
plugins: [
[makeVisitor({ types: babel.types }), {
include: ['fixtures/node_modules/should-not-cover.js']
}]
]
})
result.code.should.not.match(/statementMap/)
})
})

it('should call onCover callback', function () {
var args
babel.transformFileSync('./fixtures/plugin-should-cover.js', {
Expand Down

0 comments on commit a314f06

Please sign in to comment.