Last active
July 18, 2021 04:48
-
-
Save walisc/9879b14fdbc41c40237cdadb33dad2e8 to your computer and use it in GitHub Desktop.
Jest File Caching Patches
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/node_modules/jest-config/build/Descriptions.js b/node_modules/jest-config/build/Descriptions.js | |
index bb1d541..0400d8d 100644 | |
--- a/node_modules/jest-config/build/Descriptions.js | |
+++ b/node_modules/jest-config/build/Descriptions.js | |
@@ -99,7 +99,8 @@ const descriptions = { | |
'Indicates whether each individual test should be reported during the run', | |
watchPathIgnorePatterns: | |
'An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode', | |
- watchman: 'Whether to use watchman for file crawling' | |
+ watchman: 'Whether to use watchman for file crawling', | |
+ skipFileCache: 'An array of regexp pattern strings used to determine which files not to cache. This is useful when tests generate source files dynamically.' | |
}; | |
var _default = descriptions; | |
exports.default = _default; | |
diff --git a/node_modules/jest-config/build/ValidConfig.js b/node_modules/jest-config/build/ValidConfig.js | |
index 167b8c0..cbdf214 100644 | |
--- a/node_modules/jest-config/build/ValidConfig.js | |
+++ b/node_modules/jest-config/build/ValidConfig.js | |
@@ -182,7 +182,8 @@ const initialOptions = { | |
} | |
] | |
], | |
- watchman: true | |
+ watchman: true, | |
+ skipFileCache: [] | |
}; | |
var _default = initialOptions; | |
exports.default = _default; | |
diff --git a/node_modules/jest-config/build/index.js b/node_modules/jest-config/build/index.js | |
index ce8c60c..b937c21 100644 | |
--- a/node_modules/jest-config/build/index.js | |
+++ b/node_modules/jest-config/build/index.js | |
@@ -354,7 +354,8 @@ const groupOptions = options => ({ | |
transform: options.transform, | |
transformIgnorePatterns: options.transformIgnorePatterns, | |
unmockedModulePathPatterns: options.unmockedModulePathPatterns, | |
- watchPathIgnorePatterns: options.watchPathIgnorePatterns | |
+ watchPathIgnorePatterns: options.watchPathIgnorePatterns, | |
+ skipFileCache: options.skipFileCache | |
}) | |
}); | |
diff --git a/node_modules/jest-config/build/normalize.js b/node_modules/jest-config/build/normalize.js | |
index 969092c..47d3efb 100644 | |
--- a/node_modules/jest-config/build/normalize.js | |
+++ b/node_modules/jest-config/build/normalize.js | |
@@ -937,6 +937,7 @@ async function normalize( | |
case 'transformIgnorePatterns': | |
case 'watchPathIgnorePatterns': | |
case 'unmockedModulePathPatterns': | |
+ case 'skipFileCache': | |
value = normalizeUnmockedModulePathPatterns(oldOptions, key); | |
break; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/node_modules/jest-runtime/build/index.js b/node_modules/jest-runtime/build/index.js | |
index 045907f..8df3933 100644 | |
--- a/node_modules/jest-runtime/build/index.js | |
+++ b/node_modules/jest-runtime/build/index.js | |
@@ -806,6 +806,7 @@ class Runtime { | |
moduleRegistry = this._moduleRegistry; | |
} | |
+ this.invalidateFileCacheIfApplicable(modulePath, moduleRegistry) | |
const module = moduleRegistry.get(modulePath); | |
if (module) { | |
@@ -1409,6 +1410,19 @@ class Runtime { | |
this._currentlyExecutingModulePath = lastExecutingModulePath; | |
} | |
+ invalidateFileCacheIfApplicable(moduleName, moduleRegistry) { | |
+ if (!this._config.skipFileCache || this._config.skipFileCache.length == 0){ return } | |
+ for (const cacheSkipPattern of this._config.skipFileCache){ | |
+ if (new RegExp(cacheSkipPattern).test(moduleName)){ | |
+ moduleRegistry.delete(moduleName) | |
+ this._cacheFS.delete(moduleName) | |
+ this._fileTransforms.delete(moduleName) | |
+ this._sourceMapRegistry.delete(moduleName) | |
+ return | |
+ } | |
+ } | |
+ } | |
+ | |
transformFile(filename, options) { | |
const source = this.readFile(filename); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment