Skip to content
This repository was archived by the owner on Jan 26, 2019. It is now read-only.

Fix code-coverage reports for ts/tsx #80

Merged
merged 1 commit into from
Jun 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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