-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Issue #15865 : Fixed the change to switch to the fallback #15867
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for jestjs ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
babel-jest
babel-plugin-jest-hoist
babel-preset-jest
create-jest
@jest/diff-sequences
expect
@jest/expect-utils
jest
jest-changed-files
jest-circus
jest-cli
jest-config
@jest/console
@jest/core
@jest/create-cache-key-function
jest-diff
jest-docblock
jest-each
@jest/environment
jest-environment-jsdom
@jest/environment-jsdom-abstract
jest-environment-node
@jest/expect
@jest/fake-timers
@jest/get-type
@jest/globals
jest-haste-map
jest-jasmine2
jest-leak-detector
jest-matcher-utils
jest-message-util
jest-mock
@jest/pattern
jest-phabricator
jest-regex-util
@jest/reporters
jest-resolve
jest-resolve-dependencies
jest-runner
jest-runtime
@jest/schemas
jest-snapshot
@jest/snapshot-utils
@jest/source-map
@jest/test-result
@jest/test-sequencer
@jest/transform
@jest/types
jest-util
jest-validate
jest-watcher
jest-worker
pretty-format
commit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it be better if we add support for require ESM for Jest instead of always disabling that feature? Given that Jest already partially supports ESM, we should not move away from that.
#15865
##Summary
Problem: In Jest’s VM, process.features.require_module can be true (inherited from Node), causing defensive code to attempt require('./some-esm.js') and throw “Must use import to load ES Module”.
Fix: In packages/jest-util/src/createProcessObject.ts, when creating Jest’s VM process, override process.features.require_module to always return false (if the flag exists). This aligns the flag with Jest’s capabilities so defensive code takes the fallback path.
Scope: Only the VM’s process.features.require_module getter is affected, guarded behind presence checks. No other global behaviors are changed.
Changed files:
packages/jest-util/src/createProcessObject.ts
packages/jest-util/src/tests/installCommonGlobals.test.ts (new assertion added)
##Test plan
Added a test verifying the override:
packages/jest-util/src/tests/installCommonGlobals.test.ts
it('overrides process.features.require_module to false when present', ...)
Commands run and output:
yarn install --immutable
yarn build:ts
yarn build:js
yarn jest packages/jest-util/src/tests/installCommonGlobals.test.ts --color
Output:
PASS packages/jest-util/src/tests/installCommonGlobals.test.ts
✓ returns the passed object (63 ms)
✓ turns a V8 global object into a Node global object (3 ms)
✓ overrides process.features.require_module to false when present (2 ms)
Test Suites: 1 passed, 1 total
Tests: 3 passed, 3 total
Snapshots: 0 total
Time: 0.422 s