Skip to content
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

fix(@jest/resolve): Include stringifiedOptions in getModuleIDAsync #12766

Merged
merged 3 commits into from Apr 28, 2022

Conversation

maxdavidson
Copy link
Contributor

Summary

I use native ESM with the --experimental-vm-modules flag. When upgrading to Jest 28, jest.unstable_mockModule stopped working:

  jest.unstable_mockModule("../src/config/oidc.js", () => ({
    OIDC_CLIENT_ID: clientId,
    OIDC_CLIENT_SECRET: clientSecret,
    OIDC_ISSUER_URL: issuerUrl,
  }));

  // Not resolving the transitive mocked module in Jest 28!
  const authHandlers = await import("../src/handlers/oidc.js");

I tracked this down to the mock detection failing due to getModuleID and getModuleIDAsync not generating identical IDs. In this case getModuleIDAsync did not append the stringified options, so the lookup using the ID as a key failed.

There are other slight differences between getModuleID and getModuleIDAsync that might lead to similar issues.

Test plan

  • jest.unstable_mockModule followed by a dynamic import should resolve the mocked module

Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

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

oh, good catch! would you be able to add a test as well?

(and a changelog entry)

There are other slight differences between getModuleID and getModuleIDAsync that might lead to similar issues.

We should fix those. Is it possible to extract some utils to keep it DRY?

@maxdavidson
Copy link
Contributor Author

oh, good catch! would you be able to add a test as well?
(and a changelog entry)

Sure, I'll make an attempt 👍

There are other slight differences between getModuleID and getModuleIDAsync that might lead to similar issues.

We should fix those. Is it possible to extract some utils to keep it DRY?

I can look into it 👍

Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

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

Fantastic, thanks!

@SimenB SimenB merged commit bf88f76 into jestjs:main Apr 28, 2022
@SimenB
Copy link
Member

SimenB commented Apr 29, 2022

@github-actions
Copy link

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 May 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants