-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
Copy pathchild_process-node.test.js
792 lines (730 loc) · 23.7 KB
/
child_process-node.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
import { bunEnv, bunExe, isWindows } from "harness";
import { createTest } from "node-harness";
import { ChildProcess, exec, fork, spawn } from "node:child_process";
import { tmpdir } from "node:os";
import path from "node:path";
import util from "node:util";
const { beforeAll, beforeEach, afterAll, describe, expect, it, throws, assert, createCallCheckCtx, createDoneDotAll } =
createTest(import.meta.path);
const origProcessEnv = process.env;
beforeEach(() => {
process.env = { ...bunEnv };
});
afterAll(() => {
process.env = origProcessEnv;
});
const strictEqual = (a, b) => expect(a).toStrictEqual(b);
const debug = process.env.DEBUG ? console.log : () => {};
const platformTmpDir = require("fs").realpathSync(tmpdir());
const TYPE_ERR_NAME = "TypeError";
const fixturesDir = path.join(__dirname, "fixtures");
const fixtures = {
path(...args) {
const strings = [fixturesDir, ...args].filter(util.isString);
return path.join(...strings);
},
};
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
const common = {
pwdCommand: isWindows ? ["node", ["-e", "process.stdout.write(process.cwd() + '\\n')"]] : ["pwd", []],
};
describe("ChildProcess.constructor", () => {
it("should be a function", () => {
strictEqual(typeof ChildProcess, "function");
});
});
describe("ChildProcess.spawn()", () => {
it("should throw on invalid options", () => {
// Verify that invalid options to spawn() throw.
const child = new ChildProcess();
[undefined, null, "foo", 0, 1, NaN, true, false].forEach(options => {
throws(
() => {
child.spawn(options);
},
{
code: "ERR_INVALID_ARG_TYPE",
name: TYPE_ERR_NAME,
// message:
// 'The "options" argument must be of type object.' +
// `${common.invalidArgTypeHelper(options)}`,
},
);
});
});
it("should throw if file is not a string", () => {
// Verify that spawn throws if file is not a string.
const child = new ChildProcess();
[undefined, null, 0, 1, NaN, true, false, {}].forEach(file => {
throws(
() => {
child.spawn({ file });
},
{
code: "ERR_INVALID_ARG_TYPE",
name: TYPE_ERR_NAME,
// message:
// 'The "options.file" property must be of type string.' +
// `${common.invalidArgTypeHelper(file)}`,
},
);
});
});
it("should throw if envPairs is not an array or undefined", () => {
// Verify that spawn throws if envPairs is not an array or undefined.
const child = new ChildProcess();
[null, 0, 1, NaN, true, false, {}, "foo"].forEach(envPairs => {
throws(
() => {
child.spawn({
envPairs,
stdio: ["ignore", "ignore", "ignore", "ipc"],
});
},
{
code: "ERR_INVALID_ARG_TYPE",
name: TYPE_ERR_NAME,
// message:
// 'The "options.envPairs" property must be an instance of Array.' +
// common.invalidArgTypeHelper(envPairs),
},
);
});
});
it("should throw if stdio is not an array or undefined", () => {
// Verify that spawn throws if args is not an array or undefined.
const child = new ChildProcess();
[null, 0, 1, NaN, true, false, {}, "foo"].forEach(args => {
throws(
() => {
child.spawn({ file: "foo", args });
},
{
code: "ERR_INVALID_ARG_TYPE",
name: TYPE_ERR_NAME,
// message:
// 'The "options.args" property must be an instance of Array.' +
// common.invalidArgTypeHelper(args),
},
);
});
});
});
describe("ChildProcess.spawn", () => {
function getChild() {
const child = new ChildProcess();
child.spawn({
file: "node",
// file: process.execPath,
args: ["node", "--interactive"],
cwd: process.cwd(),
stdio: ["ignore", "ignore", "ignore"],
});
return child;
}
it("should spawn a process", () => {
const child = getChild();
// Test that we can call spawn
strictEqual(Object.hasOwn(child, "pid"), true);
assert(Number.isInteger(child.pid));
child.kill();
});
it("should throw error on invalid signal", () => {
const child = getChild();
// Try killing with invalid signal
throws(
() => {
child.kill("foo");
},
{ code: "ERR_UNKNOWN_SIGNAL", name: TYPE_ERR_NAME },
);
});
});
describe("ChildProcess spawn bad stdio", () => {
// Monkey patch spawn() to create a child process normally, but destroy the
// stdout and stderr streams. This replicates the conditions where the streams
// cannot be properly created.
function createChild(options, callback, target) {
return new Promise((resolve, reject) => {
var __originalSpawn = ChildProcess.prototype.spawn;
ChildProcess.prototype.spawn = function () {
const err = __originalSpawn.apply(this, arguments);
this.stdout.destroy();
this.stderr.destroy();
return err;
};
let cmd =
target === "sleep"
? // The process can exit before returning which breaks tests.
((target = ""), `${bunExe()} -e "setTimeout(() => {}, 100)"`)
: `${bunExe()} ${path.join(import.meta.dir, "spawned-child.js")}`;
if (target) cmd += " " + target;
const child = exec(cmd, options, async (err, stdout, stderr) => {
try {
await callback(err, stdout, stderr);
resolve();
} catch (e) {
reject(e);
}
});
ChildProcess.prototype.spawn = __originalSpawn;
});
}
it("should handle normal execution of child process", async () => {
await createChild({}, (err, stdout, stderr) => {
strictEqual(err, null);
strictEqual(stdout, "");
strictEqual(stderr, "");
});
});
it.todo("should handle error event of child process", async () => {
const error = new Error(`Command failed: bun ${import.meta.dir}/spawned-child.js ERROR`);
await createChild(
{},
(err, stdout, stderr) => {
strictEqual(stdout, "");
strictEqual(stderr, "");
strictEqual(err?.message, error.message);
},
"ERROR",
);
});
it("should handle killed process", async () => {
await createChild(
{ timeout: 1 },
(err, stdout, stderr) => {
strictEqual(err.killed, true);
strictEqual(stdout, "");
strictEqual(stderr, "");
},
"sleep",
);
});
});
describe("child_process cwd", () => {
// Spawns 'pwd' with given options, then test
// - whether the child pid is undefined or number,
// - whether the exit code equals expectCode,
// - optionally whether the trimmed stdout result matches expectData
function testCwd(options, { expectPidType, expectCode = 0, expectData }, done = () => {}) {
const createDone = createDoneDotAll(done);
const { mustCall } = createCallCheckCtx(createDone(1500));
const exitDone = createDone(5000);
const child = spawn(...common.pwdCommand, { stdio: ["inherit", "pipe", "inherit"], ...options });
strictEqual(typeof child.pid, expectPidType);
child.stdout.setEncoding("utf8");
// No need to assert callback since `data` is asserted.
let data = "";
child.stdout.on("data", chunk => {
data += chunk;
});
// TODO: Test exit events
// // Can't assert callback, as stayed in to API:
// // _The 'exit' event may or may not fire after an error has occurred._
child.on("exit", (code, signal) => {
try {
strictEqual(code, expectCode);
exitDone();
} catch (err) {
exitDone(err);
}
});
child.stdout.on(
"close",
mustCall(() => {
expectData && strictEqual(data.trim(), expectData);
}),
);
return child;
}
// TODO: Make sure this isn't important
// Currently Bun.spawn will still spawn even though cwd doesn't exist
// // Assume does-not-exist doesn't exist, expect exitCode=-1 and errno=ENOENT
// it("should throw an error when given cwd doesn't exist", () => {
// testCwd({ cwd: "does-not-exist" }, "undefined", -1).on(
// "error",
// mustCall(function (e) {
// console.log(e);
// strictEqual(e.code, "ENOENT");
// }),
// );
// });
// TODO: Make sure this isn't an important test
// it("should throw when cwd is a non-file url", () => {
// throws(() => {
// testCwd(
// {
// cwd: new URL("http://example.com/"),
// },
// "number",
// 0,
// tmpdir.path
// );
// }, /The URL must be of scheme file/);
// // if (process.platform !== "win32") {
// // throws(() => {
// // testCwd(
// // {
// // cwd: new URL("file://host/dev/null"),
// // },
// // "number",
// // 0,
// // tmpdir.path
// // );
// // }, /File URL host must be "localhost" or empty on/);
// // }
// });
it("should work for valid given cwd", done => {
const tmpdir = { path: platformTmpDir };
const createDone = createDoneDotAll(done);
// Assume these exist, and 'pwd' gives us the right directory back
testCwd(
{ cwd: tmpdir.path },
{
expectPidType: "number",
expectCode: 0,
expectData: platformTmpDir,
},
createDone(1500),
);
const shouldExistDir = isWindows ? "C:\\Windows\\System32" : "/dev";
testCwd(
{ cwd: shouldExistDir },
{
expectPidType: "number",
expectCode: 0,
expectData: shouldExistDir,
},
createDone(1500),
);
testCwd(
{ cwd: Bun.pathToFileURL(tmpdir.path) },
{
expectPidType: "number",
expectCode: 0,
expectData: platformTmpDir,
},
createDone(1500),
);
});
it("shouldn't try to chdir to an invalid cwd", done => {
const createDone = createDoneDotAll(done);
// Spawn() shouldn't try to chdir() to invalid arg, so this should just work
testCwd({ cwd: "" }, { expectPidType: "number" }, createDone(1500));
testCwd({ cwd: undefined }, { expectPidType: "number" }, createDone(1500));
testCwd({ cwd: null }, { expectPidType: "number" }, createDone(1500));
});
});
describe("child_process default options", () => {
it("should use process.env as default env", done => {
process.env.TMPDIR = platformTmpDir;
// fake printenv
let child = spawn(bunExe(), ["--print", "process.env"], {});
let response = "";
child.stdout.setEncoding("utf8");
child.stdout.on("data", chunk => {
debug(`stdout: ${chunk}`);
response += chunk;
});
// NOTE: Original test used child.on("exit"), but this is unreliable
// because the process can exit before the stream is closed and the data is read
child.stdout.on("close", () => {
try {
expect(response).toContain(`TMPDIR: "${platformTmpDir.replace(/\\/g, "\\\\")}"`);
done();
} catch (e) {
done(e);
}
});
});
});
describe("child_process double pipe", () => {
it("should allow two pipes to be used at once", done => {
// const { mustCallAtLeast, mustCall } = createCallCheckCtx(done);
const mustCallAtLeast = fn => fn;
const mustCall = fn => fn;
let fakeGrep, fakeSed, fakeEcho;
fakeGrep = spawn(bunExe(), [
"-e",
"process.stdin.on('data', (data) => { const dataStr = data.toString(); if (dataStr.includes('o')) process.stdout.write(dataStr); });",
]);
fakeSed = spawn(bunExe(), [
"-e",
"process.stdin.on('data', (data) => { process.stdout.write(data.toString().replace(/o/g, 'O')); });",
]);
fakeEcho = spawn(bunExe(), ["-e", "console.log('hello');console.log('node');console.log('world');"]);
// pipe grep | sed
fakeGrep.stdout.on(
"data",
mustCallAtLeast(data => {
debug(`grep stdout ${data.length}`);
if (!fakeSed.stdin.write(data)) {
fakeGrep.stdout.pause();
}
}),
);
// print sed's output
fakeSed.stdout.on(
"data",
mustCallAtLeast(data => {
result += data.toString("utf8");
debug(data);
}),
);
fakeEcho.stdout.on(
"data",
mustCallAtLeast(data => {
debug(`grep stdin write ${data.length}`);
if (!fakeGrep.stdin.write(data)) {
debug("echo stdout pause");
fakeEcho.stdout.pause();
}
}),
);
// TODO(Derrick): We don't implement the full API for this yet,
// So stdin has no 'drain' event.
// TODO(@jasnell): This does not appear to ever be
// emitted. It's not clear if it is necessary.
fakeGrep.stdin.on("drain", () => {
debug("echo stdout resume");
fakeEcho.stdout.resume();
});
// Propagate end from echo to grep
fakeEcho.stdout.on(
"end",
mustCall(() => {
debug("echo stdout end");
fakeGrep.stdin.end();
}),
);
fakeEcho.on(
"exit",
mustCall(() => {
debug("echo exit");
}),
);
fakeGrep.on(
"exit",
mustCall(() => {
debug("grep exit");
}),
);
fakeSed.on(
"exit",
mustCall(() => {
debug("sed exit");
}),
);
// TODO(@jasnell): This does not appear to ever be
// emitted. It's not clear if it is necessary.
fakeSed.stdin.on("drain", () => {
fakeGrep.stdout.resume();
});
// Propagate end from grep to sed
fakeGrep.stdout.on(
"end",
mustCall(() => {
debug("grep stdout end");
fakeSed.stdin.end();
}),
);
let result = "";
fakeSed.stdout.on(
"end",
mustCall(() => {
debug("result: " + result);
strictEqual(result, `hellO\nnOde\nwOrld\n`);
done();
}),
);
});
});
describe("fork", () => {
const expectedEnv = { foo: "bar" };
describe("abort-signal", () => {
it("Test aborting a forked child_process after calling fork", done => {
const { mustCall } = createCallCheckCtx(done);
const ac = new AbortController();
const { signal } = ac;
const cp = fork(fixtures.path("child-process-stay-alive-forever.js"), {
signal,
env: bunEnv,
});
cp.on(
"exit",
mustCall((code, killSignal) => {
strictEqual(code, null);
strictEqual(killSignal, "SIGTERM");
}),
);
cp.on(
"error",
mustCall(err => {
strictEqual(err.name, "AbortError");
}),
);
process.nextTick(() => ac.abort());
});
it("Test aborting with custom error", done => {
const { mustCall } = createCallCheckCtx(done);
const ac = new AbortController();
const { signal } = ac;
const cp = fork(fixtures.path("child-process-stay-alive-forever.js"), {
signal,
env: bunEnv,
});
cp.on(
"exit",
mustCall((code, killSignal) => {
strictEqual(code, null);
strictEqual(killSignal, "SIGTERM");
}),
);
cp.on(
"error",
mustCall(err => {
strictEqual(err.name, "AbortError");
strictEqual(err.cause.name, "Error");
strictEqual(err.cause.message, "boom");
}),
);
process.nextTick(() => ac.abort(new Error("boom")));
});
it("Test passing an already aborted signal to a forked child_process", done => {
const { mustCall } = createCallCheckCtx(done);
const signal = AbortSignal.abort();
const cp = fork(fixtures.path("child-process-stay-alive-forever.js"), {
signal,
env: bunEnv,
});
cp.on(
"exit",
mustCall((code, killSignal) => {
strictEqual(code, null);
strictEqual(killSignal, "SIGTERM");
}),
);
cp.on(
"error",
mustCall(err => {
strictEqual(err.name, "AbortError");
}),
);
});
it("Test passing an aborted signal with custom error to a forked child_process", done => {
const { mustCall } = createCallCheckCtx(done);
const signal = AbortSignal.abort(new Error("boom"));
const cp = fork(fixtures.path("child-process-stay-alive-forever.js"), {
signal,
});
cp.on(
"exit",
mustCall((code, killSignal) => {
strictEqual(code, null);
strictEqual(killSignal, "SIGTERM");
}),
);
cp.on(
"error",
mustCall(err => {
strictEqual(err.name, "AbortError");
strictEqual(err.cause.name, "Error");
strictEqual(err.cause.message, "boom");
}),
);
});
it("Test passing a different kill signal", done => {
const { mustCall } = createCallCheckCtx(done);
const signal = AbortSignal.abort();
const cp = fork(fixtures.path("child-process-stay-alive-forever.js"), {
signal,
killSignal: "SIGKILL",
env: bunEnv,
});
cp.on(
"exit",
mustCall((code, killSignal) => {
strictEqual(code, null);
strictEqual(killSignal, "SIGKILL");
}),
);
cp.on(
"error",
mustCall(err => {
strictEqual(err.name, "AbortError");
}),
);
});
// This event doesn't run
it.todo("Test aborting a cp before close but after exit", done => {
const { mustCall, mustNotCall } = createCallCheckCtx(done);
const ac = new AbortController();
const { signal } = ac;
const cp = fork(fixtures.path("child-process-stay-alive-forever.js"), {
signal,
env: bunEnv,
});
cp.on(
"exit",
mustCall(() => {
ac.abort();
}),
);
cp.on("error", mustNotCall());
setTimeout(() => cp.kill(), 1);
});
});
describe("args", () => {
const invalidModulePath = [0, true, undefined, null, [], {}, () => {}, Symbol("t")];
invalidModulePath.forEach(modulePath => {
it(`Ensure that first argument \`modulePath\` must be provided and be of type string :: ${String(modulePath)}`, () => {
expect(() => fork(modulePath, { env: bunEnv })).toThrow(
expect.objectContaining({
code: "ERR_INVALID_ARG_TYPE",
name: "TypeError",
message: expect.stringContaining(
`The "modulePath" argument must be of type string, Buffer or URL. Received: `,
),
}),
);
});
});
// This test fails due to a DataCloneError or due to "Unable to deserialize data."
// This test was originally marked as TODO before the process changes.
it.todo(
"Ensure that the second argument of `fork` and `fork` should parse options correctly if args is undefined or null",
done => {
const invalidSecondArgs = [0, true, () => {}, Symbol("t")];
try {
invalidSecondArgs.forEach(arg => {
expect(() => fork(fixtures.path("child-process-echo-options.js"), arg)).toThrow({
code: "ERR_INVALID_ARG_TYPE",
name: "TypeError",
message: `The \"args\" argument must be of type Array. Received ${arg?.toString()}`,
});
});
} catch (e) {
done(e);
return;
}
const argsLists = [[]];
const { mustCall } = createCallCheckCtx(done);
argsLists.forEach(args => {
const cp = fork(fixtures.path("child-process-echo-options.js"), args, {
env: { ...bunEnv, ...expectedEnv },
});
cp.on(
"message",
mustCall(({ env }) => {
assert.strictEqual(env.foo, expectedEnv.foo);
}),
);
cp.on(
"exit",
mustCall(code => {
assert.strictEqual(code, 0);
}),
);
});
},
);
const invalidThirdArgs = [0, true, () => {}, Symbol("t")];
invalidThirdArgs.forEach(arg => {
it(`Ensure that the third argument should be type of object if provided :: ${String(arg)}`, () => {
expect(() => {
fork(fixtures.path("child-process-echo-options.js"), [], arg);
}).toThrow(
expect.objectContaining({
code: "ERR_INVALID_ARG_TYPE",
name: "TypeError",
message: expect.stringContaining(`The "options" argument must be of type object. Received: `),
}),
);
});
});
});
describe.todo("close", () => {
// https://github.com/nodejs/node/blob/v20.5.0/test/parallel/test-child-process-fork-close.js
});
describe.todo("detached", () => {
// https://github.com/nodejs/node/blob/v20.5.0/test/parallel/test-child-process-fork-detached.js
});
describe.todo("dgram", () => {
// https://github.com/nodejs/node/blob/v20.5.0/test/parallel/test-child-process-fork-dgram.js
});
describe.todo("net", () => {
// https://github.com/nodejs/node/blob/v20.5.0/test/parallel/test-child-process-fork-net.js
});
describe.todo("net-server", () => {
// https://github.com/nodejs/node/blob/v20.5.0/test/parallel/test-child-process-fork-net-server.js
});
describe.todo("net-socket", () => {
// https://github.com/nodejs/node/blob/v20.5.0/test/parallel/test-child-process-fork-net-socket.js
});
describe.todo("no-shell", () => {
// https://github.com/nodejs/node/blob/v20.5.0/test/parallel/test-child-process-fork-no-shell.js
});
describe.todo("ref", () => {
// https://github.com/nodejs/node/blob/v20.5.0/test/parallel/test-child-process-fork-ref.js
});
describe.todo("stdio", () => {
// https://github.com/nodejs/node/blob/v20.5.0/test/parallel/test-child-process-fork-stdio.js
});
describe("fork", () => {
it.todo("message", done => {
// TODO - bun has no `send` method in the process
const { mustCall } = createCallCheckCtx(done);
const args = ["foo", "bar"];
const n = fork(fixtures.path("child-process-spawn-node.js"), args);
assert.strictEqual(n.channel, n._channel);
assert.deepStrictEqual(args, ["foo", "bar"]);
n.on("message", m => {
debug("PARENT got message:", m);
assert.ok(m.foo);
});
expect(() => n.send(undefined)).toThrow({
name: "TypeError",
message: 'The "message" argument must be specified',
code: "ERR_MISSING_ARGS",
});
expect(() => n.send()).toThrow({
name: "TypeError",
message: 'The "message" argument must be specified',
code: "ERR_MISSING_ARGS",
});
expect(() => n.send(Symbol())).toThrow({
name: "TypeError",
message:
'The "message" argument must be one of type string,' +
" object, number, or boolean. Received type symbol (Symbol())",
code: "ERR_INVALID_ARG_TYPE",
});
n.send({ hello: "world" });
n.on(
"exit",
mustCall(c => {
assert.strictEqual(c, 0);
}),
);
});
});
});