Skip to content

Commit 4d03a0f

Browse files
committed
feat: exclude unexpected file in sourcemap result
1 parent 49c45b3 commit 4d03a0f

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
@@ -128,6 +128,15 @@ class Report {
128128
map.merge(converter.toIstanbul())
129129
}
130130
}
131+
132+
if (!this.all) {
133+
for (const fileURL in map.data) {
134+
if (!this.exclude.shouldInstrument(fileURL)) {
135+
delete map.data[fileURL]
136+
}
137+
}
138+
}
139+
131140
this._allCoverageFiles = map
132141
return this._allCoverageFiles
133142
}

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
@@ -289,6 +289,17 @@ All files | 75 | 50 | 100 | 75 |
289289
,"
290290
`;
291291
292+
exports[`c8 exclude unexpected file in result 1`] = `
293+
",reachable
294+
----------|---------|----------|---------|---------|-------------------
295+
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
296+
----------|---------|----------|---------|---------|-------------------
297+
All files | 100 | 100 | 100 | 100 |
298+
index.js | 100 | 100 | 100 | 100 |
299+
----------|---------|----------|---------|---------|-------------------
300+
,"
301+
`;
302+
292303
exports[`c8 merges reports from subprocesses together 1`] = `
293304
",first
294305

0 commit comments

Comments
 (0)