diff --git a/packages/jest-config/package.json b/packages/jest-config/package.json index d0677510d6f8..acb0fe2c87ae 100644 --- a/packages/jest-config/package.json +++ b/packages/jest-config/package.json @@ -9,6 +9,7 @@ "main": "build/index.js", "dependencies": { "chalk": "^1.1.1", + "find-cache-dir": "^0.1.1", "jest-environment-jsdom": "^17.0.2", "jest-environment-node": "^17.0.2", "jest-jasmine2": "^17.0.3", diff --git a/packages/jest-config/src/defaults.js b/packages/jest-config/src/defaults.js index cadcda57dfd6..0f0bdf9d58ea 100644 --- a/packages/jest-config/src/defaults.js +++ b/packages/jest-config/src/defaults.js @@ -16,14 +16,17 @@ const constants = require('./constants'); const os = require('os'); const path = require('path'); const {replacePathSepForRegex} = require('jest-util'); +const findCacheDir = require('find-cache-dir'); +const cacheDir = findCacheDir({name: 'jest'}); +const fallbackCacheDir = path.join(os.tmpdir(), 'jest'); const NODE_MODULES_REGEXP = replacePathSepForRegex(constants.NODE_MODULES); module.exports = ({ automock: false, bail: false, browser: false, - cacheDirectory: path.join(os.tmpdir(), 'jest'), + cacheDirectory: cacheDir || fallbackCacheDir, coveragePathIgnorePatterns: [NODE_MODULES_REGEXP], coverageReporters: ['json', 'text', 'lcov', 'clover'], expand: false, diff --git a/packages/jest-runtime/src/index.js b/packages/jest-runtime/src/index.js index 68b07ec81286..7c7456dd8a59 100644 --- a/packages/jest-runtime/src/index.js +++ b/packages/jest-runtime/src/index.js @@ -27,6 +27,7 @@ const transform = require('./transform'); const { createDirectory, replacePathSepForRegex, + escapeStrForRegex, } = require('jest-util'); type Module = {| @@ -195,7 +196,9 @@ class Runtime { options?: HasteMapOptions, ): HasteMap { const ignorePattern = new RegExp( - [config.cacheDirectory].concat(config.modulePathIgnorePatterns).join('|'), + [escapeStrForRegex(config.cacheDirectory)] + .concat(config.modulePathIgnorePatterns) + .join('|'), ); return new HasteMap({