Skip to content
Myr

incoming.js

This file

Path

test/ipc/incoming.js

57 lines · 2.6 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} 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 testSeriesParent = async (buffer, filter) => {

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 12–15why, one step back
12 const subprocess = execa('ipc-send-many.js', [`${PARALLEL_COUNT}`], {ipc: true, buffer});
1314 for (let index = 0; index < PARALLEL_COUNT; index += 1) {15 // eslint-disable-next-line no-await-in-loop

TweaksSindre Sorhusbefore adoption698a1b8

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

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 17–20why, one step back
17 }
1819 const {ipcOutput} = await subprocess;20 if (buffer) {

TweaksSindre Sorhusbefore adoption698a1b8

line 21why, one step back
21 assert.deepEqual(ipcOutput, Array.from({length: PARALLEL_COUNT}, (_, index) => index));

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 22–24why, one step back
22 }
23};24

TweaksSindre Sorhusbefore adoption698a1b8

lines 25–28why, one step back
25test('subprocess.getOneMessage() can be called multiple times in a row, buffer false', () => testSeriesParent(false, undefined));
26test('subprocess.getOneMessage() can be called multiple times in a row, buffer true', () => testSeriesParent(true, undefined));27test('subprocess.getOneMessage() can be called multiple times in a row, buffer false, filter', () => testSeriesParent(false, isAlwaysTrue));28test('subprocess.getOneMessage() can be called multiple times in a row, buffer true, filter', () => testSeriesParent(true, isAlwaysTrue));

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

line 29why, one step back
29

TweaksSindre Sorhusbefore adoption698a1b8

line 30why, one step back
30const testSeriesSubprocess = async filter => {

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 31–36why, one step back
31 const subprocess = execa('ipc-print-many.js', [`${PARALLEL_COUNT}`, `${filter}`], {ipc: true});
32 const indexes = Array.from({length: PARALLEL_COUNT}, (_, index) => `${index}`);33 await Promise.all(indexes.map(index => subprocess.sendMessage(index)));3435 const {stdout} = await subprocess;36 const expectedOutput = indexes.join('\n');

TweaksSindre Sorhusbefore adoption698a1b8

line 37why, one step back
37 assert.equal(stdout, expectedOutput);

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 38–39why, one step back
38};
39

TweaksSindre Sorhusbefore adoption698a1b8

lines 40–41why, one step back
40test('exports.getOneMessage() can be called multiple times in a row', () => testSeriesSubprocess(false));
41test('exports.getOneMessage() can be called multiple times in a row, filter', () => testSeriesSubprocess(true));

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

line 42why, one step back
42

TweaksSindre Sorhusbefore adoption698a1b8

line 43why, one step back
43test('Can iterate multiple times over IPC messages in subprocess', async () => {

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 44–45why, one step back
44 const subprocess = execa('ipc-iterate-twice.js', {ipc: true});
45

TweaksSindre Sorhusbefore adoption698a1b8

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

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

line 47why, one step back
47 await subprocess.sendMessage('.');

TweaksSindre Sorhusbefore adoption698a1b8

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

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

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

TweaksSindre Sorhusbefore adoption698a1b8

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

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

line 51why, one step back
51 await subprocess.sendMessage('.');

TweaksSindre Sorhusbefore adoption698a1b8

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

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 53–55why, one step back
53 await subprocess.sendMessage(foobarString);
5455 const {ipcOutput} = await subprocess;

TweaksSindre Sorhusbefore adoption698a1b8

line 56why, one step back
56 assert.deepEqual(ipcOutput, [foobarString, '0.', foobarString, '1.']);

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

line 57why, one step back
57});