jest not exiting on successful completion of test suite

Created on 18 May 2017  路  11Comments  路  Source: facebook/jest

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

jest does not exit after test suite completes successfully.

Repository

Issue began in the following repository:

Repository I made for looking at the issue and troubleshooting it:

README has more information and screenshots present.

What is the expected behavior?

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 Info

| 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) |

Jest Config

{
  "bail": true,
  "testEnvironment": "node"
}

Update

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

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.

All 11 comments

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:

process-yarn-test

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?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stephenlautier picture stephenlautier  路  3Comments

ticky picture ticky  路  3Comments

ianp picture ianp  路  3Comments

Secretmapper picture Secretmapper  路  3Comments

StephanBijzitter picture StephanBijzitter  路  3Comments