From 9cee325b513e18d37839ef179fcd988f1bc053ff Mon Sep 17 00:00:00 2001 From: C L <0cl> Date: Mon, 17 Aug 2020 04:21:30 +0100 Subject: [PATCH 1/5] fix: skip open handle --- packages/jest-core/src/collectHandles.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/jest-core/src/collectHandles.ts b/packages/jest-core/src/collectHandles.ts index 3575387e28da..4db21d8fc2a1 100644 --- a/packages/jest-core/src/collectHandles.ts +++ b/packages/jest-core/src/collectHandles.ts @@ -52,7 +52,11 @@ export default function collectHandles(): () => Array { _triggerAsyncId, resource: {} | NodeJS.Timeout, ) { - if (type === 'PROMISE' || type === 'TIMERWRAP') { + if ( + type === 'PROMISE' || + type === 'TIMERWRAP' || + type === 'ELDHISTOGRAM' + ) { return; } const error = new ErrorWithStack(type, initHook); From 079272d172e6800d280d785b1ffa271bf4c313d9 Mon Sep 17 00:00:00 2001 From: C L Date: Mon, 17 Aug 2020 20:00:26 +0100 Subject: [PATCH 2/5] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd0ebbcf853a..24aeea265177 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Fixes +- `[jest-core]` Don't report ELDHistogram as open handle ([#10417](https://github.com/facebook/jest/pull/10417)) - `[jest-reporters]` Fixes notify reporter on Linux (using notify-send) ([#10393](https://github.com/facebook/jest/pull/10400)) - `[jest-snapshot]` Correctly handles arrays and property matchers in snapshots ([#10404](https://github.com/facebook/jest/pull/10404)) From 6564528b781cca7585dc006d00943d2dd89b4b64 Mon Sep 17 00:00:00 2001 From: C L Date: Mon, 17 Aug 2020 21:59:08 +0100 Subject: [PATCH 3/5] fix: don't report ELD histograms as open handles --- e2e/__tests__/detectOpenHandles.ts | 10 ++++++++++ e2e/detect-open-handles/__tests__/histogram.js | 10 ++++++++++ 2 files changed, 20 insertions(+) create mode 100644 e2e/detect-open-handles/__tests__/histogram.js diff --git a/e2e/__tests__/detectOpenHandles.ts b/e2e/__tests__/detectOpenHandles.ts index fd5ecc03cce8..094c8d48cc66 100644 --- a/e2e/__tests__/detectOpenHandles.ts +++ b/e2e/__tests__/detectOpenHandles.ts @@ -71,6 +71,16 @@ it('does not report promises', () => { expect(textAfterTest).toBe(''); }); +it('does not report ELD histograms', () => { + const {stderr} = runJest('detect-open-handles', [ + 'histogram', + '--detectOpenHandles', + ]); + const textAfterTest = getTextAfterTest(stderr); + + expect(textAfterTest).toBe(''); +}); + describe('notify', () => { it('does not report --notify flag', () => { if (process.platform === 'win32') { diff --git a/e2e/detect-open-handles/__tests__/histogram.js b/e2e/detect-open-handles/__tests__/histogram.js new file mode 100644 index 000000000000..3172ab00f387 --- /dev/null +++ b/e2e/detect-open-handles/__tests__/histogram.js @@ -0,0 +1,10 @@ +/** + * 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. + */ + +test('something', () => { + expect(true).toBe(true); +}); From 5f86e41b00a19e682ba4a4f4d031965b4c3e968a Mon Sep 17 00:00:00 2001 From: C L Date: Wed, 19 Aug 2020 00:11:50 +0100 Subject: [PATCH 4/5] Add histogram object --- e2e/detect-open-handles/__tests__/histogram.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/e2e/detect-open-handles/__tests__/histogram.js b/e2e/detect-open-handles/__tests__/histogram.js index 3172ab00f387..44eb14738c2c 100644 --- a/e2e/detect-open-handles/__tests__/histogram.js +++ b/e2e/detect-open-handles/__tests__/histogram.js @@ -4,7 +4,13 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ +const perf_hooks = require('perf_hooks'); test('something', () => { + try { + perf_hooks.monitorEventLoopDelay({}).enable(); + } catch { + // node version <11.10.0 + } expect(true).toBe(true); }); From 976894cece46eaf2f9b858d48bf4f6365f3e3183 Mon Sep 17 00:00:00 2001 From: C L Date: Wed, 19 Aug 2020 15:38:16 +0100 Subject: [PATCH 5/5] Update test with onNodeVersions --- e2e/__tests__/detectOpenHandles.ts | 16 +++++++++------- e2e/detect-open-handles/__tests__/histogram.js | 9 +++------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/e2e/__tests__/detectOpenHandles.ts b/e2e/__tests__/detectOpenHandles.ts index 094c8d48cc66..977434965a3f 100644 --- a/e2e/__tests__/detectOpenHandles.ts +++ b/e2e/__tests__/detectOpenHandles.ts @@ -71,14 +71,16 @@ it('does not report promises', () => { expect(textAfterTest).toBe(''); }); -it('does not report ELD histograms', () => { - const {stderr} = runJest('detect-open-handles', [ - 'histogram', - '--detectOpenHandles', - ]); - const textAfterTest = getTextAfterTest(stderr); +onNodeVersions('>=11.10.0', () => { + it('does not report ELD histograms', () => { + const {stderr} = runJest('detect-open-handles', [ + 'histogram', + '--detectOpenHandles', + ]); + const textAfterTest = getTextAfterTest(stderr); - expect(textAfterTest).toBe(''); + expect(textAfterTest).toBe(''); + }); }); describe('notify', () => { diff --git a/e2e/detect-open-handles/__tests__/histogram.js b/e2e/detect-open-handles/__tests__/histogram.js index 44eb14738c2c..df971ba126ad 100644 --- a/e2e/detect-open-handles/__tests__/histogram.js +++ b/e2e/detect-open-handles/__tests__/histogram.js @@ -4,13 +4,10 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ -const perf_hooks = require('perf_hooks'); +const {monitorEventLoopDelay} = require('perf_hooks'); test('something', () => { - try { - perf_hooks.monitorEventLoopDelay({}).enable(); - } catch { - // node version <11.10.0 - } + const histogram = monitorEventLoopDelay(); + histogram.enable(); expect(true).toBe(true); });