diff --git a/CHANGELOG.md b/CHANGELOG.md index ca32e2a69b4c..86d006b78741 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ - `[jest-config]` [**BREAKING**] Add `mts` and `cts` to default `moduleFileExtensions` config ([#14369](https://github.com/facebook/jest/pull/14369)) - `[jest-config]` [**BREAKING**] Update `testMatch` and `testRegex` default option for supporting `mjs`, `cjs`, `mts`, and `cts` ([#14584](https://github.com/jestjs/jest/pull/14584)) - `[jest-config]` Loads config file from provided path in `package.json` ([#14044](https://github.com/facebook/jest/pull/14044)) -- `[@jest/core]` [**BREAKING**] Group together open handles with the same stack trace ([#13417](https://github.com/jestjs/jest/pull/13417), & [#14543](https://github.com/jestjs/jest/pull/14543)) +- `[@jest/core]` Group together open handles with the same stack trace ([#13417](https://github.com/jestjs/jest/pull/13417), & [#14789](https://github.com/jestjs/jest/pull/14789)) - `[@jest/core]` Add `perfStats` to surface test setup overhead ([#14622](https://github.com/jestjs/jest/pull/14622)) - `[@jest/core]` [**BREAKING**] Changed `--filter` to accept an object with shape `{ filtered: Array }` to match [documentation](https://jestjs.io/docs/cli#--filterfile) ([#13319](https://github.com/jestjs/jest/pull/13319)) - `[@jest/core, @jest/test-sequencer]` [**BREAKING**] Exposes `globalConfig` & `contexts` to `TestSequencer` ([#14535](https://github.com/jestjs/jest/pull/14535), & [#14543](https://github.com/jestjs/jest/pull/14543)) diff --git a/e2e/__tests__/__snapshots__/detectOpenHandles.ts.snap b/e2e/__tests__/__snapshots__/detectOpenHandles.ts.snap index 904ae1025ae1..67fed22a3f21 100644 --- a/e2e/__tests__/__snapshots__/detectOpenHandles.ts.snap +++ b/e2e/__tests__/__snapshots__/detectOpenHandles.ts.snap @@ -19,7 +19,7 @@ exports[`prints message about flag on slow tests with a custom timeout 1`] = ` exports[`prints out info about open handlers 1`] = ` "Jest has detected the following 1 open handle potentially keeping Jest from exiting: - ● DNSCHANNEL,TCPSERVERWRAP + ● 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 0c77e7783e11..d34e6272928e 100644 --- a/packages/jest-core/src/__tests__/collectHandles.test.js +++ b/packages/jest-core/src/__tests__/collectHandles.test.js @@ -32,10 +32,8 @@ describe('collectHandles', () => { it('should not collect the PerformanceObserver open handle', async () => { const handleCollector = collectHandles(); - let obs = new PerformanceObserver((list, observer) => {}); + const obs = new PerformanceObserver((list, observer) => {}); obs.observe({entryTypes: ['mark']}); - obs.disconnect(); - obs = null; const openHandles = await handleCollector(); @@ -47,12 +45,9 @@ describe('collectHandles', () => { it('should not collect the DNSCHANNEL open handle', async () => { const handleCollector = collectHandles(); - let resolver = new dns.Resolver(); + const resolver = new dns.Resolver(); resolver.getServers(); - // We must drop references to it - resolver = null; - const openHandles = await handleCollector(); expect(openHandles).not.toContainEqual( @@ -141,11 +136,10 @@ describe('collectHandles', () => { ); }); - it('should not be false positives for some special objects such as `TLSWRAP`', async () => { + it('should not collect the `TLSWRAP` open handle', async () => { const handleCollector = collectHandles(); const socket = new TLSSocket(); - socket.destroy(); const openHandles = await handleCollector(); diff --git a/packages/jest-core/src/collectHandles.ts b/packages/jest-core/src/collectHandles.ts index 2f16c999f54c..8ef0faa684f2 100644 --- a/packages/jest-core/src/collectHandles.ts +++ b/packages/jest-core/src/collectHandles.ts @@ -82,7 +82,20 @@ export default function collectHandles(): HandleCollectionResult { // 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') { + if ( + [ + 'PROMISE', + 'TIMERWRAP', + 'ELDHISTOGRAM', + 'PerformanceObserver', + 'RANDOMBYTESREQUEST', + 'DNSCHANNEL', + 'ZLIB', + 'SIGNREQUEST', + 'TLSWRAP', + 'TCPWRAP', + ].includes(type) + ) { return; } const error = new ErrorWithStack(type, initHook, 100); @@ -136,8 +149,6 @@ export default function collectHandles(): HandleCollectionResult { await asyncSleep(30); if (activeHandles.size > 0) { - // For some special objects such as `TLSWRAP`. - // Ref: https://github.com/jestjs/jest/issues/11665 runGC(); await asyncSleep(0);