jest: DNSCHANNEL stops jest from closing
Jest does not closed himself after test finished
–detectOpenHandles suggest I need to close DNSCHANNEL manually:
Jest has detected the following 1 open handle potentially keeping Jest from exiting:
● DNSCHANNEL
at dns.js:333:23
But I cannot find any additonal information based on that problem.
I have async tests running supertest and jest.
"express": "^4.16.3",
"jest": "^23.1.0",
"supertest": "^3.1.0",
"pg": "^7.4.3",
"pg-pool": "^2.0.3"
Test code
const request = require('supertest');
const app = require('server');
// close the server after each test
afterEach(async () => {
await app.db.close();
});
const wFixture = [{
"complexity": 3,
}];
describe('Controllers', () => {
test('list get method', async () => {
const response = await request(app).get('/');
expect(response.status).toEqual(200);
expect(response.body.count).toEqual(1);
expect(response.body.data).toEqual(wFixture);
});
});
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 20
- Comments: 20 (4 by maintainers)
Commits related to this issue
- forceExit jest see https://github.com/facebook/jest/issues/6423 — committed to kay-schecker/oa-nest-middleware by kay-schecker 4 years ago
Can confirm that this issue still exists, in my case it does prevent jest to exit, thus requiring
--forceExit
:with all up-to-date versions:
I’m seeing the same issue here.
In my opinion, the issue is between
jest
and the DNSResolver
class in NodeJS the standard library.got
is not to blame there. It’s simply a popular library using theResolver
class (which shouldn’t be instantiated by default in got as it is not used by default but that’s an issue forgot
).@SimenB could it be possible to re-open this issue ?
test.spec.ts
I haven’t found a way to close the open handle.
ava
does not cause an error.For Googlers:
I have a file
db.ts
that I mocked withdb.js
.db.ts
opens up a database connection and causes this error to appear whendb.ts
is ran in a Jest test.Renaming the mock file to
db.ts
fixed this issue for me.In order to solve this issue, I found two critical problems in a project and one antipattern we’ve been using. Hope this information will help everyone who faced same issue:
express().listener()
we have been returningexpress()
in server.jsWrong version
Fixed version:
Wrong version:
Fixed version:
Same issue here. It is caused by
mongodb
in my case. This simple code will make it.module version node : 10.4.0 mongodb : 3.0.10 jest : 23.1.0
Even when i upgrade to
v14.9.0
I still got this problem. I’m also usinggot
in my project.Did you change anything else ?
I was seeing this with node
v12.10.0
, usinggot
andnock
. Upgrading to nodev14.9.0
resolved it for me.