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

Error in 'before' hook causes tests to hang #476

Closed
mallison opened this issue Nov 26, 2020 · 4 comments
Closed

Error in 'before' hook causes tests to hang #476

mallison opened this issue Nov 26, 2020 · 4 comments

Comments

@mallison
Copy link
Contributor

Current behavior

I have some setup code in Mocha's before hook that logs in and makes some API requests to set up the database.

If an error occurs in this hook the test hangs.

Screenshot 2020-11-26 at 14 51 32

It gets stuck here with the timer stopped and the progress icon spins indefinitely.

This only happens if the feature file has more than one scenario.

Desired behavior

The tests should stop and show the error in the sidebar.

Screenshot 2020-11-26 at 14 53 50

Test code to reproduce

I've created a minimal example https://github.com/mallison/cypress-cucumber-before-bug.

There are two feature files

  1. ErrorInBeforeHaltsTest.feature
  2. ErrorInBeforeHangsTest.feature

In each of the tests I have the following before hook:

before(() => {
    // the rejected promise is standing in for a error during login or db seeding
    return Promise.reject(new Error('this causes cypress to hang'))
})

Feature 1. has a single scenario and stops correctly showing the error in before.

Feature 2. has two scenarios and hangs

There's at least one similar issue against Cypress itself -- cypress-io/cypress#9162 -- but I've verified that a non-Cucumber test doesn't have this issue.

Versions

  • Cypress version: 6.0.0
  • Preprocessor version: 4.0.0
  • Node version: 12.4.0
@vidarc
Copy link

vidarc commented Mar 26, 2021

Have been getting this issue as well, though only seems to happen when we run the tests within our jenkins pipeline. Guessing whatever is causing our hook to fail is only failing within there for some reason. Also, seems like this issue affects the after hooks as well. We don't use any before from what I could tell, but after hooks are used to clean up various application data. Using cypress 6.x.x as well. From other teams I work with, seems Cypress 5.x.x does not have this issue.

@JoepKockelkorn
Copy link

We seems to have this same problem, but same as @vidarc says, only in our Jenkins pipeline. I haven't been able to identify an actual error from happening, but maybe a canceled request also counts as an 'error'.

@JoepKockelkorn
Copy link

JoepKockelkorn commented Sep 15, 2021

Update: What we've observed was that on teardown of a test Cypress cancels all running requests, which then are registered in the before or beforeEach of the next test. These canceled requests were not having a proper authentication token somehow, which resulted in a redirect to our identity provider (which is another domain).

Cypress only allows one domain per test, this redirect caused everything to hang. The actual fix was in our application code: prevent outgoing requests if there is no valid authentication token.

@badeball
Copy link
Owner

Due to personal reasons, the previous maintainers of this package are stepping down and handing the reigns over to me, a long-time contributor to the project and a user of it myself. This is a responsibility I'm very excited about. Furthermore, I'd like to thank @lgandecki ++ for all the work that they've done so far.

Read more about the transfer of ownership here.

The repository has however moved and all outstanding issues are being closed. This is not a reflection of the perceived importance of your reported issue. However, if after upgrading to the new version, you still find there to be an issue, feel free to open up another ticket or comment below. Please make sure to read CONTRIBUTING.md before doing so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants