-
-
Notifications
You must be signed in to change notification settings - Fork 528
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
MSW in fallback mode not intercepting and mocking image binary request #2225
Comments
Hi, did you already check if Cypress is browsing storybook with HTTPS enabled? Or in the Chrome Devtools of Cypress could you check if service worker are possible? msw/src/browser/setupWorker/setupWorker.ts Line 151 in 52d0a13
|
Looks like it's using Would you know off-hand is there's something specific I can do to enable that in the Cypress docker image? (I can go a-googlin' too!) Is it expected that fallback mode can't intercept image requests? |
Unfortunately I don't know if you can enable HTTPS in Cypress, but maybe it is not needed because if I just google for MSW and Cypress the setup is quite simple and nobody mentions problems with the fallback mode or anything related to HTTPS... So maybe if you started the Docker Container, you could check the Devtools in the Cypress browser. Paste this code in the console.log(!('serviceWorker' in navigator) ? 'NO service worker is possible' : 'service worker possible');
console.log(location.protocol === 'file:' ? 'running as local file, so no MSW mocking possible' : 'protocol is fine'); |
Just ran into this same issue trying to mock the response of a javascript file loaded via script tag with MSW, which also does not seem to work when MSW is running in fallback mode. I saw The root cause of this, was Cypress
I was able to get the proper serviceWorker version of MSW loaded by changing the services:
storybook:
container_name: test_storybook
ports:
- "6060:6060"
entrypoint: npx http-server storybook-static -p 6060 -s
# ...
cypress:
container_name: test_cypress
network_mode: service:storybook # <-- allow cypress container to access localhost of storybook container
environment:
- CYPRESS_baseUrl=http://localhost:6060 # <-- allows browser to run in secure context
depends_on:
- storybook
command: npx cypress run --browser chrome Before changes ( After changes ( |
Prerequisites
Environment check
msw
versionBrowsers
Chromium (Chrome, Brave, etc.)
Reproduction repository
https://github.com/ahayes91/msw-cypress-docker-storybook
Reproduction steps
yarn storybook
from the root of the repo to view a locally running instance of Storybook and confirm the image is being mocked correctly.yarn test:visual
to confirm that the snapshot generated by Cypress against Storybook isn't mocking the image correctly.To view how the story is being rendered in the Docker container (and see MSW in fallback mode), you need to do some setup steps:
open -a XQuartz
from your terminalIP=$(ipconfig getifaddr en0)
and/usr/X11/bin/xhost + $IP
IP=$IP yarn test:visual
to see the test runner open up, and run debugStorybook test file to inspect the Storybook entry in the test runner browser.Current behavior
MSW enters fallback mode when running Cypress in a Docker container.
Image request is not being mocked and instead the browser is attempting to fetch the image from the file system.
Expected behavior
The image request should be intercepted and handled by the mock.
The text was updated successfully, but these errors were encountered: