From 57832e1acc4f770cc19f0d056cf4d0f8e0e4000b Mon Sep 17 00:00:00 2001 From: Corey Farrell Date: Thu, 1 Aug 2019 16:07:18 -0400 Subject: [PATCH] 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 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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