Skip to content

Enable jest cacheDirectory configuration #3860

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
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
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 @@ -69,6 +69,7 @@ module.exports = (resolve, rootDir, isEjecting) => {
'resetModules',
'snapshotSerializers',
'watchPathIgnorePatterns',
'cacheDirectory',
];
if (overrides) {
supportedKeys.forEach(key => {
Expand Down
19 changes: 18 additions & 1 deletion packages/react-scripts/template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1539,6 +1539,10 @@ Supported overrides:
- [`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)
- [`resetMocks`](https://facebook.github.io/jest/docs/en/configuration.html#resetmocks-boolean)
- [`resetModules`](https://facebook.github.io/jest/docs/en/configuration.html#resetmodules-boolean)
- [`watchPathIgnorePatterns`](https://facebook.github.io/jest/docs/en/configuration.html#watchpathignorepatterns-array-string)
- [`cacheDirectory`](https://facebook.github.io/jest/docs/en/configuration.html#watchpathignorepatterns-array-string)

Example package.json:

Expand All @@ -1560,7 +1564,8 @@ Example package.json:
}
},
"coverageReporters": ["text"],
"snapshotSerializers": ["my-serializer-module"]
"snapshotSerializers": ["my-serializer-module"],
"cacheDirectory": ".tmp/cache/jest"
}
}
```
Expand Down Expand Up @@ -1635,6 +1640,18 @@ The test command will force Jest to run tests once instead of launching the watc

The build command will check for linter warnings and fail if any are found.

### Speeding up CI tests with jest cache

To speed up tests, Jest uses a cache. Unfortunately it saves the cache in hard-to-predict directory by default, making it difficult to save this cache in between builds on the CI environment. To counter this and make your tests run up to 2 times faster, you can specify which directory Jest should save it's cache to, by setting it in the `package.json`:

```json
"jest": {
"cacheDirectory": ".tmp/cache/jest"
}
```

And then configuring your CI to cache that directory. See guides for [Travis CI](https://docs.travis-ci.com/user/caching/#Arbitrary-directories) and [CircleCI](https://circleci.com/docs/2.0/caching/) on how to configure cache directories.

### Disabling jsdom

By default, the `package.json` of the generated project looks like this:
Expand Down