Add more IPC-related tests (#1083)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent 5cf6312 · Browse files · 4 files·+79 added−19 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+79 added−19 removed
- tests:+79 added−19 removed
Provenance
- Commit
c09bb18- Tree
2a59498- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
5cf6312
4 files changed+79 added−19 removed
added:test/fixtures/ipc-iterate-break.js+10 added
12345678910#!/usr/bin/env nodeimport {sendMessage, getEachMessage} from '../../index.js';import {foobarString} from '../helpers/input.js';
await sendMessage(foobarString);
// eslint-disable-next-line no-unreachable-loopfor await (const _ of getEachMessage()) { break;}added:test/fixtures/ipc-iterate-throw.js+10 added
12345678910#!/usr/bin/env nodeimport {sendMessage, getEachMessage} from '../../index.js';import {foobarString} from '../helpers/input.js';
await sendMessage(foobarString);
// eslint-disable-next-line no-unreachable-loopfor await (const message of getEachMessage()) { throw new Error(message);}added:test/fixtures/ipc-send-get.js+5 added
12345#!/usr/bin/env nodeimport {exchangeMessage} from '../../index.js';import {foobarString} from '../helpers/input.js';
await exchangeMessage(foobarString);modified:test/ipc/get-each.js+54 added-19 removed
50 unmodified lines51 const {ipcOutput} = await subprocess;52 t.deepEqual(ipcOutput, foobarArray);53 });54 55-test('break in subprocess.getEachMessage() disconnects', async t => {56- const subprocess = execa('ipc-iterate-send.js', {ipc: true});57-55+const loopAndBreak = async (t, subprocess) => {56 // eslint-disable-next-line no-unreachable-loop57 for await (const message of subprocess.getEachMessage()) {58 t.is(message, foobarString);59 break;60 }61+};62 63+test('Breaking in subprocess.getEachMessage() disconnects', async t => {64+ const subprocess = execa('ipc-iterate-send.js', {ipc: true});65+ await loopAndBreak(t, subprocess);66 const {ipcOutput} = await subprocess;67 t.deepEqual(ipcOutput, [foobarString]);68 });69 70+test('Breaking from subprocess.getEachMessage() awaits the subprocess', async t => {71+ const subprocess = execa('ipc-send-get.js', {ipc: true});72+73+ const {exitCode, isTerminated, message, ipcOutput} = await t.throwsAsync(loopAndBreak(t, subprocess));74+ t.is(exitCode, 1);75+ t.false(isTerminated);76+ t.true(message.includes('Error: exchangeMessage() could not complete'));77+ t.deepEqual(ipcOutput, [foobarString]);78+});79+80+test('Breaking from exports.getEachMessage() disconnects', async t => {81+ const subprocess = execa('ipc-iterate-break.js', {ipc: true});82+83+ t.is(await subprocess.getOneMessage(), foobarString);84+ const ipcError = await t.throwsAsync(subprocess.exchangeMessage(foobarString));85+ t.true(ipcError.message.includes('subprocess.exchangeMessage() could not complete'));86+87+ const {ipcOutput} = await subprocess;88+ t.deepEqual(ipcOutput, [foobarString]);89+});90+91 const iterateAndError = async (t, subprocess, cause) => {92 // eslint-disable-next-line no-unreachable-loop93 for await (const message of subprocess.getEachMessage()) {94 t.is(message, foobarString);95 throw cause;96 }97 };98 76-test('Exceptions in subprocess.getEachMessage() disconnect', async t => {99+test('Throwing from subprocess.getEachMessage() disconnects', async t => {100 const subprocess = execa('ipc-iterate-send.js', {ipc: true});101 102 const cause = new Error(foobarString);103 t.is(await t.throwsAsync(iterateAndError(t, subprocess, cause)), cause);1 unmodified line105 const {ipcOutput} = await subprocess;106 t.deepEqual(ipcOutput, [foobarString]);107 });108 109+test('Throwing from subprocess.getEachMessage() awaits the subprocess', async t => {110+ const subprocess = execa('ipc-send-get.js', {ipc: true});111+112+ const cause = new Error(foobarString);113+ t.is(await t.throwsAsync(iterateAndError(t, subprocess, cause)), cause);114+115+ const {exitCode, isTerminated, message, ipcOutput} = await t.throwsAsync(subprocess);116+ t.is(exitCode, 1);117+ t.false(isTerminated);118+ t.true(message.includes('Error: exchangeMessage() could not complete'));119+ t.deepEqual(ipcOutput, [foobarString]);120+});121+122+test('Throwing from exports.getEachMessage() disconnects', async t => {123+ const subprocess = execa('ipc-iterate-throw.js', {ipc: true});124+125+ t.is(await subprocess.getOneMessage(), foobarString);126+ const ipcError = await t.throwsAsync(subprocess.exchangeMessage(foobarString));127+ t.true(ipcError.message.includes('subprocess.exchangeMessage() could not complete'));128+129+ const {exitCode, isTerminated, message, ipcOutput} = await t.throwsAsync(subprocess);130+ t.is(exitCode, 1);131+ t.false(isTerminated);132+ t.true(message.includes(`Error: ${foobarString}`));133+ t.deepEqual(ipcOutput, [foobarString]);134+});135+136 test.serial('Can send many messages at once with exports.getEachMessage()', async t => {137 const subprocess = execa('ipc-iterate.js', {ipc: true});138 await Promise.all(Array.from({length: PARALLEL_COUNT}, (_, index) => subprocess.sendMessage(index)));139 await subprocess.sendMessage(foobarString);53 unmodified lines193 194 test('"error" event interrupts subprocess.getEachMessage(), buffer false', testParentError, false);195 test('error" event interrupts subprocess.getEachMessage(), buffer true', testParentError, true);196 147-const loopAndBreak = async (t, subprocess) => {148- // eslint-disable-next-line no-unreachable-loop149- for await (const message of subprocess.getEachMessage()) {150- t.is(message, foobarString);151- break;152- }153-};154-155-test('Breaking from subprocess.getEachMessage() awaits the subprocess', async t => {156- const subprocess = execa('ipc-send-fail.js', {ipc: true});157- const {exitCode, ipcOutput} = await t.throwsAsync(loopAndBreak(t, subprocess));158- t.is(exitCode, 1);159- t.deepEqual(ipcOutput, [foobarString]);160-});161-197 const testCleanupListeners = async (t, buffer) => {198 const subprocess = execa('ipc-send.js', {ipc: true, buffer});199 const bufferCount = buffer ? 1 : 0;200 14 unmodified lines