deshiknaves / cypress-msw-interceptor Goto Github PK
View Code? Open in Web Editor NEWA networking layer for Cypress using MSW
License: MIT License
A networking layer for Cypress using MSW
License: MIT License
Hey,
First of all, thanks for this awesome project ;). Saves some time.
I'm having two issues:
cy.visit()
. Like it makes webpack dev server to hang(?). I have no issues while running my tests without this plugin.POST
to graphql API. But I'm not trying to mock anything just want to track it and wait for it and it seems to work properly for first two runs.Related test code:
describe('Test different resolutions', () => {
context('desktop, mobile and tablet resolutions', () => {
const allSizes = [...];
allSizes.forEach((resolution) => {
it(`Should display exchange properly on ${resolution} screen`, () => {
cy.viewport(resolution[0], resolution[1]);
cy.interceptRequest(
'POST',
'https://somexternalurl.com/api'
).as('api');
cy.visit('http://localhost:3000');
cy.waitForRequest('@api');
cy.screenshot(`${resolution[0]}-${resolution[1]}`);
});
});
});
});
error on import 'cypress-msw-interceptor'
says
Failed to register a Service Worker for scope ('http://localhost:51138/') with script ('http://localhost:51138/mockServiceWorker.js'): Service Worker script does not exist at the given path.
I haven't gotten to actually writing any special test scenario. Just a simple test to cy.visit page.
Hi,
Thanks for this project. I am exploring and trying to make Cypress work together with this plugin for MSW: https://github.com/Tapico/tapico-msw-webarchive It works when MSW starts when the app is starting but doesn't work when I try to start MSW inside my Cypress tests, it registers all routes from .HAR file but does not actually return mocked responses. I was wondering if you are aware of that plugin and what's your opinion on that? Is it something we could try to make it work as well ?
Thanks
For the cy.interceptRequest
command, the cypress-msw-interceptor
passes the provided route
parameter as MSW's rest[lower case http method](route)
(see reference)... But in my case, when that route
parameter is a RegExp
, MSW responds with status 500 complaining that the provided expression cannot compile with a very escaped string.
Hi,
Could you adding typings to this library?
I've setup the following myself
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Cypress {
interface Chainable {
waitForRequest(alias: string): Chainable<{ id: string, request: MockedRequest, complete: boolean }>;
waitForQuery(alias: string): Chainable<{ id: string, request: MockedRequest, complete: boolean }>;
waitForMutation(alias: string): Chainable<{ id: string, request: MockedRequest, complete: boolean }>;
getRequestCalls(alias: string): Chainable<void>;
getQueryCalls(alias: string): Chainable<void>;
getMutationCalls(alias: string): Chainable<void>;
interceptRequest(type, route, ...args): Chainable<string>;
interceptQuery(name, ...args): Chainable<string>;
interceptMutation(name, ...args): Chainable<string>;
}
}
}
"cypress": "8.6.0",
"cypress-msw-interceptor": "^2.0.0",
"msw": "^0.35.0",
Hey there, I'm trying to make this work with a project that has NextJS and TS support.
I already had msw set up, and I followed the docs for this package, but when I open cypress I get this:
Error: Webpack Compilation Error
./node_modules/cypress-msw-interceptor/src/support.js 41:14
Module parse failed: Unexpected token (41:14)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|
| function registerRequest(request) {
if (request?.body?.operationName) {
| registerGraphQL(request)
| }
@ ./node_modules/cypress-msw-interceptor/index.js 4:0-27
Would like to override some of the normal mocks during cypress testing, so installed your plugin. But the interceptRequest doesn't seem to take place and instead I get the default MSW mock that has been setup. Any ideas? I've double/triple checked that I didn't miss any steps. I've double checked that I'm using the right GET/POST and the exact endpoint.
Hello, Ive migrated from cypress 9.7.0 to 10.8.0 and MSW no longer seems to work. I am seeing the following error.
[MSW] Failed to register a Service Worker for scope ('http://localhost:35607/') with script ('http://localhost:35607/mockServiceWorker.js'): Service Worker script does not exist at the given path.
Did you forget to run "npx msw init <PUBLIC_DIR>"?
Learn more about creating the Service Worker script: https://mswjs.io/docs/cli/init
Because this error occurred during a before all hook we are skipping all of the remaining tests.
Although you have test retries enabled, we do not retry tests when before all or after all hooks fail
Just FYI I needed to do the following instead of what the documentation says
import { setMswWorkerOptions} from 'cypress-msw-interceptor/src/support';
vs
import { setMswWorkerOptions}, 'cypress-msw-interceptor;
Hi,
Would you be open to adding the capability of setting up existing msw handlers that have been setup outside of cypress?
I've patch packaged in internally to do what i needed it to do for my own custom setup
Just involved adding a new workerHandlers variable and if that is defined then use it during msw setup and also ignore any msw use during the intercept cypress commands
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.