File tree Expand file tree Collapse file tree 2 files changed +38
-5
lines changed Expand file tree Collapse file tree 2 files changed +38
-5
lines changed Original file line number Diff line number Diff line change @@ -415,22 +415,22 @@ function coverageFinder () {
415415}
416416
417417NYC . prototype . getCoverageMapFromAllCoverageFiles = function ( baseDirectory ) {
418- var _this = this
419418 var map = libCoverage . createCoverageMap ( { } )
420419
421420 this . eachReport ( undefined , ( report ) => {
422421 map . merge ( report )
423422 } , baseDirectory )
423+
424+ map . data = this . sourceMaps . remapCoverage ( map . data )
425+
424426 // depending on whether source-code is pre-instrumented
425427 // or instrumented using a JIT plugin like @babel /require
426428 // you may opt to exclude files after applying
427429 // source-map remapping logic.
428430 if ( this . config . excludeAfterRemap ) {
429- map . filter ( function ( filename ) {
430- return _this . exclude . shouldInstrument ( filename )
431- } )
431+ map . filter ( filename => this . exclude . shouldInstrument ( filename ) )
432432 }
433- map . data = this . sourceMaps . remapCoverage ( map . data )
433+
434434 return map
435435}
436436
Original file line number Diff line number Diff line change @@ -1043,6 +1043,39 @@ describe('the nyc cli', function () {
10431043 done ( )
10441044 } )
10451045 } )
1046+
1047+ it ( 'uses source-maps to exclude original sources from reports' , ( done ) => {
1048+ const args = [
1049+ bin ,
1050+ '--all' ,
1051+ '--cache' , 'false' ,
1052+ '--exclude' , 'original/s1.js' ,
1053+ process . execPath , './instrumented/s1.min.js'
1054+ ]
1055+
1056+ const proc = spawn ( process . execPath , args , {
1057+ cwd : fixturesSourceMaps ,
1058+ env : env
1059+ } )
1060+
1061+ var stdout = ''
1062+ proc . stdout . on ( 'data' , function ( chunk ) {
1063+ stdout += chunk
1064+ } )
1065+
1066+ proc . on ( 'close' , function ( code ) {
1067+ code . should . equal ( 0 )
1068+ stdoutShouldEqual ( stdout , `
1069+ ----------|----------|----------|----------|----------|-------------------|
1070+ File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
1071+ ----------|----------|----------|----------|----------|-------------------|
1072+ All files | 0 | 100 | 0 | 0 | |
1073+ s2.js | 0 | 100 | 0 | 0 | 1,2,4,6 |
1074+ ----------|----------|----------|----------|----------|-------------------|`
1075+ )
1076+ done ( )
1077+ } )
1078+ } )
10461079 } )
10471080
10481081 describe ( '.map file' , ( ) => {
You can’t perform that action at this time.
0 commit comments