question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Tests hang when afterEach promise does not resolve with Retires enabled

See original GitHub issue

Current behavior

I recently noticed that our e2e tests periodically fail the first run and then randomly hang on the retry run. After outputting cypress logs via DEBUG='cypress:*' I found the following:

  • The test:after:run event never gets fired when the test hang on the retry run, The test:after:run event is supposed to happen after the afterEach and after Mocha hooks run
  • We get an onMocha hook output, which means that the afterEach hook has started
  • We never receive an onMocha hook end output. This signifies the afterEach hook has never finished. So the afterEach hook is hanging for some reason Screen Shot 2022-05-10 at 10 14 06 AM

It appears to me that the tests are hanging when retries are enabled and the afterEach promise does not resolve

Desired behavior

During the first retry, Cypress should reach timeout and fail. The test should not hang.

Test code to reproduce

I am unable to share test code/logs due to proprietary rights. However, I was able to reproduce a similar error where the test hangs on first retry when the done() callback is never invoked.

In cypress.json

"retries": {
    "runMode": 1,
    "openMode": 1
 }

Test Case

describe('Cypress Tests Hang', () => {
  it('Cypress Tests Hang', () => {
    cy.visit('https://www.google.com');
  });

  afterEach(run => {
    cy.log('In afterEach');
  });
});

You’ll see that the first run fails, and the retry run will end up hanging

Screen Shot 2022-05-24 at 2 51 46 PM

Cypress Version

9.7.0

Other

No response

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:3
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
taylorjellsworthcommented, Oct 11, 2022

@flotwig I was wondering if there’s any estimate on when this will get looked at? We are still running into this issue.

1reaction
taylorjellsworthcommented, Jul 21, 2022

Hi @jennifer-shehane ! This is still causing us issues, I was wondering if anyone has started looking into it yet?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Resolution method is overspecified”? in beforeEach and ...
When I use done in beforeEach or afterEach I get this error “Error: Resolution method is overspecified” and the test fails. But now...
Read more >
Mocha - the fun, simple, flexible JavaScript test framework
simple, flexible, fun. Mocha is a feature-rich JavaScript test framework running on Node.js and in the browser, making asynchronous testing simple and fun....
Read more >
Error Messages | Cypress Documentation
No tests found. This message means that Cypress was unable to find tests in the specified file. You'll likely get this message if...
Read more >
Test Lifecycle Events - Node Tap
As of v15, Promises are the only way to use these functions asynchronously. t.afterEach(fn(childTest)). This is called after each child test (or any...
Read more >
Frontend testing standards and style guidelines - GitLab Docs
You can also return a promise from the test function. Using the done and done.fail callbacks is discouraged when working with promises. They...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found