From 1e47f1375ec69cc5a4956224a276410bc6bbd7d9 Mon Sep 17 00:00:00 2001 From: Rob Hogan <2590098+robhogan@users.noreply.github.com> Date: Thu, 20 Feb 2025 15:55:39 +0000 Subject: [PATCH 1/2] jest-haste-map: Fix clobbering/errors when multiple configs use different haste impls --- packages/jest-haste-map/src/worker.ts | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/packages/jest-haste-map/src/worker.ts b/packages/jest-haste-map/src/worker.ts index 699480a05929..4eec06ad8dd0 100644 --- a/packages/jest-haste-map/src/worker.ts +++ b/packages/jest-haste-map/src/worker.ts @@ -21,24 +21,14 @@ import type { const PACKAGE_JSON = `${path.sep}package.json`; -let hasteImpl: HasteImpl | null = null; -let hasteImplModulePath: string | null = null; - function sha1hex(content: string | Buffer): string { return createHash('sha1').update(content).digest('hex'); } export async function worker(data: WorkerMessage): Promise { - if ( - data.hasteImplModulePath && - data.hasteImplModulePath !== hasteImplModulePath - ) { - if (hasteImpl) { - throw new Error('jest-haste-map: hasteImplModulePath changed'); - } - hasteImplModulePath = data.hasteImplModulePath; - hasteImpl = require(hasteImplModulePath); - } + const hasteImpl: HasteImpl | null = data.hasteImplModulePath + ? require(data.hasteImplModulePath) + : null; let content: string | undefined; let dependencies: WorkerMetadata['dependencies']; From 96453dddad6e9f5ccf25887407bbc5bd902b0297 Mon Sep 17 00:00:00 2001 From: Rob Hogan Date: Sat, 22 Feb 2025 16:34:13 +0000 Subject: [PATCH 2/2] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 80c462425b36..e22bb5132407 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -81,6 +81,7 @@ - `[@jest/expect-utils]` Check `Symbol` properties in equality ([#14688](https://github.com/jestjs/jest/pull/14688)) - `[@jest/expect-utils]` Catch circular references within arrays when matching objects ([#14894](https://github.com/jestjs/jest/pull/14894)) - `[@jest/expect-utils]` Fix not addressing to Sets and Maps as objects without keys ([#14873](https://github.com/jestjs/jest/pull/14873)) +- `[jest-haste-map]` Fix errors or clobbering with multiple `hasteImplModulePath`s ([#15522](https://github.com/jestjs/jest/pull/15522)) - `[jest-leak-detector]` Make leak-detector more aggressive when running GC ([#14526](https://github.com/jestjs/jest/pull/14526)) - `[jest-runtime]` Properly handle re-exported native modules in ESM via CJS ([#14589](https://github.com/jestjs/jest/pull/14589)) - `[jest-schemas, jest-types]` [**BREAKING**] Fix type of `testFailureExitCode` config option([#15232](https://github.com/jestjs/jest/pull/15232))