-
Notifications
You must be signed in to change notification settings - Fork 284
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
Mock Service Worker not intercepting requests in loader #1604
Comments
Try running in the new worker environment: If I add the following to the top of the import {setupWorker} from 'msw/browser';
const worker = setupWorker();
worker.start();
worker.events.on('request:start', ({request}) => {
console.log('-----> MSW intercepted', request.method, request.url);
}); I get these logs:
Which means MSW is working, right? |
@frandiox thank you - this actually does work. Very strange, though. Didn't even occur to me to use the browser package since I'm trying to intercept on the server. But all's well that ends well I guess. I'll mark this as closed. |
What is the location of your example repository?
https://github.com/rmiller61/hydrogen-oxygen-msw
Which package or tool is having this issue?
Hydrogen
What version of that package or tool are you using?
@shopify/remix-oxygen 2.0.2, @shopify/hydrogen 2023.10.3
What version of Remix are you using?
2.1.0
Steps to Reproduce
npm run dev
Expected Behavior
MSW should intercept requests (that match the handlers specified in tests/mocks/handlers.ts) on the server so their responses can be mocked.
I have a GraphQL query named "Header" defined in my root.tsx that should be intercepted by MSW.
Actual Behavior
MSW doesn't pick up any requests in the loader functions. This is evident by the lack of lifecycle events logged to the console, as well as the responses themselves. It does, however, intercept requests outside the loader, such as the initial fetch request Hydrogen sends to pull my environment variables from Shopify. It's specifically the requests in the loader.
It's worth noting that MSW can't intercept 3rd party APIs, either. I initially thought this might be a problem with the Storefront client, but it appears to be any fetch request inside the loader.
The text was updated successfully, but these errors were encountered: