From 7e9764c715183341cef8afe16c443d5cc493f03c Mon Sep 17 00:00:00 2001 From: Sebastian Sebald Date: Wed, 11 Apr 2018 11:52:29 +0200 Subject: [PATCH 1/3] Allow `moduleNameMapper` config override --- packages/react-scripts/scripts/utils/createJestConfig.js | 1 + packages/react-scripts/template/tsconfig.json | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/react-scripts/scripts/utils/createJestConfig.js b/packages/react-scripts/scripts/utils/createJestConfig.js index 3040471da..168187142 100644 --- a/packages/react-scripts/scripts/utils/createJestConfig.js +++ b/packages/react-scripts/scripts/utils/createJestConfig.js @@ -75,6 +75,7 @@ module.exports = (resolve, rootDir, isEjecting) => { 'coverageReporters', 'coverageThreshold', 'snapshotSerializers', + 'moduleNameMapper', ]; if (overrides) { supportedKeys.forEach(key => { 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", From 7a8d8fd28820eea46eb2accdbd6bad41bdaf8f6d Mon Sep 17 00:00:00 2001 From: Sebastian Sebald Date: Tue, 8 May 2018 11:26:19 +0200 Subject: [PATCH 2/3] Add jest configuration section to the readme --- packages/react-scripts/template/README.md | 39 +++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/packages/react-scripts/template/README.md b/packages/react-scripts/template/README.md index db61542c9..1b9d31377 100644 --- a/packages/react-scripts/template/README.md +++ b/packages/react-scripts/template/README.md @@ -1493,6 +1493,45 @@ 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" + } + } +} +``` + ### 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`. From 7c910a4dcc248f6584a7f702a25f4a7fa0df8cd2 Mon Sep 17 00:00:00 2001 From: Sebastian Sebald Date: Tue, 8 May 2018 11:29:07 +0200 Subject: [PATCH 3/3] Add note about overriding default moduleNameMapper --- packages/react-scripts/template/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/react-scripts/template/README.md b/packages/react-scripts/template/README.md index 1b9d31377..c773d2435 100644 --- a/packages/react-scripts/template/README.md +++ b/packages/react-scripts/template/README.md @@ -1532,6 +1532,8 @@ Example package.json: } ``` +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`.