I am going to build Mongodb environment in typescript project.
I referenced this page https://jestjs.io/docs/en/mongodb
and
sample project https://github.com/vladgolubev/jest-mongodb
When I run jest
in my project, it pass test ( I setup very simple test to test only mongodb environment) but it doesn't finish with success.
It recommend me to use --detectOpenHandles
to check non stopped asynchronous operations.
But when I run jest with this flag, jest --detectOpenHandles
it finish successfully without showing what operations are not stopped.
I tried many times, and it work same as I mentioned above.
Thanks
Please provide a reproduction, as stated in the template
App has no other function,
It's only mongodb environment testing and uses typescript, instead of javascript.
Mongodb test enviroment files are not modified and exactly same as example
https://github.com/vladgolubev/jest-mongodb
Thanks
We have an issue template that requests reproduction steps - this report is missing that. Happy to reopen if one is provided
@SimenB I have a repro for this:
import {createPool, sql} from 'slonik'
describe('open handles test', () => {
const slonik = createPool(`postgresql://postgres:postgres@localhost:5432/postgres`, {
maximumPoolSize: 1,
minimumPoolSize: 1,
idleTimeout: 1,
})
beforeAll(async () => {
await slonik.query(sql`drop table if exists foo`)
await slonik.query(sql`create table foo(id serial primary key, bar text)`)
await slonik.query(sql`insert into foo(bar) values('one two three')`)
})
it('selects', async () => {
const result = await slonik.one(sql`select * from foo`)
expect(result).toMatchInlineSnapshot(`
Object {
"bar": "one two three",
"id": 1,
}
`)
})
})
to run the db I'm doing docker-compose up
with this docker-compose.yaml
:
version: '3'
services:
postgres:
image: postgres
restart: always
ports:
- "5432:5432"
volumes:
- postgres:/var/lib/postgresql/data
volumes:
postgres:
dependencies "slonik": "^16.19.5", "jest": "^24.8.0"
When running with --detectOpenHandles
it just hangs after all tests pass, but doesn't report anything.
Issue in slonik: https://github.com/gajus/slonik/issues/63
edit: adding afterAll(() => new Promise(r => setTimeout(r, 0)))
fixes this for me (jest exits after tests). Not sure why that would be, but it seems like a bug.
@SimenB I can confirm the issue @mmkal is showcasing.
I'm seeing this issue too, it seems to be something do with Apollo Cache for me, any help would be appreciated. It passes locally but not in my CI.
I'm seeing this issue too, it seems to be something do with Apollo Cache for me, any help would be appreciated. It passes locally but not in my CI.
jest --forceExit
seems to work fine for me but also seems like a hack while I ignore the real problem.
you will find a reproduction of this issue in https://github.com/jeantil/documentstore
Running a test without --detectOpenHandles
yields a warning about not exiting in time:
>>> DEBUG="*:*" yarn jest src/firebase/index2.test.ts
yarn run v1.17.3
$ /home/jean/dev/startups/yupwego/src/gitlabci/node_modules/.bin/jest src/firebase/index2.test.ts
Determining test suites to run... snapdragon:compiler initializing /home/jean/dev/startups/yupwego/src/gitlabci/node_modules/snapdragon/lib/compiler.js +0ms
snapdragon:parser initializing /home/jean/dev/startups/yupwego/src/gitlabci/node_modules/snapdragon/lib/parser.js +1ms
snapdragon:compiler initializing /home/jean/dev/startups/yupwego/src/gitlabci/node_modules/snapdragon/lib/compiler.js +10ms
snapdragon:parser initializing /home/jean/dev/startups/yupwego/src/gitlabci/node_modules/snapdragon/lib/parser.js +0ms
ywg:store:firebase starting container +0ms
ywg:store:firebase container started +3s
ywg:store:firebase test starting +107ms
console.log src/firebase/index.ts:237
✔ connection to firebase 0b8e2966-7321-4e53-b3df-c209f4b942fb c192b3ca-1aa3-4ce3-bf19-52210730b6b7
ywg:store:firebase test completed +1s
ywg:store:firebase stopping container +1ms
ywg:store:firebase container stopped +11s
PASS src/firebase/index2.test.ts (20.064s)
FirebaseStore User repository
✓ should delete tokens (16886ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 20.105s, estimated 22s
Ran all test suites matching /src\/firebase\/index2.test.ts/i.
Jest did not exit one second after the test run has completed.
This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue.
running the same test with --detectOpenHandles
exits normally
>>> DEBUG="*:*" yarn jest --detectOpenHandles src/firebase/index2.test.ts
yarn run v1.17.3
$ /home/jean/dev/startups/yupwego/src/gitlabci/node_modules/.bin/jest --detectOpenHandles src/firebase/index2.test.ts
Determining test suites to run... snapdragon:compiler initializing /home/jean/dev/startups/yupwego/src/gitlabci/node_modules/snapdragon/lib/compiler.js +0ms
snapdragon:parser initializing /home/jean/dev/startups/yupwego/src/gitlabci/node_modules/snapdragon/lib/parser.js +2ms
snapdragon:compiler initializing /home/jean/dev/startups/yupwego/src/gitlabci/node_modules/snapdragon/lib/compiler.js +8ms
snapdragon:parser initializing /home/jean/dev/startups/yupwego/src/gitlabci/node_modules/snapdragon/lib/parser.js +1ms
ywg:store:firebase starting container +0ms
ywg:store:firebase container started +3s
ywg:store:firebase test starting +91ms
console.log src/firebase/index.ts:237
✔ connection to firebase 2bf81126-e892-41e4-8993-7c75b224cbd0 682ffc48-5dd6-4760-844f-d558a356797f
ywg:store:firebase test completed +1s
ywg:store:firebase stopping container +7ms
ywg:store:firebase container stopped +11s
PASS src/firebase/index2.test.ts (18.232s)
FirebaseStore User repository
✓ should delete tokens (16991ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 18.272s, estimated 21s
Ran all test suites matching /src\/firebase\/index2.test.ts/i.
Done in 34.85s.
src/firebase/index2.test.ts
uses testcontainers to spin up a docker container which runs the firebase firestore emulator. After the test is completed, the container id destroyed.
Unfortunately, as you can see from the debug output, starting and stopping the docker container of the emulator takes much more than a second. I think that long running async 'afterAll' or afterEach operations raise this issue.
Can confirm @mmkal issue, same thing for me
I have exactly the same problem
same happening to me.
bump
I have the same issue
bump
Running with jest --forceExit --detectOpenHandles
seems to work as expected. But it seems like a hack...
@mdelclaro This hack fixes warnings and make test exit, but if you really have "Open Handles" (non-resolved promises) you won't be able to detect them. So I think it is not solution to this problem
Same issue here.
@SimenB can you explain what would be required for this issue to be re-opened?
A proper reproduction we can pull down and run. I can almost guarantee anything that's not git clone && yarn && yarn test
(possibly with a docker run
before test if it needs to connect to something, and npm is of course fine) will not be very helpful.
https://github.com/facebook/jest/issues/6937#issuecomment-500886506 packaged up in a repository might work. https://github.com/facebook/jest/issues/6937#issuecomment-562861333 doesn't reproduce for me.
Note that I have an open PR that improves this (#9532), however it makes certain simpler caser worse. Need to figure out the correct balance. Probably some sort of heading saying which were collected in case it helps track down others. So more false positives, but also higher chance of not missing the ones that are real
Same here
@SimenB I've got a reproduction if you can forgive having to set up a firebase API key. I haven't been able to reproduce mocking it out.
https://gist.github.com/jamescrowley/d6f6468a9bfc5c4982d5a4838097acc2
Running with
jest --forceExit --detectOpenHandles
seems to work as expected. But it seems like a hack...
THANKS! After three hours! This was exactly what I was looking for!
A proper reproduction we can pull down and run. I can almost guarantee anything that's not
git clone && yarn && yarn test
(possibly with adocker run
before test if it needs to connect to something, and npm is of course fine) will not be very helpful.#6937 (comment) packaged up in a repository might work. #6937 (comment) doesn't reproduce for me.
Note that I have an open PR that improves this (#9532), however it makes certain simpler caser worse. Need to figure out the correct balance. Probably some sort of heading saying which were collected in case it helps track down others. So more false positives, but also higher chance of not missing the ones that are real
@SimenB as requested: https://github.com/mmkal/jest-6937-repro
Requires yarn
and docker-compose
:
git clone https://github.com/mmkal/jest-6937-repro
cd jest-6973-repro
yarn
yarn test
More details/a workaround in readme which might help to figure out the root-cause.
Experiencing the same issue here. Unfortunately, the workaround does not work for me. I have to use --forceExit
Most helpful comment
@SimenB I have a repro for this:
to run the db I'm doing
docker-compose up
with thisdocker-compose.yaml
:dependencies
"slonik": "^16.19.5", "jest": "^24.8.0"
When running with
--detectOpenHandles
it just hangs after all tests pass, but doesn't report anything.Issue in slonik: https://github.com/gajus/slonik/issues/63
edit: adding
afterAll(() => new Promise(r => setTimeout(r, 0)))
fixes this for me (jest exits after tests). Not sure why that would be, but it seems like a bug.