Skip to content
Myr

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

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

authored by ehmicky · committed by GitHub · parent d8bdaf0 · Browse files · 5 files+93 added−36 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+93 added−36 removed

  • tests:+55 added−0 removed
  • other:+38 added−36 removed

5 files+93 added−36 removed

modified:lib/ipc/methods.js+19 added-27 removed
modified:lib/ipc/send.js+19 added-9 removed
added:test/fixtures/ipc-send-io-error.js+7 added
modified:test/helpers/ipc.js+13 added
modified:test/ipc/send.js+35 added
1 unmodified line
2import {execa} from '../../index.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {foobarString} from '../helpers/input.js';5import {PARALLEL_COUNT} from '../helpers/parallel.js';6import {mockSendIoError} from '../helpers/ipc.js';78setFixtureDirectory();910test('Can exchange IPC messages', async t => {
98 unmodified lines
109test.serial('Can send messages while the subprocess is closing', async t => {110 const {message} = await findEpipeError(t);111 t.is(message, 'subprocess.sendMessage() cannot be used: the subprocess is disconnecting.');112});113114test('subprocess.sendMessage() handles I/O errors', async t => {115 const subprocess = execa('ipc-echo.js', {ipc: true});116 const error = mockSendIoError(subprocess);117 t.is(await t.throwsAsync(subprocess.sendMessage('.')), error);118119 const {exitCode, isTerminated, message, ipcOutput} = await t.throwsAsync(subprocess);120 t.is(exitCode, 1);121 t.false(isTerminated);122 t.true(message.includes('Error: getOneMessage() cannot be used: the parent process has already exited or disconnected'));123 t.deepEqual(ipcOutput, []);124});125126test('Does not hold message events on I/O errors', async t => {127 const subprocess = execa('ipc-echo.js', {ipc: true});128 const error = mockSendIoError(subprocess);129 const promise = subprocess.sendMessage('.');130 subprocess.emit('message', '.');131 t.is(await t.throwsAsync(promise), error);132133 const {exitCode, isTerminated, message, ipcOutput} = await t.throwsAsync(subprocess);134 t.is(exitCode, 1);135 t.false(isTerminated);136 t.true(message.includes('Error: getOneMessage() cannot be used: the parent process has already exited or disconnected'));137 t.deepEqual(ipcOutput, ['.']);138});139140test('exports.sendMessage() handles I/O errors', async t => {141 const {exitCode, isTerminated, message, ipcOutput} = await t.throwsAsync(execa('ipc-send-io-error.js', {ipc: true}));142 t.is(exitCode, 1);143 t.false(isTerminated);144 t.true(message.includes(`Error: ${foobarString}`));145 t.deepEqual(ipcOutput, []);146});