From ac7aa8fed2e7231ccc9eed625c0c326e7347454a Mon Sep 17 00:00:00 2001 From: Micael Mbagira Date: Fri, 26 Feb 2021 13:36:45 +0100 Subject: [PATCH 1/3] fix(): jest should not count PerformanceObserver as an open handle --- CHANGELOG.md | 1 + .../src/__tests__/collectHandles.test.js | 35 +++++++++++++++++++ packages/jest-core/src/collectHandles.ts | 3 +- 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 packages/jest-core/src/__tests__/collectHandles.test.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 024f5b662f56..5381317eb4e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ ### Fixes +- `[jest-core]` Don't report PerformanceObserver as open handle ([#11123](https://github.com/facebook/jest/pull/11123)) - `[babel-plugin-jest-hoist]` Add `__dirname` and `__filename` to whitelisted globals ([#10903](https://github.com/facebook/jest/pull/10903)) - `[expect]` [**BREAKING**] Revise `expect.not.objectContaining()` to be the inverse of `expect.objectContaining()`, as documented. ([#10708](https://github.com/facebook/jest/pull/10708)) - `[expect]` [**BREAKING**] Make `toContain` more strict with the received type ([#10119](https://github.com/facebook/jest/pull/10119) & [#10929](https://github.com/facebook/jest/pull/10929)) 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..2d44b59b2c1e --- /dev/null +++ b/packages/jest-core/src/__tests__/collectHandles.test.js @@ -0,0 +1,35 @@ +/** + * 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.length).toEqual(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.length).toEqual(0); + }); +}); 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; } From 92cf949747e7432f4847a6427abb2a53c462a306 Mon Sep 17 00:00:00 2001 From: Micael Mbagira Date: Sat, 27 Feb 2021 08:49:09 +0100 Subject: [PATCH 2/3] fixup! fix(): jest should not count PerformanceObserver as an open handle --- packages/jest-core/src/__tests__/collectHandles.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/jest-core/src/__tests__/collectHandles.test.js b/packages/jest-core/src/__tests__/collectHandles.test.js index 2d44b59b2c1e..49115117282b 100644 --- a/packages/jest-core/src/__tests__/collectHandles.test.js +++ b/packages/jest-core/src/__tests__/collectHandles.test.js @@ -31,5 +31,6 @@ describe('collectHandles', () => { const openHandles = handleCollector(); expect(openHandles.length).toEqual(0); + obs.disconnect(); }); }); From 21c6c3827a70213cfe5cb2e8e3e1821465787c70 Mon Sep 17 00:00:00 2001 From: Micael Mbagira Date: Sat, 27 Feb 2021 14:51:46 +0100 Subject: [PATCH 3/3] fixup! fix(): jest should not count PerformanceObserver as an open handle --- CHANGELOG.md | 2 +- packages/jest-core/src/__tests__/collectHandles.test.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5381317eb4e2..54974bd5946b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,7 +25,6 @@ ### Fixes -- `[jest-core]` Don't report PerformanceObserver as open handle ([#11123](https://github.com/facebook/jest/pull/11123)) - `[babel-plugin-jest-hoist]` Add `__dirname` and `__filename` to whitelisted globals ([#10903](https://github.com/facebook/jest/pull/10903)) - `[expect]` [**BREAKING**] Revise `expect.not.objectContaining()` to be the inverse of `expect.objectContaining()`, as documented. ([#10708](https://github.com/facebook/jest/pull/10708)) - `[expect]` [**BREAKING**] Make `toContain` more strict with the received type ([#10119](https://github.com/facebook/jest/pull/10119) & [#10929](https://github.com/facebook/jest/pull/10929)) @@ -36,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 index 49115117282b..24644ef39215 100644 --- a/packages/jest-core/src/__tests__/collectHandles.test.js +++ b/packages/jest-core/src/__tests__/collectHandles.test.js @@ -17,7 +17,7 @@ describe('collectHandles', () => { const openHandles = handleCollector(); - expect(openHandles.length).toEqual(1); + expect(openHandles).toHaveLength(1); expect(openHandles[0].message).toContain('Timeout'); clearInterval(interval); @@ -30,7 +30,7 @@ describe('collectHandles', () => { const openHandles = handleCollector(); - expect(openHandles.length).toEqual(0); + expect(openHandles).toHaveLength(0); obs.disconnect(); }); });