From a314f06c0f3793520b00399dd91f428bb3448e3f Mon Sep 17 00:00:00 2001 From: Eddie Date: Thu, 16 May 2019 05:33:51 -0700 Subject: [PATCH] feat: Support turning off node_modules default exclude via flag (#172) --- .gitignore | 1 + fixtures/node_modules/should-cover.js | 4 ++++ fixtures/node_modules/should-not-cover.js | 4 ++++ src/index.js | 4 +++- test/babel-plugin-istanbul.js | 26 +++++++++++++++++++++++ 5 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 fixtures/node_modules/should-cover.js create mode 100644 fixtures/node_modules/should-not-cover.js diff --git a/.gitignore b/.gitignore index b52f376..a3a83c7 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,7 @@ build/Release # Dependency directories node_modules +!fixtures/node_modules jspm_packages # Optional npm cache directory diff --git a/fixtures/node_modules/should-cover.js b/fixtures/node_modules/should-cover.js new file mode 100644 index 0000000..f36f449 --- /dev/null +++ b/fixtures/node_modules/should-cover.js @@ -0,0 +1,4 @@ +let foo = function () { + console.log('foo') +} +foo() diff --git a/fixtures/node_modules/should-not-cover.js b/fixtures/node_modules/should-not-cover.js new file mode 100644 index 0000000..aa5da74 --- /dev/null +++ b/fixtures/node_modules/should-not-cover.js @@ -0,0 +1,4 @@ +let bar = function () { + console.log('bar') +} +bar() diff --git a/src/index.js b/src/index.js index 44fba93..9536aeb 100644 --- a/src/index.js +++ b/src/index.js @@ -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. diff --git a/test/babel-plugin-istanbul.js b/test/babel-plugin-istanbul.js index 5abcafd..03405b9 100644 --- a/test/babel-plugin-istanbul.js +++ b/test/babel-plugin-istanbul.js @@ -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', {