Skip to content

Commit

Permalink
fix: Drop coverage produced by nyc --all for files that were tested (
Browse files Browse the repository at this point in the history
…#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
  • Loading branch information
coreyfarrell authored Aug 2, 2019
1 parent 7783284 commit fc1bbbf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,11 @@ class NYC {
const coverage = coverageFinder()
const lastCoverage = this.instrumenter().lastFileCoverage()
if (lastCoverage) {
coverage[lastCoverage.path] = lastCoverage
coverage[lastCoverage.path] = {
...lastCoverage,
// Only use this data if we don't have it without `all: true`
all: true
}
}
})
this.fakeRequire = false
Expand Down
3 changes: 1 addition & 2 deletions lib/instrumenters/noop.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
const { FileCoverage } = require('istanbul-lib-coverage').classes
const { readInitialCoverage } = require('istanbul-lib-instrument')

function NOOP () {
return {
instrumentSync (code, filename) {
const extracted = readInitialCoverage(code)
if (extracted) {
this.fileCoverage = new FileCoverage(extracted.coverageData)
this.fileCoverage = extracted.coverageData
} else {
this.fileCoverage = null
}
Expand Down

1 comment on commit fc1bbbf

@Oloompa
Copy link

@Oloompa Oloompa commented on fc1bbbf Sep 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has this fix been published to npm ?

I ask cause i still have the same issue it's supposed to fix.

Please sign in to comment.