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

Commit e17362e

Browse files
sebaldDorianGrey
authored andcommitted
Allow moduleNameMapper config override (#303)
* Allow `moduleNameMapper` config override * Add jest configuration section to the readme * Add note about overriding default moduleNameMapper
1 parent 10b727f commit e17362e

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

Diff for: packages/react-scripts/scripts/utils/createJestConfig.js

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ module.exports = (resolve, rootDir, isEjecting) => {
7474
'coverageReporters',
7575
'coverageThreshold',
7676
'snapshotSerializers',
77+
'moduleNameMapper',
7778
];
7879
if (overrides) {
7980
supportedKeys.forEach(key => {

Diff for: packages/react-scripts/template/README.md

+41
Original file line numberDiff line numberDiff line change
@@ -1493,6 +1493,47 @@ Run `npm test -- --coverage` (note extra `--` in the middle) to include a covera
14931493
14941494
Note that tests run much slower with coverage so it is recommended to run it separately from your normal workflow.
14951495
1496+
#### Configuration
1497+
1498+
The default Jest coverage configuration can be overriden by adding any of the following supported keys to a Jest config in your package.json.
1499+
1500+
Supported overrides:
1501+
- [`collectCoverageFrom`](https://facebook.github.io/jest/docs/en/configuration.html#collectcoveragefrom-array)
1502+
- [`coverageReporters`](https://facebook.github.io/jest/docs/en/configuration.html#coveragereporters-array-string)
1503+
- [`coverageThreshold`](https://facebook.github.io/jest/docs/en/configuration.html#coveragethreshold-object)
1504+
- [`snapshotSerializers`](https://facebook.github.io/jest/docs/en/configuration.html#snapshotserializers-array-string)
1505+
- [`moduleNameMapper`](https://facebook.github.io/jest/docs/en/configuration.html#modulenamemapper-object-string-string)
1506+
1507+
Example package.json:
1508+
1509+
```json
1510+
{
1511+
"name": "your-package",
1512+
"jest": {
1513+
"collectCoverageFrom" : [
1514+
"src/**/*.{js,jsx}",
1515+
"!<rootDir>/node_modules/",
1516+
"!<rootDir>/path/to/dir/"
1517+
],
1518+
"coverageThreshold": {
1519+
"global": {
1520+
"branches": 90,
1521+
"functions": 90,
1522+
"lines": 90,
1523+
"statements": 90
1524+
}
1525+
},
1526+
"coverageReporters": ["text"],
1527+
"snapshotSerializers": ["my-serializer-module"],
1528+
"moduleNameMapper": {
1529+
"^~/(.*)$": "<rootDir>/src/$1"
1530+
}
1531+
}
1532+
}
1533+
```
1534+
1535+
Note that customizing the `moduleNameMapper` configuration will override the default (`{ '^react-native$': 'react-native-web' }`).
1536+
14961537
### Continuous Integration
14971538

14981539
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 for: packages/react-scripts/template/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"compilerOptions": {
3+
"baseUrl": ".",
34
"outDir": "build/dist",
45
"module": "esnext",
56
"target": "es5",

0 commit comments

Comments
 (0)