diff --git a/packages/jest-worker/src/index.ts b/packages/jest-worker/src/index.ts index 50be5683dfba..a563d79781e3 100644 --- a/packages/jest-worker/src/index.ts +++ b/packages/jest-worker/src/index.ts @@ -45,6 +45,13 @@ function getExposedMethods( return exposedMethods; } +export function serializeBigInt(data: unknown): unknown { + if (typeof data === 'bigint') { + return data.toString(); + } + return data; +} + /** * The Jest farm (publicly called "Worker") is a class that allows you to queue * methods across multiple child processes, in order to parallelize work. This diff --git a/packages/jest-worker/src/workers/messageParent.ts b/packages/jest-worker/src/workers/messageParent.ts index d4a389055fc0..662e51db1643 100644 --- a/packages/jest-worker/src/workers/messageParent.ts +++ b/packages/jest-worker/src/workers/messageParent.ts @@ -5,6 +5,7 @@ * LICENSE file in the root directory of this source tree. */ +import {serializeBigInt} from '../index'; import {PARENT_MESSAGE_CUSTOM} from '../types'; const isWorkerThread: boolean = (() => { @@ -29,7 +30,7 @@ export default function messageParent( // ! is safe due to `null` check in `isWorkerThread` parentPort!.postMessage([PARENT_MESSAGE_CUSTOM, message]); } else if (typeof parentProcess.send === 'function') { - parentProcess.send([PARENT_MESSAGE_CUSTOM, message]); + parentProcess.send([PARENT_MESSAGE_CUSTOM, serializeBigInt(message)]); } else { throw new Error('"messageParent" can only be used inside a worker'); } diff --git a/packages/jest-worker/src/workers/processChild.ts b/packages/jest-worker/src/workers/processChild.ts index 64d29e19e132..5359b3f5f765 100644 --- a/packages/jest-worker/src/workers/processChild.ts +++ b/packages/jest-worker/src/workers/processChild.ts @@ -5,6 +5,7 @@ * LICENSE file in the root directory of this source tree. */ +import {serializeBigInt} from '../index'; import { CHILD_MESSAGE_CALL, CHILD_MESSAGE_END, @@ -64,7 +65,7 @@ function reportSuccess(result: unknown) { throw new Error('Child can only be used on a forked process'); } - process.send([PARENT_MESSAGE_OK, result]); + process.send([PARENT_MESSAGE_OK, serializeBigInt(result)]); } function reportClientError(error: Error) {