Jest playground for issue with jest terminating.
This repository is for figuring out the issue with jest
not terminating when the testing suite completes successfully while using supertest
to mock the api endpoints.
git clone https://github.com/rockchalkwushock/jest-playground.git
cd jest-playground
yarn install
yarn test
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
never terminates upon completion of tests.
Script executing tests:
jest --config jest.config.json # nope not --watch'ing'
"testEnvironment": "node"
has been set from the beginning.jest.unmock(module)
as per #997.afterEach()
& have tried the afterAll()
hook for closing connection to server.Initially I believed #3 that this was the issue. That the server connection was remaining open
andjest
could not close because of it. Looking at the below screenshots I don’t believe that
is the case anymore.
Upon executing yarn test
the following is seen in the console:
Upon running the command:
ps | grep node
I see the following for the two scripts in the package.json
:
yarn start
yarn test
As per discussion with @cpojer in #3602 the issue was not enough was being done in the afterEach()
hook. The connection to MongoDB
was remaining open because I was only dropping connection to the collection not the entire database.
The StackO post has been answered similarly as well.
afterEach(async () => {
try {
const { todos } = mongoose.connection.collections;
// Collection is being dropped.
await todos.drop()
// Connection to Mongo killed.
await mongoose.disconnect();
// Server connection closed.
await server.close();
} catch (error) {
console.log(`
You did something wrong dummy!
${error}
`);
throw error;
}
});