diff --git a/packages/jest-worker/src/Farm.ts b/packages/jest-worker/src/Farm.ts index f6ad78524d63..e06df7d7c2fd 100644 --- a/packages/jest-worker/src/Farm.ts +++ b/packages/jest-worker/src/Farm.ts @@ -85,9 +85,9 @@ export default class Farm { const onEnd: OnEnd = (error: Error | null, result: unknown) => { customMessageListeners.clear(); if (error) { - return reject(error); + reject(error); } else { - return resolve(result); + resolve(result); } }; diff --git a/packages/jest-worker/src/workers/messageParent.ts b/packages/jest-worker/src/workers/messageParent.ts index 45e6dba493b1..458b908ac1f2 100644 --- a/packages/jest-worker/src/workers/messageParent.ts +++ b/packages/jest-worker/src/workers/messageParent.ts @@ -8,15 +8,12 @@ import {isMainThread, parentPort} from 'worker_threads'; import {PARENT_MESSAGE_CUSTOM} from '../types'; -const isWorkerThread = !isMainThread && parentPort; - const messageParent = ( message: unknown, parentProcess: NodeJS.Process = process, ): void => { try { - if (isWorkerThread) { - const {parentPort} = require('worker_threads'); + if (!isMainThread && parentPort) { parentPort.postMessage([PARENT_MESSAGE_CUSTOM, message]); } else if (typeof parentProcess.send === 'function') { parentProcess.send([PARENT_MESSAGE_CUSTOM, message]);