diff --git a/compiler/forget/packages/snap/src/compiler-worker.ts b/compiler/forget/packages/snap/src/compiler-worker.ts index ce65610b35..cedd9c226f 100644 --- a/compiler/forget/packages/snap/src/compiler-worker.ts +++ b/compiler/forget/packages/snap/src/compiler-worker.ts @@ -11,24 +11,14 @@ import { exists } from "./utils"; const originalConsoleError = console.error; -// Subpaths to ignore when clearing the require cache -const ignoredRequireSubpaths: Array = [ - // compiler worker runner files - "node_modules/jest-worker", - // snap source files - "packages/snap", -]; -const ignoredRequirePaths: Set = new Set( - Object.keys(require.cache).filter( - (path) => - !ignoredRequireSubpaths.every((ignored) => !path.includes(ignored)) - ) -); - +// Try to avoid clearing the entire require cache, which (as of this PR) +// contains ~1250 files. This assumes that no dependencies have global caches +// that may need to be invalidated across Forget reloads. +const invalidationSubpath = "react-forget/forget/dist"; let version: number | null = null; export function clearRequireCache() { Object.keys(require.cache).forEach(function (path) { - if (!ignoredRequirePaths.has(path)) { + if (path.includes(invalidationSubpath)) { delete require.cache[path]; } }); diff --git a/compiler/forget/packages/snap/src/runner.ts b/compiler/forget/packages/snap/src/runner.ts index 89665c8cb9..97063189c9 100644 --- a/compiler/forget/packages/snap/src/runner.ts +++ b/compiler/forget/packages/snap/src/runner.ts @@ -441,13 +441,14 @@ export async function main(opts: RunnerOptions): Promise { const start = performance.now(); clearConsole(); console.log("Running tests..."); + // we don't clear console after this point, since + // it may contain debug console logging const results = await run( worker, opts, filterMode ? testFilter : null, compilerVersion ); - clearConsole(); if (mode === Mode.Update) { update(results); } else {