-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
fix(jest-resolver): Allow core ESM modules to be mocked with prefix #15774
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
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: |
…prefix (jestjs#15774)" This reverts commit 664e71f.
|
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? |
|
I don't have enough context to know what to do about it, see the PR description for details |
|
Hah, yeah, I should have maybe read the PR description. I just read the title and the code 🫠 I'll take a look! |
|
#15690 has been closed but the issue is still present! |
Thanks! |
|
Brought it back here: 0bb3101 |
|
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. |
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
_getAbsolutePathandresolveStubModuleNameAsyncwithout making the corresponding changes to_getAbsolutePathAsyncandresolveStubModuleName.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 onmainif it calledresolveModuleAsyncinstead ofresolveModule, and I don't understand #14297 well enough to fix it.