Skip to content

Commit

Permalink
feat: Fix excludeAfterRemap functionality.
Browse files Browse the repository at this point in the history
Previously excludeAfterRemap caused filtering to happen before remapping
to original source filenames.  This caused the filtering to be
completely ineffective.  Fix the order, add a test to verify
functionality.
  • Loading branch information
coreyfarrell committed Mar 7, 2019
1 parent bc5996a commit 36bcc0b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
33 changes: 33 additions & 0 deletions test/nyc-integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 36bcc0b

Please sign in to comment.