Skip to content
Myr

forward.js

This file

Path

test/ipc/forward.js

98 lines · 4.3 KiB · JavaScript

Last changed by

TweaksSindre Sorhusbefore adoption698a1b8

History of this file

Take it

TweaksSindre Sorhusbefore adoption698a1b8

lines 1–3why, one step back
1import assert from 'node:assert/strict';
2import test from 'node:test';3import {assertRejects} from '../helpers/assert.js';

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 4–6why, one step back
4import {execa} from '../../index.js';
5import {setFixtureDirectory} from '../helpers/fixtures-directory.js';6import {foobarString, foobarArray} from '../helpers/input.js';

Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d

line 7why, one step back
7import {iterateAllMessages, isAlwaysTrue} from '../helpers/ipc.js';

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 8–10why, one step back
8
9setFixtureDirectory();10

TweaksSindre Sorhusbefore adoption698a1b8

line 11why, one step back
11const testParentErrorOne = async (filter, buffer) => {

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 12–15why, one step back
12 const subprocess = execa('ipc-send.js', {ipc: true, buffer});
1314 const promise = subprocess.getOneMessage({filter});15 const cause = new Error(foobarString);

Add `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf

line 16why, one step back
16 subprocess.nodeChildProcess.emit('error', cause);

TweaksSindre Sorhusbefore adoption698a1b8

line 17why, one step back
17 assert.equal(await promise, foobarString);

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

line 18why, one step back
18

TweaksSindre Sorhusbefore adoption698a1b8

lines 19–22why, one step back
19 const error = await assertRejects(subprocess);
20 assert.equal(error.exitCode, undefined);21 assert.equal(error.isTerminated, false);22 assert.equal(error.cause, cause);

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

line 23why, one step back
23 if (buffer) {

TweaksSindre Sorhusbefore adoption698a1b8

line 24why, one step back
24 assert.deepEqual(error.ipcOutput, [foobarString]);

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 25–27why, one step back
25 }
26};27

TweaksSindre Sorhusbefore adoption698a1b8

lines 28–31why, one step back
28test('"error" event does not interrupt subprocess.getOneMessage(), buffer false', () => testParentErrorOne(undefined, false));
29test('"error" event does not interrupt subprocess.getOneMessage(), buffer true', () => testParentErrorOne(undefined, true));30test('"error" event does not interrupt subprocess.getOneMessage(), buffer false, filter', () => testParentErrorOne(isAlwaysTrue, false));31test('"error" event does not interrupt subprocess.getOneMessage(), buffer true, filter', () => testParentErrorOne(isAlwaysTrue, true));

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

line 32why, one step back
32

TweaksSindre Sorhusbefore adoption698a1b8

line 33why, one step back
33const testSubprocessErrorOne = async (filter, buffer) => {

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 34–35why, one step back
34 const subprocess = execa('ipc-process-error.js', [`${filter}`], {ipc: true, buffer});
35 await subprocess.sendMessage(foobarString);

TweaksSindre Sorhusbefore adoption698a1b8

line 36why, one step back
36 assert.equal(await subprocess.getOneMessage(), foobarString);

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 37–39why, one step back
37
38 const {ipcOutput} = await subprocess;39 if (buffer) {

TweaksSindre Sorhusbefore adoption698a1b8

line 40why, one step back
40 assert.deepEqual(ipcOutput, [foobarString]);

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 41–43why, one step back
41 }
42};43

TweaksSindre Sorhusbefore adoption698a1b8

lines 44–47why, one step back
44test('"error" event does not interrupt exports.getOneMessage(), buffer false', () => testSubprocessErrorOne(false, false));
45test('"error" event does not interrupt exports.getOneMessage(), buffer true', () => testSubprocessErrorOne(false, true));46test('"error" event does not interrupt exports.getOneMessage(), buffer false, filter', () => testSubprocessErrorOne(true, false));47test('"error" event does not interrupt exports.getOneMessage(), buffer true, filter', () => testSubprocessErrorOne(true, true));

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

line 48why, one step back
48

TweaksSindre Sorhusbefore adoption698a1b8

line 49why, one step back
49const testParentErrorEach = async buffer => {

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 50–53why, one step back
50 const subprocess = execa('ipc-send-twice.js', {ipc: true, buffer});
5152 const promise = iterateAllMessages(subprocess);53 const cause = new Error(foobarString);

Add `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf

line 54why, one step back
54 subprocess.nodeChildProcess.emit('error', cause);

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

line 55why, one step back
55

TweaksSindre Sorhusbefore adoption698a1b8

lines 56–60why, one step back
56 const error = await assertRejects(subprocess);
57 assert.equal(error, await assertRejects(promise));58 assert.equal(error.exitCode, undefined);59 assert.equal(error.isTerminated, false);60 assert.equal(error.cause, cause);

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

line 61why, one step back
61 if (buffer) {

TweaksSindre Sorhusbefore adoption698a1b8

line 62why, one step back
62 assert.deepEqual(error.ipcOutput, foobarArray);

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 63–65why, one step back
63 }
64};65

