Skip to content
Myr

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

4 files+79 added−19 removed

added:test/fixtures/ipc-iterate-break.js+10 added
added:test/fixtures/ipc-iterate-throw.js+10 added
added:test/fixtures/ipc-send-get.js+5 added
modified:test/ipc/get-each.js+54 added-19 removed
50 unmodified lines
51 const {ipcOutput} = await subprocess;52 t.deepEqual(ipcOutput, foobarArray);53});5455test('break in subprocess.getEachMessage() disconnects', async t => {56 const subprocess = execa('ipc-iterate-send.js', {ipc: true});5755const 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};6263test('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});6970test('Breaking from subprocess.getEachMessage() awaits the subprocess', async t => {71 const subprocess = execa('ipc-send-get.js', {ipc: true});7273 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});7980test('Breaking from exports.getEachMessage() disconnects', async t => {81 const subprocess = execa('ipc-iterate-break.js', {ipc: true});8283 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'));8687 const {ipcOutput} = await subprocess;88 t.deepEqual(ipcOutput, [foobarString]);89});9091const 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};9876test('Exceptions in subprocess.getEachMessage() disconnect', async t => {99test('Throwing from subprocess.getEachMessage() disconnects', async t => {100 const subprocess = execa('ipc-iterate-send.js', {ipc: true});101102 const cause = new Error(foobarString);103 t.is(await t.throwsAsync(iterateAndError(t, subprocess, cause)), cause);
1 unmodified line
105 const {ipcOutput} = await subprocess;106 t.deepEqual(ipcOutput, [foobarString]);107});108109test('Throwing from subprocess.getEachMessage() awaits the subprocess', async t => {110 const subprocess = execa('ipc-send-get.js', {ipc: true});111112 const cause = new Error(foobarString);113 t.is(await t.throwsAsync(iterateAndError(t, subprocess, cause)), cause);114115 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});121122test('Throwing from exports.getEachMessage() disconnects', async t => {123 const subprocess = execa('ipc-iterate-throw.js', {ipc: true});124125 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'));128129 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});135136test.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 lines
193194test('"error" event interrupts subprocess.getEachMessage(), buffer false', testParentError, false);195test('error" event interrupts subprocess.getEachMessage(), buffer true', testParentError, true);196147const 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};154155test('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});161197const testCleanupListeners = async (t, buffer) => {198 const subprocess = execa('ipc-send.js', {ipc: true, buffer});199 const bufferCount = buffer ? 1 : 0;200
14 unmodified lines