From 3ad86ae280640face28f3504022872ffc5e81f2e Mon Sep 17 00:00:00 2001 From: Jeppe Reinhold Date: Thu, 18 Jan 2018 20:47:28 +0100 Subject: [PATCH 1/4] allow cacheDirectory in createJestConfig.js --- packages/react-scripts/scripts/utils/createJestConfig.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/react-scripts/scripts/utils/createJestConfig.js b/packages/react-scripts/scripts/utils/createJestConfig.js index cdea70699c0..04b8368d823 100644 --- a/packages/react-scripts/scripts/utils/createJestConfig.js +++ b/packages/react-scripts/scripts/utils/createJestConfig.js @@ -69,6 +69,7 @@ module.exports = (resolve, rootDir, isEjecting) => { 'resetModules', 'snapshotSerializers', 'watchPathIgnorePatterns', + 'cacheDirectory', ]; if (overrides) { supportedKeys.forEach(key => { From f1aa1ab8e26b9cce07b2351e931e1e6040c61005 Mon Sep 17 00:00:00 2001 From: Jeppe Reinhold Date: Thu, 18 Jan 2018 20:54:57 +0100 Subject: [PATCH 2/4] add cacheDirectory, resetMocks, resetModules and watchPathIgnorePatterns to README.md template --- packages/react-scripts/template/README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/react-scripts/template/README.md b/packages/react-scripts/template/README.md index 04dc4d9b971..07973bc13f3 100644 --- a/packages/react-scripts/template/README.md +++ b/packages/react-scripts/template/README.md @@ -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: @@ -1560,7 +1564,8 @@ Example package.json: } }, "coverageReporters": ["text"], - "snapshotSerializers": ["my-serializer-module"] + "snapshotSerializers": ["my-serializer-module"], + "cacheDirectory": ".tmp/cache/jest" } } ``` From 186089d9a4d540c37af79841869050748c9ec033 Mon Sep 17 00:00:00 2001 From: Jeppe Reinhold Date: Thu, 18 Jan 2018 21:15:18 +0100 Subject: [PATCH 3/4] add CI jest cache section to README.md --- packages/react-scripts/template/README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/react-scripts/template/README.md b/packages/react-scripts/template/README.md index 07973bc13f3..06c39c7f150 100644 --- a/packages/react-scripts/template/README.md +++ b/packages/react-scripts/template/README.md @@ -1640,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: From 36af25f540f264395169f1b164b7ddf49e769052 Mon Sep 17 00:00:00 2001 From: Jeppe Reinhold Date: Thu, 18 Jan 2018 21:18:22 +0100 Subject: [PATCH 4/4] fix indentation in README --- packages/react-scripts/template/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/react-scripts/template/README.md b/packages/react-scripts/template/README.md index 06c39c7f150..1ef9769babd 100644 --- a/packages/react-scripts/template/README.md +++ b/packages/react-scripts/template/README.md @@ -1564,8 +1564,8 @@ Example package.json: } }, "coverageReporters": ["text"], - "snapshotSerializers": ["my-serializer-module"], - "cacheDirectory": ".tmp/cache/jest" + "snapshotSerializers": ["my-serializer-module"], + "cacheDirectory": ".tmp/cache/jest" } } ``` @@ -1646,7 +1646,7 @@ To speed up tests, Jest uses a cache. Unfortunately it saves the cache in hard-t ```json "jest": { - "cacheDirectory": ".tmp/cache/jest" + "cacheDirectory": ".tmp/cache/jest" } ```