Skip to content

Commit 59d33ec

Browse files
joshkelcpojer
andauthored
Per-file @jest/globals (#15773)
Co-authored-by: Christoph Nakazawa <[email protected]>
1 parent 7745acd commit 59d33ec

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## main
22

3+
### Fixes
4+
5+
- `[jest-runtime]` Importing from `@jest/globals` in more than one file no longer breaks relative paths ([#15772](https://github.com/jestjs/jest/issues/15772))
6+
37
# Chore
48

59
- `[expect]` Update docblock for `toContain()` to display info on substring check ([#15789](https://github.com/jestjs/jest/pull/15789))

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)