diff --git a/index.js b/index.js index 46c6d60c2..31fec4bbd 100755 --- a/index.js +++ b/index.js @@ -415,22 +415,22 @@ function coverageFinder () { } NYC.prototype.getCoverageMapFromAllCoverageFiles = function (baseDirectory) { - var _this = this var map = libCoverage.createCoverageMap({}) this.eachReport(undefined, (report) => { map.merge(report) }, baseDirectory) + + map.data = this.sourceMaps.remapCoverage(map.data) + // depending on whether source-code is pre-instrumented // or instrumented using a JIT plugin like @babel/require // you may opt to exclude files after applying // source-map remapping logic. if (this.config.excludeAfterRemap) { - map.filter(function (filename) { - return _this.exclude.shouldInstrument(filename) - }) + map.filter(filename => this.exclude.shouldInstrument(filename)) } - map.data = this.sourceMaps.remapCoverage(map.data) + return map } diff --git a/test/nyc-integration.js b/test/nyc-integration.js index 957b0c84b..3139bc346 100644 --- a/test/nyc-integration.js +++ b/test/nyc-integration.js @@ -1043,6 +1043,39 @@ describe('the nyc cli', function () { done() }) }) + + it('uses source-maps to exclude original sources from reports', (done) => { + const args = [ + bin, + '--all', + '--cache', 'false', + '--exclude', 'original/s1.js', + process.execPath, './instrumented/s1.min.js' + ] + + const proc = spawn(process.execPath, args, { + cwd: fixturesSourceMaps, + env: env + }) + + var stdout = '' + proc.stdout.on('data', function (chunk) { + stdout += chunk + }) + + proc.on('close', function (code) { + code.should.equal(0) + stdoutShouldEqual(stdout, ` + ----------|----------|----------|----------|----------|-------------------| + File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s | + ----------|----------|----------|----------|----------|-------------------| + All files | 0 | 100 | 0 | 0 | | + s2.js | 0 | 100 | 0 | 0 | 1,2,4,6 | + ----------|----------|----------|----------|----------|-------------------|` + ) + done() + }) + }) }) describe('.map file', () => {