MCPcopy
hub / github.com/jestjs/jest / messageParent

Function messageParent

packages/jest-worker/src/workers/messageParent.ts:14–49  ·  view source on GitHub ↗
(
  message: unknown,
  parentProcess = process,
)

Source from the content-addressed store, hash-verified

12import {packMessage} from './safeMessageTransferring';
13
14export default function messageParent(
15 message: unknown,
16 parentProcess = process,
17): void {
18 if (!isMainThread && parentPort != null) {
19 try {
20 parentPort.postMessage([PARENT_MESSAGE_CUSTOM, message]);
21 } catch (error) {
22 // Try to handle https://html.spec.whatwg.org/multipage/structured-data.html#structuredserializeinternal
23 // for `symbols` and `functions`
24 if (isDataCloneError(error)) {
25 parentPort.postMessage([PARENT_MESSAGE_CUSTOM, packMessage(message)]);
26 } else {
27 throw error;
28 }
29 }
30 } else if (typeof parentProcess.send === 'function') {
31 try {
32 parentProcess.send([PARENT_MESSAGE_CUSTOM, message]);
33 } catch (error) {
34 if (
35 isError(error) &&
36 // if .send is a function, it's a serialization issue
37 !error.message.includes('.send is not a function')
38 ) {
39 // Apply specific serialization only in error cases
40 // to avoid affecting performance in regular cases.
41 parentProcess.send([PARENT_MESSAGE_CUSTOM, packMessage(message)]);
42 } else {
43 throw error;
44 }
45 }
46 } else {
47 throw new TypeError('"messageParent" can only be used inside a worker');
48 }
49}

Callers 1

sendMessageToJestFunction · 0.90

Calls 4

isDataCloneErrorFunction · 0.90
packMessageFunction · 0.90
sendMethod · 0.65
isErrorFunction · 0.50

Tested by

no test coverage detected