Skip to content
Myr

outgoing.js

This file

Path

test/ipc/outgoing.js

93 lines · 5.1 KiB · JavaScript

Last changed by

TweaksSindre Sorhusbefore adoption698a1b8

History of this file

Take it

TweaksSindre Sorhusbefore adoption698a1b8

lines 1–2why, one step back
1import assert from 'node:assert/strict';
2import test from 'node:test';

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

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

Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d

line 6why, one step back
6import {isAlwaysTrue, subprocessGetOne, subprocessGetFirst} from '../helpers/ipc.js';

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 7–10why, one step back
7import {PARALLEL_COUNT} from '../helpers/parallel.js';
89setFixtureDirectory();10

TweaksSindre Sorhusbefore adoption698a1b8

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

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 12–14why, one step back
12 const subprocess = execa('ipc-iterate.js', {ipc: true, buffer});
1314 await subprocess.sendMessage(0);

TweaksSindre Sorhusbefore adoption698a1b8

line 15why, one step back
15 assert.equal(await subprocess.getOneMessage({filter}), 0);

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 16–20why, one step back
16
17 const messages = Array.from({length: PARALLEL_COUNT}, (_, index) => index + 1);18 await Promise.all([19 ...messages.map(message => subprocess.sendMessage(message)),20 subprocess.sendMessage(foobarString),

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

line 21why, one step back
21 subprocess.nodeChildProcess.emit('message', '.'),

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

line 22why, one step back
22 ]);

TweaksSindre Sorhusbefore adoption698a1b8

line 23why, one step back
23 assert.equal(await getMessage(subprocess, {filter}), '.');

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 24–25why, one step back
24
25 const {ipcOutput} = await subprocess;

TweaksSindre Sorhusbefore adoption698a1b8

lines 26–27why, one step back
26 if (!buffer) {
27 return;

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

line 28why, one step back
28 }

TweaksSindre Sorhusbefore adoption698a1b8

lines 29–31why, one step back
29
30 const expectedOutput = [0, '.', ...messages];31 assert.deepEqual(ipcOutput, expectedOutput);

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 32–33why, one step back
32};
33

TweaksSindre Sorhusbefore adoption698a1b8

lines 34–39why, one step back
34test('Multiple parallel subprocess.sendMessage() + subprocess.getOneMessage(), buffer false', () => testSendHoldParent(subprocessGetOne, false, undefined));
35test('Multiple parallel subprocess.sendMessage() + subprocess.getOneMessage(), buffer true', () => testSendHoldParent(subprocessGetOne, true, undefined));36test('Multiple parallel subprocess.sendMessage() + subprocess.getOneMessage(), buffer false, filter', () => testSendHoldParent(subprocessGetOne, false, isAlwaysTrue));37test('Multiple parallel subprocess.sendMessage() + subprocess.getOneMessage(), buffer true, filter', () => testSendHoldParent(subprocessGetOne, true, isAlwaysTrue));38test('Multiple parallel subprocess.sendMessage() + subprocess.getEachMessage(), buffer false', () => testSendHoldParent(subprocessGetFirst, false, undefined));39test('Multiple parallel subprocess.sendMessage() + subprocess.getEachMessage(), buffer true', () => testSendHoldParent(subprocessGetFirst, true, undefined));

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

line 40why, one step back
40

TweaksSindre Sorhusbefore adoption698a1b8

line 41why, one step back
41const testSendHoldSubprocess = async (filter, isGetEach) => {

Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10

line 42why, one step back
42 const {ipcOutput} = await execa('ipc-iterate-back.js', [`${filter}`, `${isGetEach}`], {ipcInput: 0});

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

line 43why, one step back
43 const expectedOutput = [...Array.from({length: PARALLEL_COUNT + 1}, (_, index) => index), '.'];

TweaksSindre Sorhusbefore adoption698a1b8

line 44why, one step back
44 assert.deepEqual(ipcOutput, expectedOutput);

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 45–46why, one step back
45};
46

TweaksSindre Sorhusbefore adoption698a1b8

