Bug
jest
does not exit after test suite completes successfully.
Issue began in the following repository:
Repository I made for looking at the issue and troubleshooting it:
README has more information and screenshots present.
When running jest --config jest.config.json
upon successful completion of the test suite I would expect to see _Done in X amount of seconds_.
I've search StackO & the issue tracker. Taken the advice put forth in #997 for unmocking
the modules; but issue still persists. I've removed node_modules and reinstalled, ran --no-cache
, followed the guidelines on the Troubleshooting page on the jest
website but to no avail.
| Tech | Version |
|------|-----------------------|
| node | 7.9.0 |
| npm | 4.5.0 |
| yarn | 0.24.4 |
| macOS| Sierra 10.12.4 |
| jest | 20.0.3 (package.json) |
{
"bail": true,
"testEnvironment": "node"
}
I forgot to include the original post I opened on StackO yesterday. It is pertaining to the code from the first repository.
http://stackoverflow.com/questions/44036189/jest-not-terminating-after-tests-complete-successfully
The problem is that your test is likely setting up some intervals, network connections or db connections and you aren't shutting them down properly after your tests. Jest doesn't know how to clean those up for you.
@cpojer
I checked for open processes and the only thing I get back is:
Is there another way to look for open processes that I'm not aware of? I use the afterEach()
hook to drop the database connection & close the server.
Seems like whatever you do in afterEach isn't doing enough.
@cpojer
Sorry for opening this I feel so stupid now. You were absolutely right. I was only dropping the specific collection to the database. It was dropping the database and closing the server connection but the connection to mongo
was staying open. I just wonder why the process didn't show when running 馃
ps | grep node
At any rate this was what I was missing:
// Connection to Mongo killed.
await mongoose.disconnect();
Again sorry for opening this issue.
This is not working for me, I am using mongoose 5.0.2
I have tried the following code and none of them terminates:
afterAll(async () => {
await mongoose.connection.dropDatabase('test')
mongoose.connection.close()
})
or
afterAll(async () => {
await mongoose.connection.dropDatabase('test')
await mongoose.disconnect()
})
or
afterAll((done) => {
mongoose.connection.dropDatabase('test').then(()=>{
mongoose.connection.close()
})
done()
})
or
afterAll((done) => {
mongoose.connection.dropDatabase('test').then(()=>{
mongoose.connection.close()
done()
})
})
Please help, thanks in advance
@WangHansen
Have you looked at some of the other comments left on the StackO post? This should really be something you ask on StackO as it probably is not an issue related to jest
as much as it is that the mongoose
connection is not terminating so jest
cannot terminate as well.
https://stackoverflow.com/questions/44036189/jest-not-terminating-after-tests-complete-successfully
FWIW, jest has --forceExit
which does the same.
@WangHansen your issue is that you just close the connection, not the db itself, see https://github.com/facebook/jest/pull/5571/commits/513a6fbad495d6c72de65ede00c5c787718a4724
And as mentioned above - this is very much an SO question, not something for this issue tracker.
@WangHansen have you figure it out?
@SimenB, but db doesn't have close
method according to the documentation and mongodb native driver code.
For those seeing this just now: you can use lsof
/ netstat
to identify the files / sockets held open by a given process, which can be useful in diagnosing node.js event loop hang-on-finish problems like this ;)
@candu Mind giving a couple examples of how one might do that, given a pid
?
Most helpful comment
FWIW, jest has
--forceExit
which does the same.@WangHansen your issue is that you just close the connection, not the db itself, see https://github.com/facebook/jest/pull/5571/commits/513a6fbad495d6c72de65ede00c5c787718a4724
And as mentioned above - this is very much an SO question, not something for this issue tracker.