Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Per-file @jest/globals#15773

Merged
cpojer merged 2 commits into
jestjs:mainfrom
joshkel:jest-globals-per-file
Aug 27, 2025
Merged

Per-file @jest/globals#15773
cpojer merged 2 commits into
jestjs:mainfrom
joshkel:jest-globals-per-file

Conversation

@joshkel
Copy link
Copy Markdown
Contributor

@joshkel joshkel commented Aug 4, 2025

Summary

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.

Test plan

I tested against https://github.com/joshkel/jest-globals-bug and confirmed that the bug went away.

Fixes #15772

@netlify
Copy link
Copy Markdown

netlify Bot commented Aug 4, 2025

Deploy Preview for jestjs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 78a86c6
🔍 Latest deploy log https://app.netlify.com/projects/jestjs/deploys/68ae7f2c6a0a5c0008a505bf
😎 Deploy Preview https://deploy-preview-15773--jestjs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

This fixes jestjs#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 jestjs#15772
@joshkel joshkel force-pushed the jest-globals-per-file branch from 3a1f400 to a46b5c0 Compare August 4, 2025 21:22
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Aug 4, 2025

Open in StackBlitz

babel-jest

npm i https://pkg.pr.new/babel-jest@15773

babel-plugin-jest-hoist

npm i https://pkg.pr.new/babel-plugin-jest-hoist@15773

babel-preset-jest

npm i https://pkg.pr.new/babel-preset-jest@15773

create-jest

npm i https://pkg.pr.new/create-jest@15773

@jest/diff-sequences

npm i https://pkg.pr.new/@jest/diff-sequences@15773

expect

npm i https://pkg.pr.new/expect@15773

@jest/expect-utils

npm i https://pkg.pr.new/@jest/expect-utils@15773

jest

npm i https://pkg.pr.new/jest@15773

jest-changed-files

npm i https://pkg.pr.new/jest-changed-files@15773

jest-circus

npm i https://pkg.pr.new/jest-circus@15773

jest-cli

npm i https://pkg.pr.new/jest-cli@15773

jest-config

npm i https://pkg.pr.new/jest-config@15773

@jest/console

npm i https://pkg.pr.new/@jest/console@15773

@jest/core

npm i https://pkg.pr.new/@jest/core@15773

@jest/create-cache-key-function

npm i https://pkg.pr.new/@jest/create-cache-key-function@15773

jest-diff

npm i https://pkg.pr.new/jest-diff@15773

jest-docblock

npm i https://pkg.pr.new/jest-docblock@15773

jest-each

npm i https://pkg.pr.new/jest-each@15773

@jest/environment

npm i https://pkg.pr.new/@jest/environment@15773

jest-environment-jsdom

npm i https://pkg.pr.new/jest-environment-jsdom@15773

@jest/environment-jsdom-abstract

npm i https://pkg.pr.new/@jest/environment-jsdom-abstract@15773

jest-environment-node

npm i https://pkg.pr.new/jest-environment-node@15773

@jest/expect

npm i https://pkg.pr.new/@jest/expect@15773

@jest/fake-timers

npm i https://pkg.pr.new/@jest/fake-timers@15773

@jest/get-type

npm i https://pkg.pr.new/@jest/get-type@15773

@jest/globals

npm i https://pkg.pr.new/@jest/globals@15773

jest-haste-map

npm i https://pkg.pr.new/jest-haste-map@15773

jest-jasmine2

npm i https://pkg.pr.new/jest-jasmine2@15773

jest-leak-detector

npm i https://pkg.pr.new/jest-leak-detector@15773

jest-matcher-utils

npm i https://pkg.pr.new/jest-matcher-utils@15773

jest-message-util

npm i https://pkg.pr.new/jest-message-util@15773

jest-mock

npm i https://pkg.pr.new/jest-mock@15773

@jest/pattern

npm i https://pkg.pr.new/@jest/pattern@15773

jest-phabricator

npm i https://pkg.pr.new/jest-phabricator@15773

jest-regex-util

npm i https://pkg.pr.new/jest-regex-util@15773

@jest/reporters

npm i https://pkg.pr.new/@jest/reporters@15773

jest-resolve

npm i https://pkg.pr.new/jest-resolve@15773

jest-resolve-dependencies

npm i https://pkg.pr.new/jest-resolve-dependencies@15773

jest-runner

npm i https://pkg.pr.new/jest-runner@15773

jest-runtime

npm i https://pkg.pr.new/jest-runtime@15773

@jest/schemas

npm i https://pkg.pr.new/@jest/schemas@15773

jest-snapshot

npm i https://pkg.pr.new/jest-snapshot@15773

@jest/snapshot-utils

npm i https://pkg.pr.new/@jest/snapshot-utils@15773

@jest/source-map

npm i https://pkg.pr.new/@jest/source-map@15773

@jest/test-result

npm i https://pkg.pr.new/@jest/test-result@15773

@jest/test-sequencer

npm i https://pkg.pr.new/@jest/test-sequencer@15773

@jest/transform

npm i https://pkg.pr.new/@jest/transform@15773

@jest/types

npm i https://pkg.pr.new/@jest/types@15773

jest-util

npm i https://pkg.pr.new/jest-util@15773

jest-validate

npm i https://pkg.pr.new/jest-validate@15773

jest-watcher

npm i https://pkg.pr.new/jest-watcher@15773

jest-worker

npm i https://pkg.pr.new/jest-worker@15773

pretty-format

npm i https://pkg.pr.new/pretty-format@15773

commit: 78a86c6

Copy link
Copy Markdown
Member

@cpojer cpojer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, this makes sense.

Could you send a separate PR with a test?

@cpojer cpojer merged commit 59d33ec into jestjs:main Aug 27, 2025
8 of 9 checks passed
@joshkel joshkel deleted the jest-globals-per-file branch August 27, 2025 14:17
@github-actions
Copy link
Copy Markdown

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Sep 27, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Importing from @jest/globals elsewhere breaks unstable_mockModule

2 participants