cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
46.72k stars 3.16k forks source link

Full Network Layer Stubbing / fetch support #687

Closed brian-mann closed 4 years ago

brian-mann commented 6 years ago

Pull Request (in progress): https://github.com/cypress-io/cypress/pull/4176

What users want

What we do now

What we need to do

Things to consider

Bonus Points

brian-mann commented 6 years ago

Related to:

ericadamski commented 6 years ago

@brian-mann I would be very willing to help out with this issue. This is a big blocker for use when testing our app.

brian-mann commented 6 years ago

@ericadamski could you go into more detail about this? What exactly is a big blocker?

ericadamski commented 6 years ago

@brian-mann making network requests (using a fetch polyfill) and asserting on those requests is important to our integration testing. Currently we are just spying on the window.fetch and doing some simple assertions on the params request. It would be ideal to provide the same functionality as XHRs to completely omit the server and mock responses when needed, understanding that we could stub the fetch as well, but this means stubbing each individual request with a tailored response.

brian-mann commented 6 years ago

You can do this right now using stubs. Albeit it's certainly not as nice as what we did for XHR stubbing, but it is possible and we have several examples of making this work. This is even in a new getting started video we're releasing later this week.

https://github.com/cypress-io/cypress-example-recipes/blob/master/cypress/integration/spy_stub_clock_spec.js

ericadamski commented 6 years ago

Yes we realize it can be done, albeit we would rather wait (or work toward) a more XHR style stubbing, it is just super nice.

brian-mann commented 6 years ago

Yeah it is. Okay just making sure we're on the same page.

The proposal here does a decent job outlining what needs to be done but it will be a significant amount of work.

Likely the next steps just need to be formalizing a plan for the API's themselves. There have been many requests for additional features and we should start there.

ericadamski commented 6 years ago

That sounds good.

Is it worth creating separate issues for some of the requested features for I know almost nothing about graphQL queries 😜

brian-mann commented 6 years ago

They mostly already are other issues. We need to factor in all of them and come up with a set of API's that unifies those different use cases and desired experiences.

ericadamski commented 6 years ago

Right OK, I see what you are saying.

ericadamski commented 6 years ago

@brian-mann side note, has it been thought of moving away from coffeescript and into es6?

paulpruteanu commented 6 years ago

Do you consider this feature in the next release? I reckon it would be highly valuable, for instance when