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

Merged
merged 1 commit into from May 16, 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 .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 @@ -29,7 +29,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