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.

afterAll fails to close Express server and leaves open handles

See original GitHub issue

🐛 Bug Report

Jest fails to close the Express server in the afterAll hook and leaves an open handle. After running into this issue with both supertest and axiosist, and then trying to roll my own solution, I’m starting to think this is actually an issue with Jest.

To Reproduce

  1. Clone this repo
  2. Checkout the jest-github-issue branch
  3. Run npm install
  4. Create .env file containing NODE_ENV=test
  5. Run npm test

Expected behavior

Jest should close the Express server in the afterAll hook and not leave any open handles

Link to repl or repo (highly encouraged)

https://github.com/johncmunson/todo-api Be sure to checkout the jest-github-issue branch

envinfo

System:
    OS: macOS Mojave 10.14.6
    CPU: (8) x64 Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
  Binaries:
    Node: 10.16.3 - ~/n/bin/node
    Yarn: 1.19.1 - /usr/local/bin/yarn
    npm: 6.9.0 - ~/n/bin/npm
  npmPackages:
    jest: ^24.9.0 => 24.9.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
SimenBcommented, Nov 23, 2019

Yeah, sounds good! Happy to take any other doc updates to make it clearer as well

0reactions
github-actions[bot]commented, May 11, 2021

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

How to close Express server inside Jest afterAll hook
My tests all run successfully, the only problem is that the server is failing to close down properly inside the afterAll hook. This...
Read more >
Mocha - the fun, simple, flexible JavaScript test framework
Mocha is a feature-rich JavaScript test framework running on Node.js and in the browser, making asynchronous testing simple and fun.
Read more >
Why Jest freezes after tests run? (Jest hangs indefinitely)
If you noticed that Jest (npm / yarn) test hang at the end of the test execution ... --detectOpenHandles - it attempts to...
Read more >
Fullstack part4 | Testing the backend
The test imports the Express application from the app.js module and wraps it with ... Our tests are already using the afterAll function...
Read more >
How to correctly unit test Express server - Gleb Bahmutov
Create and destroy an Express.js server in each unit test. ... To properly close the expressjs server, we need to wait for all...
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