lines 47–49why, one step back
47test('Multiple parallel exports.sendMessage() + exports.getOneMessage()', () => testSendHoldSubprocess(false, false));
48test('Multiple parallel exports.sendMessage() + exports.getOneMessage(), filter', () => testSendHoldSubprocess(true, false));49test('Multiple parallel exports.sendMessage() + exports.getEachMessage()', () => testSendHoldSubprocess(false, true));

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

line 50why, one step back
50

TweaksSindre Sorhusbefore adoption698a1b8

line 51why, one step back
51const testSendHoldParentSerial = async (getMessage, buffer, filter) => {

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 52–54why, one step back
52 const subprocess = execa('ipc-iterate.js', {ipc: true, buffer});
5354 await subprocess.sendMessage(0);

TweaksSindre Sorhusbefore adoption698a1b8

line 55why, one step back
55 assert.equal(await subprocess.getOneMessage({filter}), 0);

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 56–57why, one step back
56
57 const promise = subprocess.sendMessage(1);

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

line 58why, one step back
58 subprocess.nodeChildProcess.emit('message', '.');

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 59–69why, one step back
59 await promise;
6061 const messages = Array.from({length: PARALLEL_COUNT}, (_, index) => index + 2);62 for (const message of messages) {63 // eslint-disable-next-line no-await-in-loop64 await subprocess.sendMessage(message);65 }6667 await subprocess.sendMessage(foobarString);6869 const {ipcOutput} = await subprocess;

TweaksSindre Sorhusbefore adoption698a1b8

lines 70–71why, one step back
70 if (!buffer) {
71 return;

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

line 72why, one step back
72 }

TweaksSindre Sorhusbefore adoption698a1b8

lines 73–75why, one step back
73
74 const expectedOutput = [0, '.', 1, ...messages];75 assert.deepEqual(ipcOutput, expectedOutput);

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 76–77why, one step back
76};
77

TweaksSindre Sorhusbefore adoption698a1b8

lines 78–83why, one step back
78test('Multiple serial subprocess.sendMessage() + subprocess.getOneMessage(), buffer false', () => testSendHoldParentSerial(subprocessGetOne, false, undefined));
79test('Multiple serial subprocess.sendMessage() + subprocess.getOneMessage(), buffer true', () => testSendHoldParentSerial(subprocessGetOne, true, undefined));80test('Multiple serial subprocess.sendMessage() + subprocess.getOneMessage(), buffer false, filter', () => testSendHoldParentSerial(subprocessGetOne, false, isAlwaysTrue));81test('Multiple serial subprocess.sendMessage() + subprocess.getOneMessage(), buffer true, filter', () => testSendHoldParentSerial(subprocessGetOne, true, isAlwaysTrue));82test('Multiple serial subprocess.sendMessage() + subprocess.getEachMessage(), buffer false', () => testSendHoldParentSerial(subprocessGetFirst, false, undefined));83test('Multiple serial subprocess.sendMessage() + subprocess.getEachMessage(), buffer true', () => testSendHoldParentSerial(subprocessGetFirst, true, undefined));

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

line 84why, one step back
84

TweaksSindre Sorhusbefore adoption698a1b8

line 85why, one step back
85const testSendHoldSubprocessSerial = async (filter, isGetEach) => {

Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10

line 86why, one step back
86 const {ipcOutput} = await execa('ipc-iterate-back-serial.js', [`${filter}`, `${isGetEach}`], {ipcInput: 0});

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

line 87why, one step back
87 const expectedOutput = [...Array.from({length: PARALLEL_COUNT + 2}, (_, index) => index), '.'];

TweaksSindre Sorhusbefore adoption698a1b8

line 88why, one step back
88 assert.deepEqual(ipcOutput, expectedOutput);

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 89–90why, one step back
89};
90

TweaksSindre Sorhusbefore adoption698a1b8

lines 91–93why, one step back
91test('Multiple serial exports.sendMessage() + exports.getOneMessage()', () => testSendHoldSubprocessSerial(false, false));
92test('Multiple serial exports.sendMessage() + exports.getOneMessage(), filter', () => testSendHoldSubprocessSerial(true, false));93test('Multiple serial exports.sendMessage() + exports.getEachMessage()', () => testSendHoldSubprocessSerial(false, true));