From 277f7e481cba21c78108288a08fc6eba37710971 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Tue, 3 May 2022 15:36:56 +0200 Subject: [PATCH] chore: add test that unreffed workers are not reported (#12798) --- e2e/__tests__/detectOpenHandles.ts | 14 ++++++++++++++ e2e/detect-open-handles/__tests__/worker.js | 17 +++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 e2e/detect-open-handles/__tests__/worker.js diff --git a/e2e/__tests__/detectOpenHandles.ts b/e2e/__tests__/detectOpenHandles.ts index 97586bbbbf16..c23359faeed5 100644 --- a/e2e/__tests__/detectOpenHandles.ts +++ b/e2e/__tests__/detectOpenHandles.ts @@ -5,6 +5,7 @@ * LICENSE file in the root directory of this source tree. */ +import {onNodeVersions} from '@jest/test-utils'; import runJest, {runContinuous} from '../runJest'; function getTextAfterTest(stderr: string) { @@ -119,6 +120,19 @@ it('does not report child_process using unref', () => { expect(textAfterTest).toBe(''); }); +onNodeVersions('>=18.1.0', () => { + it('does not report worker using unref', () => { + // The test here is basically that it exits cleanly without reporting anything (does not need `until`) + const {stderr} = runJest('detect-open-handles', [ + 'worker', + '--detectOpenHandles', + ]); + const textAfterTest = getTextAfterTest(stderr); + + expect(textAfterTest).toBe(''); + }); +}); + it('prints out info about open handlers from inside tests', async () => { const run = runContinuous('detect-open-handles', [ 'inside', diff --git a/e2e/detect-open-handles/__tests__/worker.js b/e2e/detect-open-handles/__tests__/worker.js new file mode 100644 index 000000000000..51ea93201669 --- /dev/null +++ b/e2e/detect-open-handles/__tests__/worker.js @@ -0,0 +1,17 @@ +/** + * 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 {Worker} = require('worker_threads'); + +test('something', () => { + const worker = new Worker(require.resolve('../interval-code'), { + stderr: true, + stdout: true, + }); + worker.unref(); + expect(true).toBe(true); +});