Skip to content

Commit 3a1f400

Browse files
committed
Per-file @jest/globals
This fixes #15772 by giving each import of @jest/globals its own synthetic module. My assumption is that making extra @jest/globals objects won't be a problem because @jest/globals will not have many imports from a single test suite and that Jest objects are relatively cheap to construct. If either of these assumptions is wrong, let me know. If this approach seems reasonable, I can see about adding test coverage. Fixes #15772
1 parent fe7f28c commit 3a1f400

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

packages/jest-runtime/src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,13 +588,14 @@ export default class Runtime {
588588
const registry = this._isolatedModuleRegistry ?? this._esmoduleRegistry;
589589

590590
if (specifier === '@jest/globals') {
591-
const fromCache = registry.get('@jest/globals');
591+
const globalsIdentifier = `@jest/globals/${referencingIdentifier}`;
592+
const fromCache = registry.get(globalsIdentifier);
592593

593594
if (fromCache) {
594595
return fromCache;
595596
}
596597
const globals = this.getGlobalsForEsm(referencingIdentifier, context);
597-
registry.set('@jest/globals', globals);
598+
registry.set(globalsIdentifier, globals);
598599

599600
return globals;
600601
}

0 commit comments

Comments
 (0)