To clear Jest's cache, you can do either of the following: Use the Jest --clearCache CLI Option; Locate and Remove the Cache Directory.
Jest stores useful information in the cache, which improves the performance of your test suite. Reduced startup time Jest stores information about the file structure and mocks you create in your tests. By restoring the previous jest-haste-map data, it reduces the amount of work jest has to do at startup.
Jest will look for test files with any of the following popular naming conventions: Files with . js suffix in __tests__ folders. Files with .
As of Jest 22.0.0+, you can use the --clearCache
option:
Deletes the Jest cache directory and then exits without running tests. Will delete cacheDirectory if the option is passed, or Jest's default cache directory.
Just run:
jest --clearCache
If you have installed Jest as a dependency in your Node.js project and the jest
command doesn't work, just create a new script inside your package.json
file.
{
...
"scripts:" {
"clear_jest": "jest --clearCache"
}
...
}
And then, run in your terminal:
npm run clear_jest
With modern NPM, you could also run (credits to johny):
npx jest --clearCache
You can find the cache location by running jest --showConfig
. Look for the cacheDirectory
key. Its value is the name of the folder you'll need to remove.
First, you need to know the Jest version:
yarn jest --version
Jest >= 22.0.0
yarn jest --clearCache
Jest < 22.0.0
yarn jest --showConfig | grep cacheDir
Returns (you need to remove that folder)
"cacheDirectory": "/tmp/jest_rs",
Then, you remove it
rm -rf /tmp/jest_rs
If you don’t use Yarn, do instructions with npx jest
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With