jest
jest copied to clipboard
Add ability to define export conditions per modules
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.
The committers listed above are authorized under a signed CLA.
- :white_check_mark: login: jiri-prokop-pb / name: Jiří Prokop (f286c2e0c2380e7ac0e4f3de51dc993b76528637, e86d840db36d2c63a305dc9beead86bca994072c, df2054bfe2841136a85abe6759e7417a131fbb83)
Deploy Preview for jestjs ready!
Built without sensitive environment variables
| Name | Link |
|---|---|
| Latest commit | df2054bfe2841136a85abe6759e7417a131fbb83 |
| 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...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
This PR is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 30 days.
Hey! 👋
Thanks for the PR and sorry for the radio silence.
What do you think about just passing a resolver instead? https://jestjs.io/docs/configuration#resolver-string
You can then, based on the module being loaded, pass different conditions than the default ones provided by Jest
Thanks for the response and suggestion.
What do you think about just passing a resolver instead? https://jestjs.io/docs/configuration#resolver-string
You can then, based on the module being loaded, pass different conditions than the default ones provided by Jest
I wasn't aware of this option and I guess it could work.
Unfortunately at this point we migrated majority of our project to Vitest so we won't need this logic anymore.
If there is a better solution to this https://mswjs.io/docs/migrations/1.x-to-2.x/#cannot-find-module-mswnode-jsdom then authors of MSW could provide it in their docs instead.
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.