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

Conversation

JReinhold
Copy link

Fixes #2687 .

Enables the user to override Jest's cacheDirectory configuration, mainly to make it easier for users to speed up their builds on CI, by caching jest's cache in between builds.

How I tested

  • Test that it breaks without modification
    • Don't modify anything.
    • Add "jest": { "cacheDirectory": "tmp/jest-cache" } to /packages/react-scripts/package.json
    • Run yarn test
    • See that it complaints about overriding cacheDirectory
  • Test that it works with modified code
    • Add modification to code
    • Repeat above
    • See that it doesn't complain
    • See that a new folder tmp/jest-cache is created in /packages/react-scripts/template/
    • Re-run tests
    • See that it still works
  • Test that it works in generated app
    • run yarn create-react-app a-test-app
    • Repeat above steps in the newly generated app
    • See that it still works

Documentation

I've added cacheDirectory to the list of supported overrides in the template README.md. I've also added resetMocks, resetModules and watchPathIgnorePattern as they weirdly wasn't on the list, even though the are supported. If they are omitted on purpose, I'm sorry, I'll remove them again.
I've also added a short section about using the cacheDirectory option to speed up tests on CI.

Future work

Should this be accepted, I'll gladly looking into speeding up this repos tests using the cacheDirectory pattern. However I'm inexperienced with TravisCI so I might come up short. Please let me know in the comments if I should pursue this or not.

@lukebatchelor
Copy link

Heya @JReinhold I've just stumbled across this whilst trying to set this up to speed up our CI builds. I had assumed this was already an option as it's listed in the docs (https://facebook.github.io/jest/docs/en/configuration.html#cachedirectory-string).

Would you happen to know how it got there without this being merged?

If it means anything, this will be super helpful for us. Not just for the CI speed up, but because we are trying to debug a really painful edgecase to do with transformers that only occurs in CI and only very occasionally, this will help us zip up the cached transformed files and upload to s3 when it fails.

@lukebatchelor
Copy link

lukebatchelor commented Feb 21, 2018

Oh.. To make this even stranger, I found this because it looked like it wasn't working for me locally but it turned out it did work, my editor was just not indexing node_modules

  cacheDirectory: 'node_modules/.jest-cache',
$ yarn jest --showConfig

$ /Users/lbatchelor/src/atlaskit-mk-2/node_modules/.bin/jest --showConfig
{
  "config": {
    "automock": false,
    "browser": false,
    "cache": true,
    "cacheDirectory": "/Users/lbatchelor/src/atlaskit-mk-2/node_modules/.jest-cache",
    "clearMocks": false,

And sure enough, I can see the cache in that directory.

Tested in CI and got pretty great results too! (6:55min -> 2:25min to run around 6k tests)

I'm using

yarn 1.3.2
node 8.5.0
jest 20.0.4
jest-cli 20.0.4

if that helps.

@JReinhold
Copy link
Author

@lukebatchelor this might be a stupid question, but do you realize that this is a PR for create-react-app itself, and doesn't have anything to do with jest? Are you using create-react-app or are you just using jest? The reason I'm asking, is that it seems rather strange to me that you can actually make cacheDirectory work without getting any errors, because it doesn't work right now in create-react-app, however when just using plain jest it should work out of the box.
If you are in fact using create-react-app then you've probably come to the right place, and posting your package.json and relevant CI script could make it easier to figure out what's going on.

@lukebatchelor
Copy link

You are 1000% correct. I was very confused, hahaha. Thanks!

@Timer Timer closed this Sep 26, 2018
@Timer Timer reopened this Sep 26, 2018
@gaearon gaearon closed this Nov 1, 2018
@lock lock bot locked and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants