Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jest not exiting on successful completion of test suite #3602

Closed
rockchalkwushock opened this issue May 18, 2017 · 13 comments
Closed

jest not exiting on successful completion of test suite #3602

rockchalkwushock opened this issue May 18, 2017 · 13 comments

Comments

@rockchalkwushock
Copy link

rockchalkwushock commented May 18, 2017

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

@cpojer
Copy link
Member

cpojer commented May 18, 2017

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 cpojer closed this as completed May 18, 2017
@rockchalkwushock
Copy link
Author

@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.

@cpojer
Copy link
Member

cpojer commented May 18, 2017

Seems like whatever you do in afterEach isn't doing enough.

@rockchalkwushock
Copy link
Author

@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.

@WangHansen
Copy link

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

@rockchalkwushock
Copy link
Author

@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

@SimenB
Copy link
Member

SimenB commented Mar 19, 2018

FWIW, jest has --forceExit which does the same.

@WangHansen your issue is that you just close the connection, not the db itself, see 513a6fb

And as mentioned above - this is very much an SO question, not something for this issue tracker.

@sibelius
Copy link

@WangHansen have you figure it out?

@oryol
Copy link

oryol commented Sep 21, 2018

@SimenB, but db doesn't have close method according to the documentation and mongodb native driver code.

@candu
Copy link

candu commented Feb 5, 2019

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

@isaachinman
Copy link

@candu Mind giving a couple examples of how one might do that, given a pid?

@cyberwombat
Copy link

Dropping a note that --forceExit may result in really weird behavior. Took me days to figure out why my test w DynamoDb would randomly never return data - turns out that Jest was deciding to exit for whatever reason.

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants