[snap] patch bug in clearing require cache
Snap currently has a bug in which the require cache is not correctly cleared when running in filter mode (#tests < 2 * #workers). - We're currently clearing all entries in the require cache of worker threads, including `jest-worker` and `snap/dist/...` files - jest-worker seems to `require` these files on every dispatch (i.e. `worker.compile` seems to call `require(`compiler-worker`).compile`)
mofeiZ committed
May 11, 2023 at 13:53 UTC
04cee98166d4b495b29454f4e2a774788442ecd0
1 file changed
+18
-2
compiler/forget/packages/snap/src/compiler-worker.ts
+18
-2
@@ -11,10 +11,26 @@ import { exists } from "./utils";
11
12
const originalConsoleError = console.error;
13
14
+// Subpaths to ignore when clearing the require cache
15
+const ignoredRequireSubpaths: Array<string> = [
16
+ // compiler worker runner files
17
+ "node_modules/jest-worker",
18
+ // snap source files
19
+ "packages/snap",
20
+];
21
+const ignoredRequirePaths: Set<string> = new Set(
22
+ Object.keys(require.cache).filter(
23
+ (path) =>
24
+ !ignoredRequireSubpaths.every((ignored) => !path.includes(ignored))
25
+ )
26
+);
27
+
28
let version: number | null = null;
29
export function clearRequireCache() {
16
- Object.keys(require.cache).forEach(function (key) {
17
- delete require.cache[key];
30
+ Object.keys(require.cache).forEach(function (path) {
31
+ if (!ignoredRequirePaths.has(path)) {
32
+ delete require.cache[path];
33
+ }
34
});
35
}
36