Jest: Cache files created regardless of cache config setting or command line options

Created on 28 Nov 2016  路  4Comments  路  Source: facebook/jest

When running jest with either "cache": false in the config or --no-cache in the command line (or both) files are still created in the cache folder. This happens whether or not a cacheDirectory has been specified in the config or it is using the default cache directory. I would expect it to not write any files into a cache folder.

I am running jest on Windows 7, npm version 3.10.3. Debug output:

jest version = 17.0.3
test framework = jasmine2
config = {
"cache": false,
"rootDir": "D:\Stash\Temp\JestCacheTest",
"name": "D:-Stash-Temp-JestCacheTest",
"setupFiles": [],
"testRunner": "D:\Stash\Temp\JestCacheTest\node_modules\jest-jasmine2\build\index.js",
"transform": [
[
"^.+\.jsx?$",
"D:\Stash\Temp\JestCacheTest\node_modules\babel-jest\build\index.js"
]
],
"usesBabelJest": true,
"automock": false,
"bail": false,
"browser": false,
"cacheDirectory": "C:\Users\paget2\AppData\Local\Temp\jest",
"coveragePathIgnorePatterns": [
"\\node_modules\\"
],
"coverageReporters": [
"json",
"text",
"lcov",
"clover"
],
"expand": false,
"globals": {},
"haste": {
"providesModuleNodeModules": []
},
"mocksPattern": "__mocks__",
"moduleDirectories": [
"node_modules"
],
"moduleFileExtensions": [
"js",
"json",
"jsx",
"node"
],
"moduleNameMapper": {},
"modulePathIgnorePatterns": [],
"noStackTrace": false,
"notify": false,
"preset": null,
"resetMocks": false,
"resetModules": false,
"snapshotSerializers": [],
"testEnvironment": "jest-environment-jsdom",
"testPathDirs": [
"D:\Stash\Temp\JestCacheTest"
],
"testPathIgnorePatterns": [
"\\node_modules\\"
],
"testRegex": "(/__tests__/.*|\.(test|spec))\.jsx?$",
"testURL": "about:blank",
"timers": "real",
"transformIgnorePatterns": [
"\\node_modules\\"
],
"useStderr": false,
"verbose": null,
"watch": false,
"watchman": true
}
PASS .index.test.js
JestCacheTest
v should pass (2ms)

Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 3.124s
Ran all test suites.

Most helpful comment

--no-cache does create cache files, yes, but it doesn't use existing cache files. This means that subsequent runs will be fast (after dropping --no-cache). Is this a problem for you?

I'm closing this because it is unlikely we'll change this unless it turns out to be a serious issue.

All 4 comments

--no-cache does create cache files, yes, but it doesn't use existing cache files. This means that subsequent runs will be fast (after dropping --no-cache). Is this a problem for you?

I'm closing this because it is unlikely we'll change this unless it turns out to be a serious issue.

We need to run our test suite in our CI environment. We previously had problems with concurrent builds using the shared cache folder, so decided to set the cache folder to be a subfolder of the project itself, which resolved that issue. However, now we're running into a problem because when the build is complete the build script attempts to delete the project folder, but there seem to be Windows locks on files in the jest cache folder, so it can't delete it. We don't wish to use caching at all in our CI environment, and it would seem reasonable to expect a config option like cache:false to respect this.

Why not set the cacheDirectory to somewhere else? We can probably make this work by simply guarding all the cache writes. If you'd like to do that, feel free to send a PR with a few tests to make sure it works well. Here are some of the caches we use:

  • jest-haste-map creates one cache file
  • jest-runtime's transform.js file creates one cache file per transformed JS file
  • jest-cli's TestRunner.js has a "test performance" cache file

Thanks for the information. I'll take a look into whether it's possible for us to specify a cache folder outside the workspace per build project, if not I'll have a go at the PR.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nsand picture nsand  路  3Comments

mmcgahan picture mmcgahan  路  3Comments

paularmstrong picture paularmstrong  路  3Comments

stephenlautier picture stephenlautier  路  3Comments

jardakotesovec picture jardakotesovec  路  3Comments