MCPcopy Index your code
hub / github.com/nodejs/node / test

Function test

test/parallel/test-worker-messaging-errors-invalid.js:14–41  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

12const assert = require('node:assert');
13
14async function test() {
15 await assert.rejects(common.mustCall(function() {
16 return postMessageToThread(threadId);
17 }), {
18 name: 'Error',
19 code: 'ERR_WORKER_MESSAGING_SAME_THREAD',
20 });
21
22 await assert.rejects(common.mustCall(function() {
23 return postMessageToThread(Date.now());
24 }), {
25 name: 'Error',
26 code: 'ERR_WORKER_MESSAGING_FAILED',
27 });
28
29 // The delivery to the first worker will fail as there is no listener for `workerMessage`
30 const worker = new Worker(__filename, { workerData: { children: true } });
31 await once(worker, 'message');
32
33 await assert.rejects(common.mustCall(function() {
34 return postMessageToThread(worker.threadId);
35 }), {
36 name: 'Error',
37 code: 'ERR_WORKER_MESSAGING_FAILED',
38 });
39
40 worker.postMessage('success');
41}
42
43if (!workerData?.children) {
44 test();

Calls 4

postMessageMethod · 0.95
postMessageToThreadFunction · 0.85
nowMethod · 0.80
onceFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…