Add ability to define export conditions per modules #15340
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 removebrowser
condition fromcustomExportConditions
only when resolvingmsw
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:
Tests should pass while respecting exports of
different-exports
sub-package andmsw
-related packages.