Skip to content
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

cy.route2 routes not being matched with external URLs #8487

Closed
blakemann opened this issue Sep 3, 2020 · 8 comments · Fixed by #8662
Closed

cy.route2 routes not being matched with external URLs #8487

blakemann opened this issue Sep 3, 2020 · 8 comments · Fixed by #8662

Comments

@blakemann
Copy link

blakemann commented Sep 3, 2020

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).

Current behavior:

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');

image

Specifying url:

cy.route2({ url: 'https://example.cypress.io/example-path', method: 'GET' }, { fixture: 'example.json' }).as('example');

image

Specifying hostname:

cy.route2({ hostname: 'example.cypress.io', method: 'GET' }, { fixture: 'example.json' }).as('example');

image

Specifying hostname and path:

cy.route2({ hostname: 'example.cypress.io', path: '/example-path', method: 'GET' }, { fixture: 'example.json' }).as('example');

image

Desired behavior:

The request should be matched by the routes, and stubbed accordingly.

Test code to reproduce

https://github.com/blakemann/cypress-test-tiny

Versions

Cypress: 5.1.0
Operating System: MacOS Catalina (10.15.6)
Browser: Chrome 85

@benwells
Copy link

benwells commented Sep 3, 2020

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?

@flotwig
Copy link
Contributor

flotwig commented Sep 9, 2020

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.

@asos-stuartcrocker
Copy link

+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.

@coffee-mug-jk
Copy link

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.

@troythacker
Copy link

I am also seeing this behavior in the new 5.2.0 version.

@cypress-bot cypress-bot bot added stage: work in progress There is an open PR for this issue [WIP] stage: needs review The PR code is done & tested, needs review and removed stage: work in progress There is an open PR for this issue [WIP] labels Sep 24, 2020
@flotwig
Copy link
Contributor

flotwig commented Sep 24, 2020

I've narrowed down the issue and it seems to only affect HTTPS traffic to a different origin, opened a PR to fix: #8662

@cypress-bot cypress-bot bot added stage: pending release There is a closed PR for this issue and removed stage: needs review The PR code is done & tested, needs review labels Sep 25, 2020
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Sep 25, 2020

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.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Sep 29, 2020

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.

@cypress-bot cypress-bot bot removed the stage: pending release There is a closed PR for this issue label Sep 29, 2020
@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Sep 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants