File tree Expand file tree Collapse file tree 3 files changed +21
-0
lines changed Expand file tree Collapse file tree 3 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -58,6 +58,7 @@ function NYC (config) {
5858 cwd : this . cwd ,
5959 include : config . include ,
6060 exclude : config . exclude ,
61+ excludeNodeModules : config . excludeNodeModules !== false ,
6162 extension : this . extensions
6263 } )
6364
Original file line number Diff line number Diff line change @@ -89,6 +89,12 @@ Config.buildYargs = function (cwd) {
8989 description : 'should exclude logic be performed after the source-map remaps filenames?' ,
9090 global : false
9191 } )
92+ . option ( 'exclude-node-modules' , {
93+ default : true ,
94+ type : 'boolean' ,
95+ describe : 'whether or not to exclude all node_module folders (i.e. **/node_modules/**) by default' ,
96+ global : false
97+ } )
9298 . option ( 'include' , {
9399 alias : 'n' ,
94100 default : [ ] ,
Original file line number Diff line number Diff line change @@ -123,6 +123,20 @@ describe('nyc', function () {
123123 nyc . exclude . shouldInstrument ( '/cwd/foo/bar/__tests__/foo.js' , './__tests__/foo.js' ) . should . equal ( false )
124124 } )
125125
126+ it ( 'should allow turning off default node_modules exclude' , function ( ) {
127+ var nyc = new NYC ( configUtil . buildYargs ( '/cwd' ) . parse ( [
128+ '--exclude-node-modules' , 'false' ,
129+ '--exclude=**/__tests__/**' ,
130+ '--exclude=node_modules/**'
131+ ] ) )
132+ // For this test, only excluding root node_modules. Local node_modules are allowed, but we
133+ // still exclude matching items inside of local node_modules.
134+ nyc . exclude . shouldInstrument ( '/cwd/foo' , 'foo' ) . should . equal ( true )
135+ nyc . exclude . shouldInstrument ( '/cwd/node_modules/bar' , 'node_modules/bar' ) . should . equal ( false )
136+ nyc . exclude . shouldInstrument ( '/cwd/foo/node_modules/bar' , 'foo/node_modules/bar' ) . should . equal ( true )
137+ nyc . exclude . shouldInstrument ( '/cwd/foo/node_modules/bar/__tests__/baz.js' , 'foo/node_modules/bar/__tests__/baz.js' ) . should . equal ( false )
138+ } )
139+
126140 it ( 'should exclude appropriately with config.exclude' , function ( ) {
127141 var nyc = new NYC ( configUtil . buildYargs ( fixtures ) . parse ( ) )
128142
You can’t perform that action at this time.
0 commit comments