From 38087c2f03753b7726df1ee7ef487999a9c16eb4 Mon Sep 17 00:00:00 2001 From: Philip Peitsch Date: Thu, 20 Dec 2018 16:59:08 +1100 Subject: [PATCH] fix: don't double-report files with mixed slashes in their names on windows For whatever reason, the remapped coverage re-creates paths for source files with mixed slashes. This means that the reporter adds duplicate entries that differ only by the joining path separator, confusing the report writer, which fails to report the coverage on either entry. --- src/reporter.js | 7 ++++++- src/util.js | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/reporter.js b/src/reporter.js index 0075f79..f537cfc 100644 --- a/src/reporter.js +++ b/src/reporter.js @@ -102,8 +102,13 @@ function CoverageIstanbulReporter(baseReporterDecorator, logger, config) { .map; if (!coverageConfig.skipFilesWithNoCoverage) { + // On Windows, istanbul returns files with mixed forward/backslashes in them + const fixedFilePaths = {}; + remappedCoverageMap.files().forEach(path => { + fixedFilePaths[util.fixPathSeparators(path)] = true; + }); coverageMap.files().forEach(path => { - if (!(path in remappedCoverageMap)) { + if (!(util.fixPathSeparators(path) in fixedFilePaths)) { // Re-add empty coverage record remappedCoverageMap.addFileCoverage(path); } diff --git a/src/util.js b/src/util.js index 76b85a4..b54309b 100644 --- a/src/util.js +++ b/src/util.js @@ -90,6 +90,7 @@ function overrideThresholds(key, overrides, basePath) { return thresholds; } +module.exports.fixPathSeparators = fixPathSeparators; module.exports.fixWebpackSourcePaths = fixWebpackSourcePaths; module.exports.fixWebpackFilePath = fixWebpackFilePath; module.exports.overrideThresholds = overrideThresholds;