Skip to content
Myr

ipc.js

This file

Path

test/helpers/ipc.js

38 lines · 1.1 KiB · JavaScript

Last changed by

Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d

History of this file

Take it

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

line 1why, one step back
1import {getEachMessage} from '../../index.js';

Add tests for I/O errors during `sendMessage()` (#1095)ehmickybefore adoptionc6c66da

line 2why, one step back
2import {foobarString} from './input.js';

Add `exchangeMessage()` method (#1077)ehmickybefore adoption7a0a1c6

line 3why, one step back
3

Add `result.ipc`/`error.ipc` (#1067)ehmickybefore adoption3ab34de

lines 4–5why, one step back
4// @todo: replace with Array.fromAsync(subprocess.getEachMessage()) after dropping support for Node <22.0.0
5export const iterateAllMessages = async subprocess => {

Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d

line 6why, one step back
6 const messages = await Array.fromAsync(subprocess.getEachMessage());

Add `result.ipc`/`error.ipc` (#1067)ehmickybefore adoption3ab34de

lines 7–9why, one step back
7
8 return messages;9};

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 10–23why, one step back
10
11export const subprocessGetFirst = async subprocess => {12 const [firstMessage] = await iterateAllMessages(subprocess);13 return firstMessage;14};1516export const getFirst = async () => {17 // eslint-disable-next-line no-unreachable-loop18 for await (const message of getEachMessage()) {19 return message;20 }21};2223export const subprocessGetOne = (subprocess, options) => subprocess.getOneMessage(options);

Add `filter` option to `getOneMessage()` (#1076)ehmickybefore adoption571e052

line 24why, one step back
24

Update dev dependencies (#1257)Sindre Sorhusbefore adoption5944b2d

line 25why, one step back
25export const isAlwaysTrue = () => true;

Add tests for I/O errors during `sendMessage()` (#1095)ehmickybefore adoptionc6c66da

lines 26–31why, one step back
26
27// `process.send()` can fail due to I/O errors.28// However, I/O errors are seldom and hard to trigger predictably.29// So we mock them.30export const mockSendIoError = anyProcess => {31 const error = new Error(foobarString);

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

lines 32–33why, one step back
32 const target = anyProcess.nodeChildProcess ?? anyProcess;
33 target.send = () => {

Add tests for I/O errors during `sendMessage()` (#1095)ehmickybefore adoptionc6c66da

lines 34–38why, one step back
34 throw error;
35 };3637 return error;38};