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.

Improve description of "Jest did not exit one second after the test run has completed"

See original GitHub issue

I have an integration test that calls production code interacting with MySQL. All was working “fine” until I added --runInBand for debugging purposes. Suddenly, my tests started hanging after they ran and this message was shown:

Jest did not exit one second after the test run has completed.

This usually means that there are asynchronous operations that weren’t stopped in your tests. Consider running Jest with --detectOpenHandles to troubleshoot this issue.

I tried adding --detectOpenHandles as advised but that only made the message disappear – the tests still ended up hanging.

Only later I found out that the true reason was that I forgot to close the MySQL connection in my code – adding connection.end() fixed it.

I think it’s truly awesome that Jest helped me discover an actual issue but maybe the message could be improved? There seem to be other people confused by this, e.g.:

In my scenario, a message like this would be more helpful:

Jest did not exit one second after the test run has completed.

This usually means that there are asynchronous operations that weren’t stopped in your tests or that your code didn’t close network connections. Consider running Jest with --detectOpenHandles to troubleshoot this issue.

I’m not sure if this message is factually correct but unclosed connections to MySQL, Redis and similar systems seem to be a relatively common cause to the tests hanging.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
scotthovestadtcommented, Apr 14, 2019

I’m OK with updating the message but I feel like “network connections” is a still a little less clear. I tried to write something more clear, but the error message quickly grows into paragraphs.

What might be best is to update the message to something like:

Jest did not exit one second after the test run has completed. For more information, see https://jestjs.io/docs/did-not-exit-immediately

We would then be able to provide a lot more information on what’s happening and edit it easily.

@SimenB thoughts?

0reactions
github-actions[bot]commented, May 2, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest did not exit one second after the test run has completed ...
Jest did not exit one second after the test run has completed. This usually means that there are asynchronous operations that weren't stopped...
Read more >
Jest did not exit one second after the test run has completed.
Jest did not exit one second after the test run has completed. This usually means that there are asynchronous operations that weren't stopped...
Read more >
How To Fix: Jest Did Not Exit - DONN FELKER
Jest did not exit one second after the test run has completed. This usually means that there are asynchronous operations that weren't stopped...
Read more >
Jest CLI Options
Force Jest to exit after all tests have completed running. This is useful when resources set up by test code cannot be adequately...
Read more >
Testing Asynchronous Code · Jest
It's common in JavaScript for code to run asynchronously. When you have code that runs asynchronously, Jest needs to know when the code...
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