Skip to content

Commit

Permalink
Merge branch 'exclude-after-remap-always-100'
Browse files Browse the repository at this point in the history
  • Loading branch information
prantlf committed Apr 2, 2023
2 parents 985b219 + 9113449 commit 52269c9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
21 changes: 19 additions & 2 deletions lib/report.js
Expand Up @@ -98,11 +98,14 @@ class Report {
try {
const sources = this._getSourceMap(v8ScriptCov)
const path = resolve(this.resolve, v8ScriptCov.url)
const converter = v8toIstanbul(path, this.wrapperLength, sources, (path) => {
const converter = v8toIstanbul(path, this.wrapperLength, sources
// v8toIstanbul sets all coverage stats of the remaining files
// to 100, if some files are excluded here. See below.
/*, (path) => {
if (this.excludeAfterRemap) {
return !this._shouldInstrument(path)
}
})
} */)
await converter.load()

if (resultCountPerPath.has(path)) {
Expand Down Expand Up @@ -131,6 +134,20 @@ class Report {
map.merge(converter.toIstanbul())
}
}

// Workaround for too early applied excludeAfterRemap above -
// v8toIstanbul sets all coverage stats of the remaining files
// to 100, if some files are excluded by the excludePath callback.
if (this.excludeAfterRemap) {
const { data } = map
map.data = Object.keys(data).reduce((result, key) => {
if (this._shouldInstrument(key)) {
result[key] = data[key]
}
return result
}, {})
}

this._allCoverageFiles = map
return this._allCoverageFiles
}
Expand Down
4 changes: 2 additions & 2 deletions test/integration.js.snap
Expand Up @@ -156,7 +156,7 @@ hey
---------------------------------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
---------------------------------------|---------|----------|---------|---------|-------------------
All files | 1.91 | 12 | 6.25 | 1.91 |
All files | 1.89 | 12 | 6.25 | 1.89 |
c8 | 0 | 0 | 0 | 0 |
index.js | 0 | 0 | 0 | 0 | 1
c8/bin | 0 | 0 | 0 | 0 |
Expand All @@ -168,7 +168,7 @@ All files | 1.91 | 12 | 6.25 | 1.91
c8/lib | 0 | 0 | 0 | 0 |
is-cjs-esm-bridge.js | 0 | 0 | 0 | 0 | 1-10
parse-args.js | 0 | 0 | 0 | 0 | 1-218
report.js | 0 | 0 | 0 | 0 | 1-340
report.js | 0 | 0 | 0 | 0 | 1-357
source-map-from-file.js | 0 | 0 | 0 | 0 | 1-100
c8/lib/commands | 0 | 0 | 0 | 0 |
check-coverage.js | 0 | 0 | 0 | 0 | 1-70
Expand Down

0 comments on commit 52269c9

Please sign in to comment.