Skip to content

Commit a314f06

Browse files
hershmirecoreyfarrell
authored andcommitted
feat: Support turning off node_modules default exclude via flag (#172)
1 parent a12cf16 commit a314f06

File tree

5 files changed

+38
-1
lines changed

5 files changed

+38
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ build/Release
3131

3232
# Dependency directories
3333
node_modules
34+
!fixtures/node_modules
3435
jspm_packages
3536

3637
# Optional npm cache directory

fixtures/node_modules/should-cover.js

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fixtures/node_modules/should-not-cover.js

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ function makeShouldSkip () {
3030
// nyc was configured in a parent process (keep these settings).
3131
config = {
3232
include: nycConfig.include,
33-
exclude: nycConfig.exclude
33+
exclude: nycConfig.exclude,
34+
// Make sure this is true unless explicitly set to `false`. `undefined` is still `true`.
35+
excludeNodeModules: nycConfig.excludeNodeModules !== false
3436
}
3537
} else {
3638
// fallback to loading config from key in package.json.

test/babel-plugin-istanbul.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,32 @@ describe('babel-plugin-istanbul', function () {
3030
result.code.should.not.match(/statementMap/)
3131
})
3232

33+
context('local node_modules', function () {
34+
it('should instrument file if shouldSkip returns false', function () {
35+
var result = babel.transformFileSync('./fixtures/node_modules/should-cover.js', {
36+
plugins: [
37+
[makeVisitor({ types: babel.types }), {
38+
excludeNodeModules: false,
39+
exclude: ['node_modules/**'],
40+
include: ['fixtures/node_modules/should-cover.js']
41+
}]
42+
]
43+
})
44+
result.code.should.match(/statementMap/)
45+
})
46+
47+
it('should not instrument file if shouldSkip returns true', function () {
48+
var result = babel.transformFileSync('./fixtures/node_modules/should-not-cover.js', {
49+
plugins: [
50+
[makeVisitor({ types: babel.types }), {
51+
include: ['fixtures/node_modules/should-not-cover.js']
52+
}]
53+
]
54+
})
55+
result.code.should.not.match(/statementMap/)
56+
})
57+
})
58+
3359
it('should call onCover callback', function () {
3460
var args
3561
babel.transformFileSync('./fixtures/plugin-should-cover.js', {

0 commit comments

Comments
 (0)