Skip to content

Commit bfbb45c

Browse files
authored
fix: Revert breaking changes for detectOpenHandles (#14789)
1 parent 544fac7 commit bfbb45c

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
- `[jest-config]` [**BREAKING**] Add `mts` and `cts` to default `moduleFileExtensions` config ([#14369](https://github.com/facebook/jest/pull/14369))
99
- `[jest-config]` [**BREAKING**] Update `testMatch` and `testRegex` default option for supporting `mjs`, `cjs`, `mts`, and `cts` ([#14584](https://github.com/jestjs/jest/pull/14584))
1010
- `[jest-config]` Loads config file from provided path in `package.json` ([#14044](https://github.com/facebook/jest/pull/14044))
11-
- `[@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))
11+
- `[@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))
1212
- `[@jest/core]` Add `perfStats` to surface test setup overhead ([#14622](https://github.com/jestjs/jest/pull/14622))
1313
- `[@jest/core]` [**BREAKING**] Changed `--filter` to accept an object with shape `{ filtered: Array<string> }` to match [documentation](https://jestjs.io/docs/cli#--filterfile) ([#13319](https://github.com/jestjs/jest/pull/13319))
1414
- `[@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))

e2e/__tests__/__snapshots__/detectOpenHandles.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ exports[`prints message about flag on slow tests with a custom timeout 1`] = `
1919
exports[`prints out info about open handlers 1`] = `
2020
"Jest has detected the following 1 open handle potentially keeping Jest from exiting:
2121
22-
DNSCHANNEL,TCPSERVERWRAP
22+
● TCPSERVERWRAP
2323
2424
12 | const app = new Server();
2525
13 |

packages/jest-core/src/__tests__/collectHandles.test.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ describe('collectHandles', () => {
3232
it('should not collect the PerformanceObserver open handle', async () => {
3333
const handleCollector = collectHandles();
3434

35-
let obs = new PerformanceObserver((list, observer) => {});
35+
const obs = new PerformanceObserver((list, observer) => {});
3636
obs.observe({entryTypes: ['mark']});
37-
obs.disconnect();
38-
obs = null;
3937

4038
const openHandles = await handleCollector();
4139

@@ -47,12 +45,9 @@ describe('collectHandles', () => {
4745
it('should not collect the DNSCHANNEL open handle', async () => {
4846
const handleCollector = collectHandles();
4947

50-
let resolver = new dns.Resolver();
48+
const resolver = new dns.Resolver();
5149
resolver.getServers();
5250

53-
// We must drop references to it
54-
resolver = null;
55-
5651
const openHandles = await handleCollector();
5752

5853
expect(openHandles).not.toContainEqual(
@@ -143,11 +138,10 @@ describe('collectHandles', () => {
143138
);
144139
});
145140

146-
it('should not be false positives for some special objects such as `TLSWRAP`', async () => {
141+
it('should not collect the `TLSWRAP` open handle', async () => {
147142
const handleCollector = collectHandles();
148143

149144
const socket = new TLSSocket();
150-
socket.destroy();
151145

152146
const openHandles = await handleCollector();
153147

packages/jest-core/src/collectHandles.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,20 @@ export default function collectHandles(): HandleCollectionResult {
8282
// Skip resources that should not generally prevent the process from
8383
// exiting, not last a meaningfully long time, or otherwise shouldn't be
8484
// tracked.
85-
if (type === 'PROMISE') {
85+
if (
86+
[
87+
'PROMISE',
88+
'TIMERWRAP',
89+
'ELDHISTOGRAM',
90+
'PerformanceObserver',
91+
'RANDOMBYTESREQUEST',
92+
'DNSCHANNEL',
93+
'ZLIB',
94+
'SIGNREQUEST',
95+
'TLSWRAP',
96+
'TCPWRAP',
97+
].includes(type)
98+
) {
8699
return;
87100
}
88101
const error = new ErrorWithStack(type, initHook, 100);
@@ -136,8 +149,6 @@ export default function collectHandles(): HandleCollectionResult {
136149
await asyncSleep(30);
137150

138151
if (activeHandles.size > 0) {
139-
// For some special objects such as `TLSWRAP`.
140-
// Ref: https://github.com/jestjs/jest/issues/11665
141152
runGC();
142153

143154
await asyncSleep(0);

0 commit comments

Comments
 (0)