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

Add ability to define export conditions per modules #15340

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jiri-prokop-pb
Copy link

Summary

When migrating to MSW v2, we bumped into the problem described here: https://mswjs.io/docs/migrations/1.x-to-2.x/#cannot-find-module-mswnode-jsdom

Unfortunately the solution didn't work for us fully because we also have some other dependencies and the suggested solution was breaking another things.

For now we patched jest-runtime locally in our project to remove browser condition from customExportConditions only when resolving msw and @mswjs/interceptors modules and it works.

This PR is an attempt to make the logic configurable and more general.

It's my first contribution to Jest but I tried to update all relevant parts. The only thing I struggled with was testing. As far as I can see, customExportConditions are not tested right now and I wasn't sure how to prepare test env for it. If you want, I can look into it too but I'd welcome some guidance.

I hope this change make sense and could be accepted. I'm open to any feedback and adjustments.

Once it's in place, MSW could update their docs and hopefully it could help the community with adopting their new version in Jest.

Test plan

I created small demo repo: https://github.com/jiri-prokop-pb/jest-custom-export-conditions-demo-repo

You can test the logic by cloning it and running:

pnpm install
pnpm --filter main test

Tests should pass while respecting exports of different-exports sub-package and msw-related packages.

Copy link

linux-foundation-easycla bot commented Oct 9, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

Copy link

netlify bot commented Oct 9, 2024

Deploy Preview for jestjs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit df2054b
🔍 Latest deploy log https://app.netlify.com/sites/jestjs/deploys/67077ce03b35350008000604
😎 Deploy Preview https://deploy-preview-15340--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 site configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant