Skip to content

Commit

Permalink
Allow moduleNameMapper config override (facebook#303)
Browse files Browse the repository at this point in the history
* Allow `moduleNameMapper` config override

* Add jest configuration section to the readme

* Add note about overriding default moduleNameMapper
  • Loading branch information
sebald authored and DorianGrey committed May 9, 2018
1 parent 10b727f commit e17362e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
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 @@ -74,6 +74,7 @@ module.exports = (resolve, rootDir, isEjecting) => {
'coverageReporters',
'coverageThreshold',
'snapshotSerializers',
'moduleNameMapper',
];
if (overrides) {
supportedKeys.forEach(key => {
Expand Down
41 changes: 41 additions & 0 deletions packages/react-scripts/template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
"!<rootDir>/node_modules/",
"!<rootDir>/path/to/dir/"
],
"coverageThreshold": {
"global": {
"branches": 90,
"functions": 90,
"lines": 90,
"statements": 90
}
},
"coverageReporters": ["text"],
"snapshotSerializers": ["my-serializer-module"],
"moduleNameMapper": {
"^~/(.*)$": "<rootDir>/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`.
Expand Down
1 change: 1 addition & 0 deletions packages/react-scripts/template/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"baseUrl": ".",
"outDir": "build/dist",
"module": "esnext",
"target": "es5",
Expand Down

0 comments on commit e17362e

Please sign in to comment.