From 4ea625d76fd2de31f69a35b02964d4267541a1cf Mon Sep 17 00:00:00 2001 From: Oliver Salzburg Date: Tue, 2 Nov 2021 14:50:18 +0100 Subject: [PATCH] fix: Incorrect detection of open ZLIB handles It appears that some calls into `zlib` are detected as incorrectly being open. This change ignores open handles in the ZLIB context. Fixes #11542 --- CHANGELOG.md | 1 + .../src/__tests__/collectHandles.test.js | 15 +++++++++++++++ packages/jest-core/src/collectHandles.ts | 3 ++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fd5bcd972f8..d093394b71b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ### Fixes - `[expect]` Allow again `expect.Matchers` generic with single value ([#11986](https://github.com/facebook/jest/pull/11986)) +- `[jest-core]` Incorrect detection of open ZLIB handles ([#12022](https://github.com/facebook/jest/pull/12022)) - `[jest-environment-jsdom]` Add `@types/jsdom` dependency ([#11999](https://github.com/facebook/jest/pull/11999)) - `[jest-transform]` Improve error and warning messages ([#11998](https://github.com/facebook/jest/pull/11998)) diff --git a/packages/jest-core/src/__tests__/collectHandles.test.js b/packages/jest-core/src/__tests__/collectHandles.test.js index e35201822189..b0628157af00 100644 --- a/packages/jest-core/src/__tests__/collectHandles.test.js +++ b/packages/jest-core/src/__tests__/collectHandles.test.js @@ -9,6 +9,7 @@ import {promises as dns} from 'dns'; import http from 'http'; import {PerformanceObserver} from 'perf_hooks'; +import zlib from 'zlib'; import collectHandles from '../collectHandles'; describe('collectHandles', () => { @@ -52,6 +53,20 @@ describe('collectHandles', () => { ); }); + it('should not collect the ZLIB open handle', async () => { + const handleCollector = collectHandles(); + + const decompressed = zlib.inflateRawSync( + Buffer.from('cb2a2d2e5128492d2ec9cc4b0700', 'hex'), + ); + + const openHandles = await handleCollector(); + + expect(openHandles).not.toContainEqual( + expect.objectContaining({message: 'ZLIB'}), + ); + }); + 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 6212625a8914..72fea6ee6b94 100644 --- a/packages/jest-core/src/collectHandles.ts +++ b/packages/jest-core/src/collectHandles.ts @@ -71,7 +71,8 @@ export default function collectHandles(): HandleCollectionResult { type === 'ELDHISTOGRAM' || type === 'PerformanceObserver' || type === 'RANDOMBYTESREQUEST' || - type === 'DNSCHANNEL' + type === 'DNSCHANNEL' || + type === 'ZLIB' ) { return; }