diff --git a/CHANGELOG.md b/CHANGELOG.md index 36888f1eb302..ef1541b09591 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ### Fixes - `[jest-circus, @jest/test-sequencer]` Remove dependency on `jest-runner` ([#11466](https://github.com/facebook/jest/pull/11466)) +- `[jest-core]` Do not warn about `DNSCHANNEL` handles when using the `--detectOpenHandles` option ([#11470](https://github.com/facebook/jest/pull/11470)) - `[jest-runner]` Remove dependency on `jest-config` ([#11466](https://github.com/facebook/jest/pull/11466)) - `[jest-worker]` Loosen engine requirement to `>= 10.13.0` ([#11451](https://github.com/facebook/jest/pull/11451)) diff --git a/e2e/__tests__/__snapshots__/detectOpenHandles.ts.snap b/e2e/__tests__/__snapshots__/detectOpenHandles.ts.snap index 40aeef9d4529..42094ed3b596 100644 --- a/e2e/__tests__/__snapshots__/detectOpenHandles.ts.snap +++ b/e2e/__tests__/__snapshots__/detectOpenHandles.ts.snap @@ -13,7 +13,7 @@ This usually means that there are asynchronous operations that weren't stopped i exports[`prints out info about open handlers 1`] = ` Jest has detected the following 1 open handle potentially keeping Jest from exiting: - ● DNSCHANNEL + ● TCPSERVERWRAP 12 | const app = new Server(); 13 | diff --git a/packages/jest-core/src/__tests__/collectHandles.test.js b/packages/jest-core/src/__tests__/collectHandles.test.js index 9e97b8c64498..e35201822189 100644 --- a/packages/jest-core/src/__tests__/collectHandles.test.js +++ b/packages/jest-core/src/__tests__/collectHandles.test.js @@ -6,6 +6,7 @@ * */ +import {promises as dns} from 'dns'; import http from 'http'; import {PerformanceObserver} from 'perf_hooks'; import collectHandles from '../collectHandles'; @@ -38,6 +39,19 @@ describe('collectHandles', () => { obs.disconnect(); }); + it('should not collect the DNSCHANNEL open handle', async () => { + const handleCollector = collectHandles(); + + const resolver = new dns.Resolver(); + resolver.getServers(); + + const openHandles = await handleCollector(); + + expect(openHandles).not.toContainEqual( + expect.objectContaining({message: 'DNSCHANNEL'}), + ); + }); + it('should collect handles opened in test functions with `done` callbacks', done => { const handleCollector = collectHandles(); const server = http.createServer((_, response) => response.end('ok')); diff --git a/packages/jest-core/src/collectHandles.ts b/packages/jest-core/src/collectHandles.ts index c98543d647c1..6212625a8914 100644 --- a/packages/jest-core/src/collectHandles.ts +++ b/packages/jest-core/src/collectHandles.ts @@ -62,12 +62,16 @@ export default function collectHandles(): HandleCollectionResult { triggerAsyncId, resource: {} | NodeJS.Timeout, ) { + // Skip resources that should not generally prevent the process from + // exiting, not last a meaningfully long time, or otherwise shouldn't be + // tracked. if ( type === 'PROMISE' || type === 'TIMERWRAP' || type === 'ELDHISTOGRAM' || type === 'PerformanceObserver' || - type === 'RANDOMBYTESREQUEST' + type === 'RANDOMBYTESREQUEST' || + type === 'DNSCHANNEL' ) { return; }