Skip to content

Conversation

@jonathan-conder
Copy link
Contributor

Summary

I think this fixes #15690. I added a test which resembles the example there. It fails on the main branch but passes once the other changes are made.

When mocking an ESM module, jest stores the mock under a certain module ID. A different ID is used when the module is later imported asynchronously. This is related to #14297, which changed _getAbsolutePath and resolveStubModuleNameAsync without making the corresponding changes to _getAbsolutePathAsync and resolveStubModuleName.

Test plan

See the test I added (can mock transitive builtin module).

Since I modified resolveStubModuleName, I also broke a different test (resolveModule › custom resolver can resolve node modules). But I think that test would be broken on main if it called resolveModuleAsync instead of resolveModule, and I don't understand #14297 well enough to fix it.

@netlify
Copy link

netlify bot commented Aug 5, 2025

Deploy Preview for jestjs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 0793beb
🔍 Latest deploy log https://app.netlify.com/projects/jestjs/deploys/68ae813086f8520008bdaadc
😎 Deploy Preview https://deploy-preview-15774--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.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Aug 5, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: jonathan-conder / name: Jonathan Conder (bd4f22d)
  • ✅ login: cpojer / name: Christoph Nakazawa (0793beb)

@pkg-pr-new
Copy link

pkg-pr-new bot commented Aug 5, 2025

Open in StackBlitz

babel-jest

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

babel-plugin-jest-hoist

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

babel-preset-jest

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

create-jest

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

@jest/diff-sequences

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

expect

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

@jest/expect-utils

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

jest

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

jest-changed-files

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

jest-circus

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

jest-cli

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

jest-config

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

@jest/console

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

@jest/core

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

@jest/create-cache-key-function

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

jest-diff

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

jest-docblock

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

jest-each

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

@jest/environment

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

jest-environment-jsdom

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

@jest/environment-jsdom-abstract

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

jest-environment-node

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

@jest/expect

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

@jest/fake-timers

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

@jest/get-type

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

@jest/globals

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

jest-haste-map

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

jest-jasmine2

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

jest-leak-detector

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

jest-matcher-utils

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

jest-message-util

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

jest-mock

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

@jest/pattern

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

jest-phabricator

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

jest-regex-util

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

@jest/reporters

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

jest-resolve

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

jest-resolve-dependencies

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

jest-runner

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

jest-runtime

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

@jest/schemas

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

jest-snapshot

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

@jest/snapshot-utils

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

@jest/source-map

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

@jest/test-result

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

@jest/test-sequencer

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

@jest/transform

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

@jest/types

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

jest-util

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

jest-validate

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

jest-watcher

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

jest-worker

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

pretty-format

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

commit: 0793beb

@cpojer cpojer merged commit 664e71f into jestjs:main Aug 27, 2025
8 of 9 checks passed
cpojer added a commit to cpojer/jest that referenced this pull request Aug 27, 2025
@cpojer
Copy link
Member

cpojer commented Aug 27, 2025

Unfortunately I had to revert this since it broke one of the core resolver tests. Would you mind looking into it and sending a new PR?

@jonathan-conder
Copy link
Contributor Author

I don't have enough context to know what to do about it, see the PR description for details

@cpojer
Copy link
Member

cpojer commented Aug 27, 2025

Hah, yeah, I should have maybe read the PR description. I just read the title and the code 🫠 I'll take a look!

@Luligu
Copy link

Luligu commented Aug 27, 2025

#15690 has been closed but the issue is still present!

@jonathan-conder
Copy link
Contributor Author

Hah, yeah, I should have maybe read the PR description. I just read the title and the code 🫠 I'll take a look!

Thanks!

cpojer added a commit that referenced this pull request Sep 2, 2025
@cpojer
Copy link
Member

cpojer commented Sep 2, 2025

Brought it back here: 0bb3101

@github-actions
Copy link

github-actions bot commented Oct 3, 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 Oct 3, 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]: unstable_mockModule doesn't mock anymore

3 participants