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
- Clone this repo
- Checkout the
jest-github-issue
branch - Run
npm install
- Create
.env
file containingNODE_ENV=test
- 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:
- Created 4 years ago
- Comments:6
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yeah, sounds good! Happy to take any other doc updates to make it clearer as well
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.