incoming.js
This file
Path
test/ipc/incoming.js
57 lines · 2.6 KiB · JavaScript
Last changed by
TweaksSindre Sorhusbefore adoption698a1b8
History of this fileTake it
TweaksSindre Sorhusbefore adoption698a1b8
lines 1–2why, one step back1import assert from 'node:assert/strict';2import test from 'node:test';Debounce `message` events (#1087)ehmickybefore adoptione8bab97
lines 3–5why, one step back3import {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 back6import {isAlwaysTrue} from '../helpers/ipc.js';Debounce `message` events (#1087)ehmickybefore adoptione8bab97
lines 7–10why, one step back7import {PARALLEL_COUNT} from '../helpers/parallel.js';89setFixtureDirectory();10TweaksSindre Sorhusbefore adoption698a1b8
line 11why, one step back11const testSeriesParent = async (buffer, filter) => {Debounce `message` events (#1087)ehmickybefore adoptione8bab97
lines 12–15why, one step back12 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-loopTweaksSindre Sorhusbefore adoption698a1b8
line 16why, one step back16 assert.equal(await subprocess.getOneMessage({filter}), index);Debounce `message` events (#1087)ehmickybefore adoptione8bab97
lines 17–20why, one step back17 }1819 const {ipcOutput} = await subprocess;20 if (buffer) {TweaksSindre Sorhusbefore adoption698a1b8
line 21why, one step back21 assert.deepEqual(ipcOutput, Array.from({length: PARALLEL_COUNT}, (_, index) => index));Debounce `message` events (#1087)ehmickybefore adoptione8bab97
lines 22–24why, one step back22 }23};24TweaksSindre Sorhusbefore adoption698a1b8
lines 25–28why, one step back25test('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 back29TweaksSindre Sorhusbefore adoption698a1b8
line 30why, one step back30const testSeriesSubprocess = async filter => {Debounce `message` events (#1087)ehmickybefore adoptione8bab97
lines 31–36why, one step back31 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 back37 assert.equal(stdout, expectedOutput);Debounce `message` events (#1087)ehmickybefore adoptione8bab97
lines 38–39why, one step back38};39TweaksSindre Sorhusbefore adoption698a1b8
lines 40–41why, one step back40test('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 back42TweaksSindre Sorhusbefore adoption698a1b8
line 43why, one step back43test('Can iterate multiple times over IPC messages in subprocess', async () => {Debounce `message` events (#1087)ehmickybefore adoptione8bab97
lines 44–45why, one step back44 const subprocess = execa('ipc-iterate-twice.js', {ipc: true});45TweaksSindre Sorhusbefore adoption698a1b8
line 46why, one step back46 assert.equal(await subprocess.getOneMessage(), foobarString);Debounce `message` events (#1087)ehmickybefore adoptione8bab97
line 47why, one step back47 await subprocess.sendMessage('.');TweaksSindre Sorhusbefore adoption698a1b8
line 48why, one step back48 assert.equal(await subprocess.getOneMessage(), '0.');Debounce `message` events (#1087)ehmickybefore adoptione8bab97
line 49why, one step back49 await subprocess.sendMessage(foobarString);TweaksSindre Sorhusbefore adoption698a1b8
line 50why, one step back50 assert.equal(await subprocess.getOneMessage(), foobarString);Debounce `message` events (#1087)ehmickybefore adoptione8bab97
line 51why, one step back51 await subprocess.sendMessage('.');TweaksSindre Sorhusbefore adoption698a1b8
line 52why, one step back52 assert.equal(await subprocess.getOneMessage(), '1.');Debounce `message` events (#1087)ehmickybefore adoptione8bab97
lines 53–55why, one step back53 await subprocess.sendMessage(foobarString);5455 const {ipcOutput} = await subprocess;TweaksSindre Sorhusbefore adoption698a1b8
line 56why, one step back56 assert.deepEqual(ipcOutput, [foobarString, '0.', foobarString, '1.']);Debounce `message` events (#1087)ehmickybefore adoptione8bab97
line 57why, one step back57});