First of all, thanks for the work on cy.route2
, it looks like it's going to make a lot of things much easier to do! I've jumped in to try it out and am having some trouble with URLs that are outside of my application (ie, API requests and such).
If the application sends a request to an external URL:
fetch('https://example.cypress.io/example-path')
In the tests, when cy.route2
is used, it does not appear to be possible to match the request.
Specifying path
:
cy.route2({ path: '/example-path', method: 'GET' }, { fixture: 'example.json' }).as('example');
Specifying url
:
cy.route2({ url: 'https://example.cypress.io/example-path', method: 'GET' }, { fixture: 'example.json' }).as('example');
Specifying hostname
:
cy.route2({ hostname: 'example.cypress.io', method: 'GET' }, { fixture: 'example.json' }).as('example');
Specifying hostname
and path
:
cy.route2({ hostname: 'example.cypress.io', path: '/example-path', method: 'GET' }, { fixture: 'example.json' }).as('example');
The request should be matched by the routes, and stubbed accordingly.
https://github.com/blakemann/cypress-test-tiny
Cypress: 5.1.0
Operating System: MacOS Catalina (10.15.6)
Browser: Chrome 85
One thing we tried (with no luck) in addition to what is mentioned above is adding
cy.server({
urlMatchingOptions: { matchBase: false }
});
before the cy.route2()
calls. This matchBase config is what seemed to get this external host functionality working with cy.route()
. I know that route2
does something to the effect of calling cy.server()
for us, but I wonder is there a way to override whatever server defaults are initiated by route2
?
This is probably a bug where we aren't intercepting all HTTP traffic, only HTTP traffic that seems pertinent to the current test. With cy.route2
we need to start intercepting all traffic from all domains.
@benwells cy.server
is going to be removed once cy.route2
replaces cy.route
, it should not have any special interaction with cy.route2
's behavior. There's currently not a way to set defaults for cy.route2
outside of making a custom command.
+1 for this. We're noticing an intermittent issue in Cypress, where some calls are not being added to the window.performance registry. We were using this workaround to check if a non-xhr request was being made. So we thought we'd give route2 a go, but as this particular call isn't on the same domain as the app being tested, route2 doesn't pick it up.
What are the estimates of fixing it? We have this strange issue when using experimentalFetchPolyfill
with our React events (some actions are not fired correctly), but I see that cy,route2
would be a fix (as it does not require experimentalFetchPolyfill
) for us. Unfortunately it does not handle external domains yet.
I am also seeing this behavior in the new 5.2.0 version.
I've narrowed down the issue and it seems to only affect HTTPS traffic to a different origin, opened a PR to fix: https://github.com/cypress-io/cypress/pull/8662
The code for this is done in cypress-io/cypress#8662, but has yet to be released.
We'll update this issue and reference the changelog when it's released.
Released in 5.3.0
.
This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v5.3.0, please open a new issue.
Most helpful comment
I am also seeing this behavior in the new 5.2.0 version.