Skip to content

fix(runtime): user can use dynamic import in code when running tests#15842

Merged
cpojer merged 4 commits intojestjs:mainfrom
hainenber:fix/user-can-use-dynamic-import-in-code
Oct 1, 2025
Merged

fix(runtime): user can use dynamic import in code when running tests#15842
cpojer merged 4 commits intojestjs:mainfrom
hainenber:fix/user-can-use-dynamic-import-in-code

Conversation

@hainenber
Copy link
Copy Markdown
Contributor

Summary

Resolves #15823

When user specifies feature flag to enable ESM support from Node.js runtime, jest-runtime should tolerate dynamic imports. I've verified that tests added in #14110 are still holding so the extended condition should ideally fix referred issue within an acceptable impact radius.

Test plan

  • Green CI
  • Confirmation from affected user

Signed-off-by: hainenber <dotronghai96@gmail.com>
Signed-off-by: hainenber <dotronghai96@gmail.com>
@netlify
Copy link
Copy Markdown

netlify bot commented Sep 28, 2025

Deploy Preview for jestjs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 52c723e
🔍 Latest deploy log https://app.netlify.com/projects/jestjs/deploys/68da9aead299610008f6d2f5
😎 Deploy Preview https://deploy-preview-15842--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.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Sep 28, 2025

Open in StackBlitz

babel-jest

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

babel-plugin-jest-hoist

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

babel-preset-jest

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

create-jest

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

@jest/diff-sequences

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

expect

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

@jest/expect-utils

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

jest

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

jest-changed-files

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

jest-circus

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

jest-cli

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

jest-config

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

@jest/console

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

@jest/core

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

@jest/create-cache-key-function

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

jest-diff

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

jest-docblock

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

jest-each

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

@jest/environment

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

jest-environment-jsdom

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

@jest/environment-jsdom-abstract

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

jest-environment-node

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

@jest/expect

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

@jest/fake-timers

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

@jest/get-type

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

@jest/globals

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

jest-haste-map

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

jest-jasmine2

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

jest-leak-detector

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

jest-matcher-utils

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

jest-message-util

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

jest-mock

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

@jest/pattern

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

jest-phabricator

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

jest-regex-util

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

@jest/reporters

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

jest-resolve

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

jest-resolve-dependencies

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

jest-runner

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

jest-runtime

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

@jest/schemas

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

jest-snapshot

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

@jest/snapshot-utils

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

@jest/source-map

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

@jest/test-result

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

@jest/test-sequencer

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

@jest/transform

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

@jest/types

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

jest-util

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

jest-validate

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

jest-watcher

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

jest-worker

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

pretty-format

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

commit: 52c723e

Signed-off-by: hainenber <dotronghai96@gmail.com>

// Source: https://github.com/jestjs/jest/issues/15823
test('test double with dynamic import', () => {
expect(double(2)).toBe(4);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this test use the newly added function doubleWithDynamicImport? The test title indicates that dynamic import is used but the test body doesn't say that

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for catching this! I've fixed in latest commit. Too much autocompletion reliance, I suppose :D

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM 👍 I think you might need to fix unit tests to improve code coverage. I suspect that adding the condition && !supportsDynamicImport requires some adjustments for unit tests

Signed-off-by: hainenber <dotronghai96@gmail.com>
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.

👍

@cpojer cpojer merged commit f73c098 into jestjs:main Oct 1, 2025
72 of 74 checks passed
@github-actions
Copy link
Copy Markdown

github-actions bot commented Nov 1, 2025

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 Nov 1, 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]: You are trying to import a file outside of the scope of the test code. This issue still occurs at jest30.0.0 and node22

3 participants