Skip to content
Myr

Add more IPC-related tests (#1061)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by ehmicky · committed by GitHub · parent ecc00ed · Browse files · 5 files+58 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+58 added−1 removed

  • tests:+56 added−0 removed
  • other:+2 added−1 removed

5 files+58 added−1 removed

modified:lib/ipc/validation.js+2 added-1 removed
added:test/fixtures/ipc-send-argv.js+6 added
added:test/fixtures/ipc-send-print.js+10 added
modified:test/ipc/get-each.js+9 added
modified:test/ipc/get-one.js+31 added
1import {once} from 'node:events';2import test from 'ava';3import {execa} from '../../index.js';4import {setFixtureDirectory} from '../helpers/fixtures-directory.js';5import {foobarString} from '../helpers/input.js';
15 unmodified lines
21 t.is(await subprocess.getOneMessage(), foobarString);22 await subprocess;23});2425test('Buffers initial message to current process', async t => {26 const subprocess = execa('ipc-send-print.js', {ipc: true});27 const [chunk] = await once(subprocess.stdout, 'data');28 t.is(chunk.toString(), '.');29 t.is(await subprocess.getOneMessage(), foobarString);30 await subprocess.sendMessage('.');31 await subprocess;32});3334const HIGH_CONCURRENCY_COUNT = 100;3536test.serial('Can retrieve initial IPC messages under heavy load', async t => {37 await Promise.all(38 Array.from({length: HIGH_CONCURRENCY_COUNT}, async (_, index) => {39 const subprocess = execa('ipc-send-argv.js', [`${index}`], {ipc: true});40 t.is(await subprocess.getOneMessage(), `${index}`);41 await subprocess;42 }),43 );44});4546test('subprocess.getOneMessage() can be called twice at the same time', async t => {47 const subprocess = execa('ipc-send.js', {ipc: true});48 t.deepEqual(49 await Promise.all([subprocess.getOneMessage(), subprocess.getOneMessage()]),50 [foobarString, foobarString],51 );52 await subprocess;53});5455test('Cleans up subprocess.getOneMessage() listeners', async t => {56 const subprocess = execa('ipc-send.js', {ipc: true});5758 t.is(subprocess.listenerCount('message'), 0);
29 unmodified lines