-
Notifications
You must be signed in to change notification settings - Fork 4
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
Support MSW 2 #12
Support MSW 2 #12
Conversation
41b47e2
to
8c2ab14
Compare
Nevermind, figured it out. Opened evanw/esbuild#3377 as a suggestion for improvement. |
One of the reasons I explored this in the first place is that I'm not able to use the current build output in my app, as I get an error:
This seems to be because msw is not currently ESM-compatible. It relies on an older version of The alternative, if we want to keep using msw 1, is to try to resolve by polyfilling |
I think I've solved the "dynamic require" issue in #13, but it might still be worth considering supporting msw2. |
We'd also get support for |
@mrloop are you using mirage-msw currently? It sounds like you're in favor of moving to msw2. I think we might also need to make Mirage's |
I tried out the branch, thanks! There's an issue around FormData. Pretender, MSWv1 and MSWv2 handle form data differently. Using mirage/pretender I can access a FormData instance on the request.requestBody There's a bit of discussion about form data handling here mswjs/msw#1327. Notably request.body is deprecated and no longer in MSWv2, and there is a new request.formData() method. How should a mirage/MSWv2 user handle form data?
|
Any thoughts on this @IanVS. I can probably add option 2) next week |
Sorry @mrloop I'm not currently in this headspace, but I'm happy to let you experiment and come up with a solution that meets your needs. Feel free to open a PR into this PR, if you'd like. I'll try to return to this some time in the next few weeks. |
This prevents multiple duplicate handlers from being added
I've been using this in my own app, and with the fixes I've made here, it's working well. I'm going to merge this, and can continue to iterate on it in subsequent PRs. |
Thanks for keeping this up. Way back when I had two tests that failed when I used MSW, will have to try again maybe they work now with all your changes. Would definitely like to experiment with it again. |
@cah-brian-gantzler thanks. I've merged a PR that uses this in my app at work, so I'm hopeful that it's in a pretty good spot. I did have some issues with the latest versions of msw, and had to pin to Right now I'm running a patched version of miragejs that adds some async startup, but that will also require a breaking change at some point, I'd suggest doing it when we're confident that this msw support is in good shape. |
This updates the plugin to use MSW version 2, which relies more directly on standard
fetch
apis. The migration doc is here: https://github.com/mswjs/msw/blob/feat/standard-api/MIGRATING.md.I think at this point, it's best to support only MSW 2+, to keep our maintenance burden lower, but I'd be happy to hear other opinions on it.