Skip to content

Commit

Permalink
Merge pull request facebook#80 from zinserjan/fix-code-coverage
Browse files Browse the repository at this point in the history
Fix code-coverage reports for ts/tsx
  • Loading branch information
wmonk authored Jun 23, 2017
2 parents 0b2821f + 106599d commit d9e728b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
19 changes: 17 additions & 2 deletions packages/react-scripts/config/jest/typescriptTransform.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,24 @@ if (fs.existsSync(tsconfigPath)) {
}

module.exports = {
process(src, path) {
process(src, path, config, options) {
if (path.endsWith('.ts') || path.endsWith('.tsx')) {
return tsc.transpile(src, compilerConfig, path, []);
let compilerOptions = compilerConfig;
if (options.instrument) {
// inline source with source map for remapping coverage
compilerOptions = Object.assign({}, compilerConfig);
delete compilerOptions.sourceMap;
compilerOptions.inlineSourceMap = true;
compilerOptions.inlineSources = true;
// fix broken paths in coverage report if `.outDir` is set
delete compilerOptions.outDir;
}

const tsTranspiled = tsc.transpileModule(src, {
compilerOptions: compilerOptions,
fileName: path,
});
return tsTranspiled.outputText;
}
return src;
},
Expand Down
1 change: 1 addition & 0 deletions packages/react-scripts/scripts/utils/createJestConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = (resolve, rootDir) => {
// TODO: I don't know if it's safe or not to just use / as path separator
// in Jest configs. We need help from somebody with Windows to determine this.
const config = {
mapCoverage: true,
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}'],
setupFiles: [resolve('config/polyfills.js')],
setupTestFrameworkScriptFile: setupTestsFile,
Expand Down

0 comments on commit d9e728b

Please sign in to comment.