From fc1bbbf490f6ab0272359ce10ceb4987d1716256 Mon Sep 17 00:00:00 2001 From: Corey Farrell Date: Fri, 2 Aug 2019 08:51:53 -0400 Subject: [PATCH] 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 --- index.js | 6 +++++- lib/instrumenters/noop.js | 3 +-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 60130c2e0..791da87b1 100755 --- a/index.js +++ b/index.js @@ -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 diff --git a/lib/instrumenters/noop.js b/lib/instrumenters/noop.js index a134ea5dd..7efe8bd80 100644 --- a/lib/instrumenters/noop.js +++ b/lib/instrumenters/noop.js @@ -1,4 +1,3 @@ -const { FileCoverage } = require('istanbul-lib-coverage').classes const { readInitialCoverage } = require('istanbul-lib-instrument') function NOOP () { @@ -6,7 +5,7 @@ function NOOP () { instrumentSync (code, filename) { const extracted = readInitialCoverage(code) if (extracted) { - this.fileCoverage = new FileCoverage(extracted.coverageData) + this.fileCoverage = extracted.coverageData } else { this.fileCoverage = null }