From 27bee728eba5ad1a0d808b921420d0abee1f574a Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Fri, 21 May 2021 00:05:40 +0200 Subject: [PATCH] fix: run GC before collecting open handles (#11278) --- CHANGELOG.md | 1 + e2e/__tests__/detectOpenHandles.ts | 11 +++++++++++ e2e/detect-open-handles/__tests__/crypto.js | 13 +++++++++++++ packages/jest-core/src/collectHandles.ts | 3 ++- 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 e2e/detect-open-handles/__tests__/crypto.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 70d616f2e945..dac3fa0e83f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -70,6 +70,7 @@ - `[jest-core]` Don't report PerformanceObserver as open handle ([#11123](https://github.com/facebook/jest/pull/11123)) - `[jest-core]` Use `WeakRef` to hold timers when detecting open handles ([#11277](https://github.com/facebook/jest/pull/11277)) - `[jest-core]` Correctly detect open handles that were created in test functions using `done` callbacks ([#11382](https://github.com/facebook/jest/pull/11382)) +- `[jest-core]` Do not collect `RANDOMBYTESREQUEST` as open handles ([#11278](https://github.com/facebook/jest/pull/11278)) - `[jest-diff]` [**BREAKING**] Use only named exports ([#11371](https://github.com/facebook/jest/pull/11371)) - `[jest-each]` [**BREAKING**] Ignore excess words in headings ([#8766](https://github.com/facebook/jest/pull/8766)) - `[jest-each]` Support array index with template strings ([#10763](https://github.com/facebook/jest/pull/10763)) diff --git a/e2e/__tests__/detectOpenHandles.ts b/e2e/__tests__/detectOpenHandles.ts index f070f4b9e25b..6e7ec474812f 100644 --- a/e2e/__tests__/detectOpenHandles.ts +++ b/e2e/__tests__/detectOpenHandles.ts @@ -71,6 +71,17 @@ it('does not report promises', () => { expect(textAfterTest).toBe(''); }); +it('does not report crypto random data', () => { + // The test here is basically that it exits cleanly without reporting anything (does not need `until`) + const {stderr} = runJest('detect-open-handles', [ + 'crypto', + '--detectOpenHandles', + ]); + const textAfterTest = getTextAfterTest(stderr); + + expect(textAfterTest).toBe(''); +}); + onNodeVersions('>=11.10.0', () => { it('does not report ELD histograms', () => { const {stderr} = runJest('detect-open-handles', [ diff --git a/e2e/detect-open-handles/__tests__/crypto.js b/e2e/detect-open-handles/__tests__/crypto.js new file mode 100644 index 000000000000..1a4284994d8e --- /dev/null +++ b/e2e/detect-open-handles/__tests__/crypto.js @@ -0,0 +1,13 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +const {randomFillSync} = require('crypto'); + +test('randomFillSync()', () => { + const buf = Buffer.alloc(10); + randomFillSync(buf); +}); diff --git a/packages/jest-core/src/collectHandles.ts b/packages/jest-core/src/collectHandles.ts index bb617a3c60bc..05f2ea481936 100644 --- a/packages/jest-core/src/collectHandles.ts +++ b/packages/jest-core/src/collectHandles.ts @@ -63,7 +63,8 @@ export default function collectHandles(): HandleCollectionResult { type === 'PROMISE' || type === 'TIMERWRAP' || type === 'ELDHISTOGRAM' || - type === 'PerformanceObserver' + type === 'PerformanceObserver' || + type === 'RANDOMBYTESREQUEST' ) { return; }