cypress-io / cypress

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

Cypress hangs when reloading after an intercept that forces an error. #26000

Closed mjhenkes closed 1 year ago

mjhenkes commented 1 year ago

Current behavior

Given the following tests, cypress will hang the browser when cy.reload is called. This didn't happen for me immediately but it did happen on a refreh.

context('Cypress Lockup', function () {
  it('Stuck Test', function () {
    // These are not real credentials.
    // Please sign up (for free) at www.vidyard.com, verify your email address and then update these accordingly.
    // You must also complete the onboarding and hide the tutorial in your new account.
    const email = 'you@cypress.io';
    const password = 'yourPassword!';
    cy.visit('https://secure.vidyard.com/user/sign_in');
    cy.get('#username').type(email);
    cy.get('#next-login').click();
    cy.get('#password').type(password);
    cy.get('#sign-in').click();
    cy.wait(10000); // Just to make sure the login process is complete.
    cy.intercept('/graphql', { forceNetworkError: true }); // Forces an error page to appear.
    cy.reload();
  });
});

Desired behavior

No hangs.

Test code to reproduce

Private repo, as me for access. https://github.com/mjhenkes/cypress-intercept-reload-hang

Cypress Version

12.7.0

Node version

18

Operating System

macos

Debug Logs

No response

Other

Internal slack link: https://cypressio.slack.com/archives/C9KG9TQBX/p1677775559454759?thread_ts=1677617269.109309&cid=C9KG9TQBX

chrisbreiding commented 1 year ago

I believe this issue is a bug in the user's application and not a bug in Cypress. I can reproduce this outside of Cypress like so:

The user code gets hung up in an infinite loop in a function called setupAdvancedSearch. There's a component that, when mounted, calls setupAdvancedSearch. It expects a certain search input to exist. If it doesn't, it waits a tick, then recursively calls itself, probably expecting the search input to eventually render. The problem is that the search input never renders on the error page that's triggered by that request failing, so the function infinitely calls itself and hangs up the browser.

There's nothing we can do in Cypress to prevent this. It needs to be fixed in the app code.