Skip to content

Commit d9e728b

Browse files
authored
Merge pull request facebook#80 from zinserjan/fix-code-coverage
Fix code-coverage reports for ts/tsx
2 parents 0b2821f + 106599d commit d9e728b

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

packages/react-scripts/config/jest/typescriptTransform.js

+17-2
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,24 @@ if (fs.existsSync(tsconfigPath)) {
2626
}
2727

2828
module.exports = {
29-
process(src, path) {
29+
process(src, path, config, options) {
3030
if (path.endsWith('.ts') || path.endsWith('.tsx')) {
31-
return tsc.transpile(src, compilerConfig, path, []);
31+
let compilerOptions = compilerConfig;
32+
if (options.instrument) {
33+
// inline source with source map for remapping coverage
34+
compilerOptions = Object.assign({}, compilerConfig);
35+
delete compilerOptions.sourceMap;
36+
compilerOptions.inlineSourceMap = true;
37+
compilerOptions.inlineSources = true;
38+
// fix broken paths in coverage report if `.outDir` is set
39+
delete compilerOptions.outDir;
40+
}
41+
42+
const tsTranspiled = tsc.transpileModule(src, {
43+
compilerOptions: compilerOptions,
44+
fileName: path,
45+
});
46+
return tsTranspiled.outputText;
3247
}
3348
return src;
3449
},

packages/react-scripts/scripts/utils/createJestConfig.js

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ module.exports = (resolve, rootDir) => {
2323
// TODO: I don't know if it's safe or not to just use / as path separator
2424
// in Jest configs. We need help from somebody with Windows to determine this.
2525
const config = {
26+
mapCoverage: true,
2627
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}'],
2728
setupFiles: [resolve('config/polyfills.js')],
2829
setupTestFrameworkScriptFile: setupTestsFile,

0 commit comments

Comments
 (0)