Skip to content

Commit 24b544a

Browse files
committed
feat: exclude unexpected file in sourcemap result
1 parent 6ca0e6a commit 24b544a

File tree

5 files changed

+97
-0
lines changed

5 files changed

+97
-0
lines changed

lib/report.js

+9
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,15 @@ class Report {
127127
map.merge(converter.toIstanbul())
128128
}
129129
}
130+
131+
if (!this.all) {
132+
for (const fileURL in map.data) {
133+
if (!this.exclude.shouldInstrument(fileURL)) {
134+
delete map.data[fileURL]
135+
}
136+
}
137+
}
138+
130139
this._allCoverageFiles = map
131140
return this._allCoverageFiles
132141
}

test/fixtures/bundle.js

+58
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/bundle.js.map

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/integration.js

+12
Original file line numberDiff line numberDiff line change
@@ -646,4 +646,16 @@ describe('c8', () => {
646646
output.toString('utf8').should.matchSnapshot()
647647
})
648648
})
649+
650+
it('exclude unexpected file in result', () => {
651+
const { output } = spawnSync(nodePath, [
652+
c8Path,
653+
'--exclude="test/*.js"',
654+
'--temp-directory=tmp/bundle',
655+
'--clean=false',
656+
nodePath,
657+
require.resolve('./fixtures/bundle.js')
658+
])
659+
output.toString('utf8').should.matchSnapshot()
660+
})
649661
})

test/integration.js.snap

+11
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,17 @@ All files | 75 | 50 | 100 | 75 |
330330
,"
331331
`;
332332
333+
exports[`c8 exclude unexpected file in result 1`] = `
334+
",unreachable
335+
----------|---------|----------|---------|---------|-------------------
336+
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
337+
----------|---------|----------|---------|---------|-------------------
338+
All files | 100 | 100 | 100 | 100 |
339+
index.js | 100 | 100 | 100 | 100 |
340+
----------|---------|----------|---------|---------|-------------------
341+
,"
342+
`;
343+
333344
exports[`c8 merges reports from subprocesses together 1`] = `
334345
",first
335346

0 commit comments

Comments
 (0)