diff --git a/packages/react-scripts/scripts/utils/createJestConfig.js b/packages/react-scripts/scripts/utils/createJestConfig.js index 960b1655d..515e56364 100644 --- a/packages/react-scripts/scripts/utils/createJestConfig.js +++ b/packages/react-scripts/scripts/utils/createJestConfig.js @@ -74,6 +74,7 @@ module.exports = (resolve, rootDir, isEjecting) => { 'coverageReporters', 'coverageThreshold', 'snapshotSerializers', + 'moduleNameMapper', ]; if (overrides) { supportedKeys.forEach(key => { diff --git a/packages/react-scripts/template/README.md b/packages/react-scripts/template/README.md index db61542c9..c773d2435 100644 --- a/packages/react-scripts/template/README.md +++ b/packages/react-scripts/template/README.md @@ -1493,6 +1493,47 @@ Run `npm test -- --coverage` (note extra `--` in the middle) to include a covera Note that tests run much slower with coverage so it is recommended to run it separately from your normal workflow. +#### Configuration + +The default Jest coverage configuration can be overriden by adding any of the following supported keys to a Jest config in your package.json. + +Supported overrides: + - [`collectCoverageFrom`](https://facebook.github.io/jest/docs/en/configuration.html#collectcoveragefrom-array) + - [`coverageReporters`](https://facebook.github.io/jest/docs/en/configuration.html#coveragereporters-array-string) + - [`coverageThreshold`](https://facebook.github.io/jest/docs/en/configuration.html#coveragethreshold-object) + - [`snapshotSerializers`](https://facebook.github.io/jest/docs/en/configuration.html#snapshotserializers-array-string) + - [`moduleNameMapper`](https://facebook.github.io/jest/docs/en/configuration.html#modulenamemapper-object-string-string) + +Example package.json: + +```json +{ + "name": "your-package", + "jest": { + "collectCoverageFrom" : [ + "src/**/*.{js,jsx}", + "!/node_modules/", + "!/path/to/dir/" + ], + "coverageThreshold": { + "global": { + "branches": 90, + "functions": 90, + "lines": 90, + "statements": 90 + } + }, + "coverageReporters": ["text"], + "snapshotSerializers": ["my-serializer-module"], + "moduleNameMapper": { + "^~/(.*)$": "/src/$1" + } + } +} +``` + +Note that customizing the `moduleNameMapper` configuration will override the default (`{ '^react-native$': 'react-native-web' }`). + ### Continuous Integration By default `npm test` runs the watcher with interactive CLI. However, you can force it to run tests once and finish the process by setting an environment variable called `CI`. diff --git a/packages/react-scripts/template/tsconfig.json b/packages/react-scripts/template/tsconfig.json index 859735414..1e47f9053 100644 --- a/packages/react-scripts/template/tsconfig.json +++ b/packages/react-scripts/template/tsconfig.json @@ -1,5 +1,6 @@ { "compilerOptions": { + "baseUrl": ".", "outDir": "build/dist", "module": "esnext", "target": "es5",