Giter Club home page Giter Club logo

cypress-msw-interceptor's People

Contributors

deshiknaves avatar mwarger avatar raphaeleidus avatar ryanfiller avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cypress-msw-interceptor's Issues

webpack dev server hangs on sequential tests

Hey,

First of all, thanks for this awesome project ;). Saves some time.

I'm having two issues:

  1. I'm running my tests on local webpack dev server in a loop for each resolution provided in a test. First two are passing without issues with test code below, however third one timesout on cy.visit(). Like it makes webpack dev server to hang(?). I have no issues while running my tests without this plugin.
  2. The request that I'm waiting for is 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.
  3. After looking at browser console in cypress, I'm able to see this error (maybe related?):

Screenshot 2020-09-25 at 14 22 00

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]}`);
			});
		});
	});
});

Service Worker script does not exist at the given path

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.

Possibility to make it work with .HAR files

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

RegExp-typed 'route' parameter are over-escaped and fail compiling

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.

error "TypeError : cannot read 'type'

This error occurs when cypress starts new test case and the last test case hasn't fully executed then async function composeeRequest yet.

I added

" if (type == undefined) return "

in line:87 to solve the problem.

Capture d’écran de 2021-11-29 19-14-10

I think it's because cypress release immediately resources between each test.

Adding typings?

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>;
    }
  }
}

Doesn't work with Next & TS

"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

Any idea why interceptRequest not working?

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.

MSW Failed to Init

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

Feature request for using existing msw handlers outside of cypress

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.