TweaksSindre Sorhusbefore adoption698a1b8

lines 66–67why, one step back
66test('"error" event does not interrupt subprocess.getEachMessage(), buffer false', () => testParentErrorEach(false));
67test('"error" event does not interrupt subprocess.getEachMessage(), buffer true', () => testParentErrorEach(true));

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

line 68why, one step back
68

TweaksSindre Sorhusbefore adoption698a1b8

line 69why, one step back
69const testSubprocessErrorEach = async (filter, buffer) => {

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 70–71why, one step back
70 const subprocess = execa('ipc-iterate-error.js', [`${filter}`], {ipc: true, buffer});
71 await subprocess.sendMessage('.');

TweaksSindre Sorhusbefore adoption698a1b8

line 72why, one step back
72 assert.equal(await subprocess.getOneMessage(), '.');

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 73–76why, one step back
73 await subprocess.sendMessage(foobarString);
7475 const {ipcOutput} = await subprocess;76 if (buffer) {

TweaksSindre Sorhusbefore adoption698a1b8

line 77why, one step back
77 assert.deepEqual(ipcOutput, ['.']);

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 78–80why, one step back
78 }
79};80

TweaksSindre Sorhusbefore adoption698a1b8

lines 81–82why, one step back
81test('"error" event does not interrupt exports.getEachMessage(), buffer false', () => testSubprocessErrorEach('ipc-iterate-error.js', false));
82test('"error" event does not interrupt exports.getEachMessage(), buffer true', () => testSubprocessErrorEach('ipc-iterate-error.js', true));

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

line 83why, one step back
83

TweaksSindre Sorhusbefore adoption698a1b8

line 84why, one step back
84test('"error" event does not interrupt result.ipcOutput', async () => {

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 85–87why, one step back
85 const subprocess = execa('ipc-echo-twice.js', {ipcInput: foobarString});
8687 const cause = new Error(foobarString);

Add `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf

line 88why, one step back
88 subprocess.nodeChildProcess.emit('error', cause);

TweaksSindre Sorhusbefore adoption698a1b8

line 89why, one step back
89 assert.equal(await subprocess.getOneMessage(), foobarString);

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

line 90why, one step back
90 await subprocess.sendMessage(foobarString);

TweaksSindre Sorhusbefore adoption698a1b8

line 91why, one step back
91 assert.equal(await subprocess.getOneMessage(), foobarString);

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

line 92why, one step back
92

TweaksSindre Sorhusbefore adoption698a1b8

lines 93–97why, one step back
93 const error = await assertRejects(subprocess);
94 assert.equal(error.exitCode, undefined);95 assert.equal(error.isTerminated, false);96 assert.equal(error.cause, cause);97 assert.deepEqual(error.ipcOutput, [foobarString, foobarString]);

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

line 98why, one step back
98});