Skip to content

Commit fc1bbbf

Browse files
authored
fix: Drop coverage produced by nyc --all for files that were tested (#1155)
* fix: Drop coverage produced by `nyc --all` for files that were tested Sometimes the coverage data produced by `nyc --all` is incompatible with the coverage data produced by actual test runs. This is generally due to configuration error but results in inconsistent coverage reports or in some cases causes `nyc report` to crash. The workaround is implemented in istanbul-lib-coverage to drop coverage data associated with `nyc --all` when coverage data from a test run is found. This commit tags the coverage data when appropriate so the coverage merge logic knows what to do. Fixes #1113, #1124, #1148
1 parent 7783284 commit fc1bbbf

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,11 @@ class NYC {
170170
const coverage = coverageFinder()
171171
const lastCoverage = this.instrumenter().lastFileCoverage()
172172
if (lastCoverage) {
173-
coverage[lastCoverage.path] = lastCoverage
173+
coverage[lastCoverage.path] = {
174+
...lastCoverage,
175+
// Only use this data if we don't have it without `all: true`
176+
all: true
177+
}
174178
}
175179
})
176180
this.fakeRequire = false

lib/instrumenters/noop.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
const { FileCoverage } = require('istanbul-lib-coverage').classes
21
const { readInitialCoverage } = require('istanbul-lib-instrument')
32

43
function NOOP () {
54
return {
65
instrumentSync (code, filename) {
76
const extracted = readInitialCoverage(code)
87
if (extracted) {
9-
this.fileCoverage = new FileCoverage(extracted.coverageData)
8+
this.fileCoverage = extracted.coverageData
109
} else {
1110
this.fileCoverage = null
1211
}

0 commit comments

Comments
 (0)