Skip to content

Commit 9c55f2b

Browse files
shenjunrucpojer
authored andcommitted
Use "inputSourceMap" for coverage re-mapping. (#4009)
* Use "inputSourceMap" for coverage re-mapping. Use "inputSourceMap" instead of read from file. The "babel-plugin-istanbul" can use the input source map from "inputSourceMap" or "inlineSourceMap". The final source map from babel is not suitable for the coverage re-mapping. The "istanbul" will ignore the "inputSourceMap", if it already registered. * Fix issue of "inputSourceMap". * Fix issue of "inputSourceMap". * Fix issue of "inputSourceMap". * Fix issue of "inputSourceMap". * Fix issue of "inputSourceMap". * Fix issue of "inputSourceMap".
1 parent f48a788 commit 9c55f2b

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

packages/jest-cli/src/reporters/coverage_reporter.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import type {
1212
AggregatedResult,
1313
CoverageMap,
14+
FileCoverage,
1415
SerializableError,
1516
TestResult,
1617
} from 'types/TestResult';
@@ -57,10 +58,20 @@ class CoverageReporter extends BaseReporter {
5758
delete testResult.coverage;
5859

5960
Object.keys(testResult.sourceMaps).forEach(sourcePath => {
60-
this._sourceMapStore.registerURL(
61-
sourcePath,
62-
testResult.sourceMaps[sourcePath],
63-
);
61+
let coverage: FileCoverage, inputSourceMap: ?Object;
62+
try {
63+
coverage = this._coverageMap.fileCoverageFor(sourcePath);
64+
({inputSourceMap} = coverage.toJSON());
65+
} finally {
66+
if (inputSourceMap) {
67+
this._sourceMapStore.registerMap(sourcePath, inputSourceMap);
68+
} else {
69+
this._sourceMapStore.registerURL(
70+
sourcePath,
71+
testResult.sourceMaps[sourcePath],
72+
);
73+
}
74+
}
6475
});
6576
}
6677
}

0 commit comments

Comments
 (0)