Skip to content

Commit

Permalink
feat: exclude unexpected file in sourcemap result
Browse files Browse the repository at this point in the history
  • Loading branch information
bvanjoi committed Jan 24, 2022
1 parent 6ca0e6a commit 9b25d8e
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/report.js
Expand Up @@ -127,6 +127,15 @@ class Report {
map.merge(converter.toIstanbul())
}
}

if (!this.all) {
for (const fileURL in map.data) {
if (!this.exclude.shouldInstrument(fileURL)) {
delete map.data[fileURL]
}
}
}

this._allCoverageFiles = map
return this._allCoverageFiles
}
Expand Down
58 changes: 58 additions & 0 deletions test/fixtures/bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions test/fixtures/bundle.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions test/integration.js
Expand Up @@ -646,4 +646,16 @@ describe('c8', () => {
output.toString('utf8').should.matchSnapshot()
})
})

it('exclude unexpected file in result', () => {
const { output } = spawnSync(nodePath, [
c8Path,
'--exclude="test/*.js"',
'--temp-directory=tmp/bundle',
'--clean=false',
nodePath,
require.resolve('./fixtures/bundle.js')
])
output.toString('utf8').should.matchSnapshot()
})
})
11 changes: 11 additions & 0 deletions test/integration.js.snap
Expand Up @@ -330,6 +330,17 @@ All files | 75 | 50 | 100 | 75 |
,"
`;
exports[`c8 exclude unexpected file in result 1`] = `
",reachable
----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 100 | 100 | 100 | 100 |
index.js | 100 | 100 | 100 | 100 |
----------|---------|----------|---------|---------|-------------------
,"
`;
exports[`c8 merges reports from subprocesses together 1`] = `
",first
Expand Down

0 comments on commit 9b25d8e

Please sign in to comment.