From 711b60262a13fedb75a5eb1b37b36056e66da617 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mica=C3=ABl=20Mbagira?= Date: Sat, 27 Feb 2021 15:28:19 +0100 Subject: [PATCH] fix: do not count PerformanceObserver as an open handle (#11123) --- CHANGELOG.md | 1 + .../src/__tests__/collectHandles.test.js | 36 +++++++++++++++++++ packages/jest-core/src/collectHandles.ts | 3 +- 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 packages/jest-core/src/__tests__/collectHandles.test.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 024f5b662f56..54974bd5946b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ - `[jest-cli]` Print custom error if error thrown from global hooks is not an error already ([#11003](https://github.com/facebook/jest/pull/11003)) - `[jest-config]` [**BREAKING**] Change default file extension order by moving json behind ts and tsx ([10572](https://github.com/facebook/jest/pull/10572)) - `[jest-console]` `console.dir` now respects the second argument correctly ([#10638](https://github.com/facebook/jest/pull/10638)) +- `[jest-core]` Don't report PerformanceObserver as open handle ([#11123](https://github.com/facebook/jest/pull/11123)) - `[jest-each]` [**BREAKING**] Ignore excess words in headings ([#8766](https://github.com/facebook/jest/pull/8766)) - `[jest-environment-jsdom]` Use inner realm’s `ArrayBuffer` constructor ([#10885](https://github.com/facebook/jest/pull/10885)) - `[jest-globals]` [**BREAKING**] Disallow return values other than a `Promise` from hooks and tests ([#10512](https://github.com/facebook/jest/pull/10512)) diff --git a/packages/jest-core/src/__tests__/collectHandles.test.js b/packages/jest-core/src/__tests__/collectHandles.test.js new file mode 100644 index 000000000000..24644ef39215 --- /dev/null +++ b/packages/jest-core/src/__tests__/collectHandles.test.js @@ -0,0 +1,36 @@ +/** + * 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. + * + */ + +import {PerformanceObserver} from 'perf_hooks'; +import collectHandles from '../collectHandles'; + +describe('collectHandles', () => { + it('should collect Timeout', () => { + const handleCollector = collectHandles(); + + const interval = setInterval(() => {}, 100); + + const openHandles = handleCollector(); + + expect(openHandles).toHaveLength(1); + expect(openHandles[0].message).toContain('Timeout'); + + clearInterval(interval); + }); + + it('should not collect the PerformanceObserver open handle', () => { + const handleCollector = collectHandles(); + const obs = new PerformanceObserver((list, observer) => {}); + obs.observe({entryTypes: ['mark']}); + + const openHandles = handleCollector(); + + expect(openHandles).toHaveLength(0); + obs.disconnect(); + }); +}); diff --git a/packages/jest-core/src/collectHandles.ts b/packages/jest-core/src/collectHandles.ts index b39310aebc10..13a8181ec3b4 100644 --- a/packages/jest-core/src/collectHandles.ts +++ b/packages/jest-core/src/collectHandles.ts @@ -57,7 +57,8 @@ export default function collectHandles(): () => Array { if ( type === 'PROMISE' || type === 'TIMERWRAP' || - type === 'ELDHISTOGRAM' + type === 'ELDHISTOGRAM' || + type === 'PerformanceObserver' ) { return; }