Skip to content
Myr

Rename `result.ipc` to `result.ipcOutput` (#1075)

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

authored by ehmicky · committed by GitHub · parent 587b490 · Browse files · 26 files+159 added−159 removed
This commit

State

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

Diff stats

26 files+159 added−159 removed

  • tests:+75 added−75 removed
  • other:+84 added−84 removed

26 files+159 added−159 removed

modified:docs/api.md+1 added-1 removed
465 unmodified lines
466Items are arrays when their corresponding `stdio` option is a [transform in object mode](transform.md#object-mode).467468[More info.](output.md#additional-file-descriptors)469470### result.ipc470### result.ipcOutput471472_Type_: [`Message[]`](ipc.md#message-type)473474All the messages [sent by the subprocess](#sendmessagemessage) to the current process.
632 unmodified lines
modified:docs/execution.md+1 added-1 removed
modified:docs/ipc.md+5 added-5 removed
67 unmodified lines
68```6970## Retrieve all messages7172The [`result.ipc`](api.md#resultipc) array contains all the messages sent by the subprocess. In many situations, this is simpler than using [`subprocess.getOneMessage()`](api.md#subprocessgetonemessage) and [`subprocess.getEachMessage()`](api.md#subprocessgeteachmessage).72The [`result.ipcOutput`](api.md#resultipcoutput) array contains all the messages sent by the subprocess. In many situations, this is simpler than using [`subprocess.getOneMessage()`](api.md#subprocessgetonemessage) and [`subprocess.getEachMessage()`](api.md#subprocessgeteachmessage).7374```js75// main.js76import {execaNode} from 'execa';7778const {ipc} = await execaNode`build.js`;79console.log(ipc[0]); // {kind: 'start', timestamp: date}80console.log(ipc[1]); // {kind: 'stop', timestamp: date}78const {ipcOutput} = await execaNode`build.js`;79console.log(ipcOutput[0]); // {kind: 'start', timestamp: date}80console.log(ipcOutput[1]); // {kind: 'stop', timestamp: date}81```8283```js84// build.js
39 unmodified lines
124## Debugging125126When the [`verbose`](api.md#optionsverbose) option is `'full'`, the IPC messages sent by the subprocess to the current process are [printed on the console](debugging.md#full-mode).127128Also, when the subprocess [failed](errors.md#subprocess-failure), [`error.ipc`](api.md) contains all the messages sent by the subprocess. Those are also shown at the end of the [error message](errors.md#error-message).128Also, when the subprocess [failed](errors.md#subprocess-failure), [`error.ipcOutput`](api.md) contains all the messages sent by the subprocess. Those are also shown at the end of the [error message](errors.md#error-message).129130<hr>131132[**Next**: 🐛 Debugging](debugging.md)\
2 unmodified lines
modified:docs/output.md+7 added-7 removed
55 unmodified lines
56```5758## Any output type5960If the subprocess uses Node.js, [IPC](ipc.md) can be used to return [almost any type](ipc.md#message-type) from the subprocess. The [`result.ipc`](api.md#resultipc) array contains all the messages sent by the subprocess.60If the subprocess uses Node.js, [IPC](ipc.md) can be used to return [almost any type](ipc.md#message-type) from the subprocess. The [`result.ipcOutput`](api.md#resultipcoutput) array contains all the messages sent by the subprocess.6162```js63// main.js64import {execaNode} from 'execa';6566const {ipc} = await execaNode`build.js`;67console.log(ipc[0]); // {kind: 'start', timestamp: date}68console.log(ipc[1]); // {kind: 'stop', timestamp: date}66const {ipcOutput} = await execaNode`build.js`;67console.log(ipcOutput[0]); // {kind: 'start', timestamp: date}68console.log(ipcOutput[1]); // {kind: 'stop', timestamp: date}69```7071```js72// build.js
88 unmodified lines
161## Big output162163To prevent high memory consumption, a maximum output size can be set using the [`maxBuffer`](api.md#optionsmaxbuffer) option. It defaults to 100MB.164165When this threshold is hit, the subprocess fails and [`error.isMaxBuffer`](api.md#errorismaxbuffer) becomes `true`. The truncated output is still available using [`error.stdout`](api.md#resultstdout), [`error.stderr`](api.md#resultstderr) and [`error.ipc`](api.md#resultipc).165When this threshold is hit, the subprocess fails and [`error.isMaxBuffer`](api.md#errorismaxbuffer) becomes `true`. The truncated output is still available using [`error.stdout`](api.md#resultstdout), [`error.stderr`](api.md#resultstderr) and [`error.ipcOutput`](api.md#resultipcoutput).166167This is measured:168- By default: in [characters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length).169- If the [`encoding`](binary.md#encoding) option is `'buffer'`: in bytes.170- If the [`lines`](lines.md#simple-splitting) option is `true`: in lines.171- If a [transform in object mode](transform.md#object-mode) is used: in objects.172- With [`error.ipc`](ipc.md#retrieve-all-messages): in messages.172- With [`error.ipcOutput`](ipc.md#retrieve-all-messages): in messages.173174```js175try {176 await execa({maxBuffer: 1_000_000})`npm run build`;
9 unmodified lines
186```187188## Low memory189190When the [`buffer`](api.md#optionsbuffer) option is `false`, [`result.stdout`](api.md#resultstdout), [`result.stderr`](api.md#resultstderr), [`result.all`](api.md#resultall), [`result.stdio[*]`](api.md#resultstdio) and [`result.ipc`](api.md#resultipc) properties are empty.190When the [`buffer`](api.md#optionsbuffer) option is `false`, [`result.stdout`](api.md#resultstdout), [`result.stderr`](api.md#resultstderr), [`result.all`](api.md#resultall), [`result.stdio[*]`](api.md#resultstdio) and [`result.ipcOutput`](api.md#resultipcoutput) properties are empty.191192This prevents high memory consumption when the output is big. However, the output must be either ignored, [redirected](#file-output), [streamed](streams.md) or [listened to](ipc.md#listening-to-messages). If streamed, this should be done right away to avoid missing any data.193194<hr>
4 unmodified lines
modified:lib/io/max-buffer.js+3 added-3 removed
33 unmodified lines
3435 return 'characters';36};3738// Check the `maxBuffer` option with `result.ipc`39export const checkIpcMaxBuffer = (subprocess, ipcMessages, maxBuffer) => {40 if (ipcMessages.length !== maxBuffer) {38// Check the `maxBuffer` option with `result.ipcOutput`39export const checkIpcMaxBuffer = (subprocess, ipcOutput, maxBuffer) => {40 if (ipcOutput.length !== maxBuffer) {41 return;42 }4344 disconnect(subprocess);
45 unmodified lines
modified:lib/ipc/buffer-messages.js+9 added-9 removed
modified:lib/methods/main-async.js+5 added-5 removed
135 unmodified lines
136 errorInfo,137 [exitCode, signal],138 stdioResults,139 allResult,140 ipcMessages,140 ipcOutput,141 ] = await waitForSubprocessResult({142 subprocess,143 options,144 context,
13 unmodified lines
158 exitCode,159 signal,160 stdio,161 all,162 ipcMessages,162 ipcOutput,163 context,164 options,165 command,166 escapedCommand,
1 unmodified line
168 });169 return handleResult(result, verboseInfo, options);170};171172const getAsyncResult = ({errorInfo, exitCode, signal, stdio, all, ipcMessages, context, options, command, escapedCommand, startTime}) => 'error' in errorInfo172const getAsyncResult = ({errorInfo, exitCode, signal, stdio, all, ipcOutput, context, options, command, escapedCommand, startTime}) => 'error' in errorInfo173 ? makeError({174 error: errorInfo.error,175 command,176 escapedCommand,
3 unmodified lines
180 exitCode,181 signal,182 stdio,183 all,184 ipcMessages,184 ipcOutput,185 options,186 startTime,187 isSync: false,188 })
1 unmodified line
190 command,191 escapedCommand,192 stdio,193 all,194 ipcMessages,194 ipcOutput,195 options,196 startTime,197 });
modified:lib/methods/main-sync.js+2 added-2 removed
143 unmodified lines
144 command,145 escapedCommand,146 stdio,147 all,148 ipcMessages: [],148 ipcOutput: [],149 options,150 startTime,151 })152 : makeError({
6 unmodified lines
159 exitCode,160 signal,161 stdio,162 all,163 ipcMessages: [],163 ipcOutput: [],164 options,165 startTime,166 isSync: true,167 });
modified:lib/resolve/wait-subprocess.js+5 added-5 removed
2 unmodified lines
3import {throwOnTimeout} from '../terminate/timeout.js';4import {isStandardStream} from '../utils/standard-stream.js';5import {TRANSFORM_TYPES} from '../stdio/type.js';6import {getBufferedData} from '../io/contents.js';7import {waitForIpcMessages} from '../ipc/buffer-messages.js';7import {waitForIpcOutput} from '../ipc/buffer-messages.js';8import {sendIpcInput} from '../ipc/ipc-input.js';9import {waitForAllStream} from './all-async.js';10import {waitForStdioStreams} from './stdio.js';11import {waitForExit, waitForSuccessfulExit} from './exit-async.js';
47 unmodified lines
59 stripFinalNewline,60 verboseInfo,61 streamInfo,62 });63 const ipcMessages = [];63 const ipcOutput = [];64 const originalPromises = waitForOriginalStreams(originalStreams, subprocess, streamInfo);65 const customStreamsEndPromises = waitForCustomStreamsEnd(fileDescriptors, streamInfo);6667 try {
2 unmodified lines
70 {},71 waitForSuccessfulExit(exitPromise),72 Promise.all(stdioPromises),73 allPromise,74 waitForIpcMessages({74 waitForIpcOutput({75 subprocess,76 buffer,77 maxBuffer,78 ipc,79 ipcMessages,79 ipcOutput,80 verboseInfo,81 }),82 sendIpcInput(subprocess, ipcInput),83 ...originalPromises,
8 unmodified lines
92 {error},93 exitPromise,94 Promise.all(stdioPromises.map(stdioPromise => getBufferedData(stdioPromise))),95 getBufferedData(allPromise),96 ipcMessages,96 ipcOutput,97 Promise.allSettled(originalPromises),98 Promise.allSettled(customStreamsEndPromises),99 ]);100 }
24 unmodified lines
modified:lib/return/message.js+2 added-2 removed
8 unmodified lines
9// Computes `error.message`, `error.shortMessage` and `error.originalMessage`10export const createMessages = ({11 stdio,12 all,13 ipcMessages,13 ipcOutput,14 originalError,15 signal,16 signalDescription,17 exitCode,
25 unmodified lines
43 const message = [44 shortMessage,45 ...messageStdio,46 ...stdio.slice(3),47 ipcMessages.map(ipcMessage => serializeIpcMessage(ipcMessage)).join('\n'),47 ipcOutput.map(ipcMessage => serializeIpcMessage(ipcMessage)).join('\n'),48 ]49 .map(messagePart => escapeLines(stripFinalNewline(serializeMessagePart(messagePart))))50 .filter(Boolean)51 .join('\n\n');
62 unmodified lines
modified:lib/return/result.js+8 added-8 removed
7 unmodified lines
8 command,9 escapedCommand,10 stdio,11 all,12 ipcMessages,12 ipcOutput,13 options: {cwd},14 startTime,15}) => omitUndefinedProperties({16 command,
9 unmodified lines
26 stdout: stdio[1],27 stderr: stdio[2],28 all,29 stdio,30 ipc: ipcMessages,30 ipcOutput,31 pipedFrom: [],32});3334// Object returned on subprocess failure before spawning
13 unmodified lines
48 timedOut: false,49 isCanceled: false,50 isMaxBuffer: false,51 stdio: Array.from({length: fileDescriptors.length}),52 ipcMessages: [],52 ipcOutput: [],53 options,54 isSync,55});56
9 unmodified lines
66 exitCode: rawExitCode,67 signal: rawSignal,68 stdio,69 all,70 ipcMessages,70 ipcOutput,71 options: {timeoutDuration, timeout = timeoutDuration, cwd, maxBuffer},72 isSync,73}) => {74 const {exitCode, signal, signalDescription} = normalizeExitPayload(rawExitCode, rawSignal);75 const {originalMessage, shortMessage, message} = createMessages({76 stdio,77 all,78 ipcMessages,78 ipcOutput,79 originalError,80 signal,81 signalDescription,82 exitCode,
18 unmodified lines
101 signal,102 signalDescription,103 stdio,104 all,105 ipcMessages,105 ipcOutput,106 cwd,107 originalMessage,108 shortMessage,109 }));
12 unmodified lines
122 signal,123 signalDescription,124 stdio,125 all,126 ipcMessages,126 ipcOutput,127 cwd,128 originalMessage,129 shortMessage,130}) => omitUndefinedProperties({
15 unmodified lines
146 stdout: stdio[1],147 stderr: stdio[2],148 all,149 stdio,150 ipc: ipcMessages,150 ipcOutput,151 pipedFrom: [],152});153154const omitUndefinedProperties = result => Object.fromEntries(Object.entries(result).filter(([, value]) => value !== undefined));
9 unmodified lines
modified:lib/verbose/ipc.js+1 added-1 removed
1 unmodified line
23// When `verbose` is `'full'`, print IPC messages from the subprocess4export const shouldLogIpc = ({verbose}) => verbose.at(-1) === 'full';56export const logIpcMessage = (message, {verboseId}) => {6export const logIpcOutput = (message, {verboseId}) => {7 verboseLog(serializeLogMessage(message), verboseId, 'ipc');8};
modified:test/io/max-buffer.js+6 added-6 removed
265 unmodified lines
266 t.true(failed);267 t.false(isMaxBuffer);268});269270test('maxBuffer works with result.ipc', async t => {270test('maxBuffer works with result.ipcOutput', async t => {271 const {272 isMaxBuffer,273 shortMessage,274 message,275 stderr,276 ipc,276 ipcOutput,277 } = await t.throwsAsync(execa('ipc-send-twice-wait.js', {ipc: true, maxBuffer: {ipc: 1}}));278 t.true(isMaxBuffer);279 t.is(shortMessage, 'Command\'s IPC output was larger than 1 messages: ipc-send-twice-wait.js\nmaxBuffer exceeded');280 t.true(message.endsWith(`\n\n${foobarString}`));281 t.true(stderr.includes('Error: getOneMessage() could not complete'));282 t.deepEqual(ipc, [foobarString]);282 t.deepEqual(ipcOutput, [foobarString]);283});284285test('maxBuffer is ignored with result.ipc if buffer is false', async t => {285test('maxBuffer is ignored with result.ipcOutput if buffer is false', async t => {286 const subprocess = execa('ipc-send-twice-wait.js', {ipc: true, maxBuffer: {ipc: 1}, buffer: false});287 t.is(await subprocess.getOneMessage(), foobarString);288 t.is(await subprocess.getOneMessage(), foobarString);289 await subprocess.sendMessage(foobarString);290291 const {ipc} = await subprocess;292 t.deepEqual(ipc, []);291 const {ipcOutput} = await subprocess;292 t.deepEqual(ipcOutput, []);293});
modified:test/ipc/buffer-messages.js+28 added-28 removed
4 unmodified lines
56setFixtureDirectory();78const testResultIpc = async (t, options) => {9 const {ipc} = await execa('ipc-send-twice.js', {...options, ipc: true});10 t.deepEqual(ipc, foobarArray);9 const {ipcOutput} = await execa('ipc-send-twice.js', {...options, ipc: true});10 t.deepEqual(ipcOutput, foobarArray);11};1213test('Sets result.ipc', testResultIpc, {});14test('Sets result.ipc, fd-specific buffer', testResultIpc, {buffer: {stdout: false}});13test('Sets result.ipcOutput', testResultIpc, {});14test('Sets result.ipcOutput, fd-specific buffer', testResultIpc, {buffer: {stdout: false}});1516const testResultNoBuffer = async (t, options) => {17 const {ipc} = await execa('ipc-send.js', {...options, ipc: true});18 t.deepEqual(ipc, []);17 const {ipcOutput} = await execa('ipc-send.js', {...options, ipc: true});18 t.deepEqual(ipcOutput, []);19};2021test('Sets empty result.ipc if buffer is false', testResultNoBuffer, {buffer: false});22test('Sets empty result.ipc if buffer is false, fd-specific buffer', testResultNoBuffer, {buffer: {ipc: false}});21test('Sets empty result.ipcOutput if buffer is false', testResultNoBuffer, {buffer: false});22test('Sets empty result.ipcOutput if buffer is false, fd-specific buffer', testResultNoBuffer, {buffer: {ipc: false}});2324test('Sets empty result.ipc if ipc is false', async t => {25 const {ipc} = await execa('empty.js');26 t.deepEqual(ipc, []);24test('Sets empty result.ipcOutput if ipc is false', async t => {25 const {ipcOutput} = await execa('empty.js');26 t.deepEqual(ipcOutput, []);27});2829test('Sets empty result.ipc, sync', t => {30 const {ipc} = execaSync('empty.js');31 t.deepEqual(ipc, []);29test('Sets empty result.ipcOutput, sync', t => {30 const {ipcOutput} = execaSync('empty.js');31 t.deepEqual(ipcOutput, []);32});3334const testErrorIpc = async (t, options) => {35 const {ipc} = await t.throwsAsync(execa('ipc-send-fail.js', {...options, ipc: true}));36 t.deepEqual(ipc, [foobarString]);35 const {ipcOutput} = await t.throwsAsync(execa('ipc-send-fail.js', {...options, ipc: true}));36 t.deepEqual(ipcOutput, [foobarString]);37};3839test('Sets error.ipc', testErrorIpc, {});40test('Sets error.ipc, fd-specific buffer', testErrorIpc, {buffer: {stdout: false}});39test('Sets error.ipcOutput', testErrorIpc, {});40test('Sets error.ipcOutput, fd-specific buffer', testErrorIpc, {buffer: {stdout: false}});4142const testErrorNoBuffer = async (t, options) => {43 const {ipc} = await t.throwsAsync(execa('ipc-send-fail.js', {...options, ipc: true}));44 t.deepEqual(ipc, []);43 const {ipcOutput} = await t.throwsAsync(execa('ipc-send-fail.js', {...options, ipc: true}));44 t.deepEqual(ipcOutput, []);45};4647test('Sets empty error.ipc if buffer is false', testErrorNoBuffer, {buffer: false});48test('Sets empty error.ipc if buffer is false, fd-specific buffer', testErrorNoBuffer, {buffer: {ipc: false}});47test('Sets empty error.ipcOutput if buffer is false', testErrorNoBuffer, {buffer: false});48test('Sets empty error.ipcOutput if buffer is false, fd-specific buffer', testErrorNoBuffer, {buffer: {ipc: false}});4950test('Sets empty error.ipc if ipc is false', async t => {51 const {ipc} = await t.throwsAsync(execa('fail.js'));52 t.deepEqual(ipc, []);50test('Sets empty error.ipcOutput if ipc is false', async t => {51 const {ipcOutput} = await t.throwsAsync(execa('fail.js'));52 t.deepEqual(ipcOutput, []);53});5455test('Sets empty error.ipc, sync', t => {56 const {ipc} = t.throws(() => execaSync('fail.js'));57 t.deepEqual(ipc, []);55test('Sets empty error.ipcOutput, sync', t => {56 const {ipcOutput} = t.throws(() => execaSync('fail.js'));57 t.deepEqual(ipcOutput, []);58});
modified:test/ipc/get-each.js+16 added-16 removed
11 unmodified lines
12 for await (const message of subprocess.getEachMessage()) {13 t.is(message, foobarArray[count++]);14 }1516 const {ipc} = await subprocess;17 t.deepEqual(ipc, foobarArray);16 const {ipcOutput} = await subprocess;17 t.deepEqual(ipcOutput, foobarArray);18});1920test('Can iterate over IPC messages in subprocess', async t => {21 const subprocess = execa('ipc-iterate.js', {ipc: true});
1 unmodified line
23 await subprocess.sendMessage('.');24 await subprocess.sendMessage('.');25 await subprocess.sendMessage(foobarString);2627 const {ipc} = await subprocess;28 t.deepEqual(ipc, ['.', '.']);27 const {ipcOutput} = await subprocess;28 t.deepEqual(ipcOutput, ['.', '.']);29});3031test('Can iterate multiple times over IPC messages in subprocess', async t => {32 const subprocess = execa('ipc-iterate-twice.js', {ipc: true});
6 unmodified lines
39 t.is(await subprocess.getOneMessage(), '.');40 await subprocess.sendMessage(foobarString);41 t.is(await subprocess.getOneMessage(), foobarString);4243 const {ipc} = await subprocess;44 t.deepEqual(ipc, ['.', foobarString, '.', foobarString]);43 const {ipcOutput} = await subprocess;44 t.deepEqual(ipcOutput, ['.', foobarString, '.', foobarString]);45});4647test('subprocess.getEachMessage() can be called twice at the same time', async t => {48 const subprocess = execa('ipc-send-twice.js', {ipc: true});
1 unmodified line
50 await Promise.all([iterateAllMessages(subprocess), iterateAllMessages(subprocess)]),51 [foobarArray, foobarArray],52 );5354 const {ipc} = await subprocess;55 t.deepEqual(ipc, foobarArray);54 const {ipcOutput} = await subprocess;55 t.deepEqual(ipcOutput, foobarArray);56});5758const HIGH_CONCURRENCY_COUNT = 100;59
1 unmodified line
61 const subprocess = execa('ipc-iterate.js', {ipc: true});62 await Promise.all(Array.from({length: HIGH_CONCURRENCY_COUNT}, (_, index) => subprocess.sendMessage(index)));63 await subprocess.sendMessage(foobarString);6465 const {ipc} = await subprocess;66 t.deepEqual(ipc, Array.from({length: HIGH_CONCURRENCY_COUNT}, (_, index) => index));65 const {ipcOutput} = await subprocess;66 t.deepEqual(ipcOutput, Array.from({length: HIGH_CONCURRENCY_COUNT}, (_, index) => index));67});6869test('Disconnecting in the current process stops exports.getEachMessage()', async t => {70 const subprocess = execa('ipc-iterate-print.js', {ipc: true});
10 unmodified lines
81 for await (const message of subprocess.getEachMessage()) {82 t.is(message, foobarString);83 }8485 const {ipc} = await subprocess;86 t.deepEqual(ipc, [foobarString]);85 const {ipcOutput} = await subprocess;86 t.deepEqual(ipcOutput, [foobarString]);87});8889test('Exiting the subprocess stops subprocess.getEachMessage()', async t => {90 const subprocess = execa('ipc-send.js', {ipc: true});91 for await (const message of subprocess.getEachMessage()) {92 t.is(message, foobarString);93 }9495 const {ipc} = await subprocess;96 t.deepEqual(ipc, [foobarString]);95 const {ipcOutput} = await subprocess;96 t.deepEqual(ipcOutput, [foobarString]);97});9899const loopAndBreak = async (t, subprocess) => {100 // eslint-disable-next-line no-unreachable-loop
4 unmodified lines
105};106107test('Breaking from subprocess.getEachMessage() awaits the subprocess', async t => {108 const subprocess = execa('ipc-send-fail.js', {ipc: true});109 const {exitCode, ipc} = await t.throwsAsync(loopAndBreak(t, subprocess));109 const {exitCode, ipcOutput} = await t.throwsAsync(loopAndBreak(t, subprocess));110 t.is(exitCode, 1);111 t.deepEqual(ipc, [foobarString]);111 t.deepEqual(ipcOutput, [foobarString]);112});113114const testCleanupListeners = async (t, buffer) => {115 const subprocess = execa('ipc-send.js', {ipc: true, buffer});
16 unmodified lines
modified:test/ipc/get-one.js+6 added-6 removed
45 unmodified lines
46 const [chunk] = await once(subprocess.stdout, 'data');47 t.is(chunk.toString(), '.');48 t.is(await Promise.race([setTimeout(1e3), subprocess.getOneMessage()]), undefined);49 await subprocess.sendMessage('.');50 const {ipc} = await subprocess;51 t.deepEqual(ipc, [foobarString]);50 const {ipcOutput} = await subprocess;51 t.deepEqual(ipcOutput, [foobarString]);52});5354const HIGH_CONCURRENCY_COUNT = 100;55
9 unmodified lines
6566test.serial('Can retrieve initial IPC messages under heavy load, buffer true', async t => {67 await Promise.all(68 Array.from({length: HIGH_CONCURRENCY_COUNT}, async (_, index) => {69 const {ipc} = await execa('ipc-send-argv.js', [`${index}`], {ipc: true});70 t.deepEqual(ipc, [`${index}`]);69 const {ipcOutput} = await execa('ipc-send-argv.js', [`${index}`], {ipc: true});70 t.deepEqual(ipcOutput, [`${index}`]);71 }),72 );73});74
32 unmodified lines
107108test('Cleans up subprocess.getOneMessage() listeners, buffer false', testCleanupListeners, false);109test('Cleans up subprocess.getOneMessage() listeners, buffer true', testCleanupListeners, true);110111test('"error" event interrupts result.ipc', async t => {111test('"error" event interrupts result.ipcOutput', async t => {112 const subprocess = execa('ipc-echo-twice.js', {ipcInput: foobarString});113 t.is(await subprocess.getOneMessage(), foobarString);114115 const cause = new Error(foobarString);116 subprocess.emit('error', cause);117 const error = await t.throwsAsync(subprocess);118 t.is(error.cause, cause);119 t.deepEqual(error.ipc, [foobarString]);119 t.deepEqual(error.ipcOutput, [foobarString]);120});121122const testParentDisconnect = async (t, buffer) => {123 const subprocess = execa('ipc-echo-twice.js', {ipc: true, buffer});
70 unmodified lines
modified:test/ipc/ipc-input.js+2 added-2 removed
4 unmodified lines
56setFixtureDirectory();78const testSuccess = async (t, options) => {9 const {ipc} = await execa('ipc-echo.js', {ipcInput: foobarString, ...options});10 t.deepEqual(ipc, [foobarString]);9 const {ipcOutput} = await execa('ipc-echo.js', {ipcInput: foobarString, ...options});10 t.deepEqual(ipcOutput, [foobarString]);11};1213test('Sends a message with the "ipcInput" option, ipc undefined', testSuccess, {});14test('Sends a message with the "ipcInput" option, ipc true', testSuccess, {ipc: true});
32 unmodified lines
modified:test/ipc/send.js+2 added-2 removed
37 unmodified lines
38test('Handles backpressure', async t => {39 const subprocess = execa('ipc-iterate.js', {ipc: true});40 await subprocess.sendMessage(BIG_PAYLOAD_SIZE);41 t.true(subprocess.send(foobarString));42 const {ipc} = await subprocess;43 t.deepEqual(ipc, [BIG_PAYLOAD_SIZE]);42 const {ipcOutput} = await subprocess;43 t.deepEqual(ipcOutput, [BIG_PAYLOAD_SIZE]);44});4546test('Disconnects IPC on exports.sendMessage() error', async t => {47 const subprocess = execa('ipc-echo-twice.js', {ipc: true});
37 unmodified lines
modified:test/return/message.js+11 added-11 removed
93 unmodified lines
94 const {originalMessage} = await t.throwsAsync(execa('noop.js', {uid: true}));95 t.is(originalMessage, 'The "options.uid" property must be int32. Received type boolean (true)');96});9798const testIpcMessage = async (t, doubles, ipcInput, returnedMessage) => {98const testIpcOutput = async (t, doubles, ipcInput, returnedMessage) => {99 const fixtureName = doubles ? 'ipc-echo-twice-fail.js' : 'ipc-echo-fail.js';100 const {exitCode, message, ipc} = await t.throwsAsync(execa(fixtureName, {ipcInput}));100 const {exitCode, message, ipcOutput} = await t.throwsAsync(execa(fixtureName, {ipcInput}));101 t.is(exitCode, 1);102 t.true(message.endsWith(`\n\n${doubles ? `${returnedMessage}\n${returnedMessage}` : returnedMessage}`));103 t.deepEqual(ipc, doubles ? [ipcInput, ipcInput] : [ipcInput]);103 t.deepEqual(ipcOutput, doubles ? [ipcInput, ipcInput] : [ipcInput]);104};105106test('error.message contains IPC messages, single string', testIpcMessage, false, foobarString, foobarString);107test('error.message contains IPC messages, two strings', testIpcMessage, true, foobarString, foobarString);108test('error.message contains IPC messages, single object', testIpcMessage, false, foobarObject, foobarObjectInspect);109test('error.message contains IPC messages, two objects', testIpcMessage, true, foobarObject, foobarObjectInspect);110test('error.message contains IPC messages, multiline string', testIpcMessage, false, `${foobarString}\n${foobarString}`, `${foobarString}\n${foobarString}`);111test('error.message contains IPC messages, control characters', testIpcMessage, false, '\0', '\\u0000');106test('error.message contains IPC messages, single string', testIpcOutput, false, foobarString, foobarString);107test('error.message contains IPC messages, two strings', testIpcOutput, true, foobarString, foobarString);108test('error.message contains IPC messages, single object', testIpcOutput, false, foobarObject, foobarObjectInspect);109test('error.message contains IPC messages, two objects', testIpcOutput, true, foobarObject, foobarObjectInspect);110test('error.message contains IPC messages, multiline string', testIpcOutput, false, `${foobarString}\n${foobarString}`, `${foobarString}\n${foobarString}`);111test('error.message contains IPC messages, control characters', testIpcOutput, false, '\0', '\\u0000');112113test('error.message does not contain IPC messages, buffer false', async t => {114 const {exitCode, message, ipc} = await t.throwsAsync(execa('ipc-echo-fail.js', {ipcInput: foobarString, buffer: false}));114 const {exitCode, message, ipcOutput} = await t.throwsAsync(execa('ipc-echo-fail.js', {ipcInput: foobarString, buffer: false}));115 t.is(exitCode, 1);116 t.true(message.endsWith('ipc-echo-fail.js'));117 t.deepEqual(ipc, []);117 t.deepEqual(ipcOutput, []);118});
modified:test/return/output.js+2 added-2 removed
120 unmodified lines
121122test('ipc on subprocess spawning errors', async t => {123 const error = await t.throwsAsync(getEarlyErrorSubprocess({ipc: true}));124 t.like(error, expectedEarlyError);125 t.deepEqual(error.ipc, []);125 t.deepEqual(error.ipcOutput, []);126});127128const testEarlyErrorNoIpc = async (t, options) => {129 const error = await t.throwsAsync(getEarlyErrorSubprocess(options));130 t.like(error, expectedEarlyError);131 t.deepEqual(error.ipc, []);131 t.deepEqual(error.ipcOutput, []);132};133134test('ipc on subprocess spawning errors, ipc false', testEarlyErrorNoIpc, {ipc: false});135test('ipc on subprocess spawning errors, buffer false', testEarlyErrorNoIpc, {buffer: false});
modified:test/return/result.js+2 added-2 removed
23 unmodified lines
24 'stdout',25 'stderr',26 'all',27 'stdio',28 'ipc',28 'ipcOutput',29 'pipedFrom',30 ]);31};32
20 unmodified lines
53 'stdout',54 'stderr',55 'all',56 'stdio',57 'ipc',57 'ipcOutput',58 'pipedFrom',59 ]);60};61
82 unmodified lines
modified:test-d/return/result-ipc.ts+25 added-25 removed
9 unmodified lines
10 type Options,11} from '../../index.js';1213const ipcResult = await execa('unicorns', {ipc: true});14expectType<Array<Message<'advanced'>>>(ipcResult.ipc);14expectType<Array<Message<'advanced'>>>(ipcResult.ipcOutput);1516const ipcFdResult = await execa('unicorns', {ipc: true, buffer: {stdout: false}});17expectType<Array<Message<'advanced'>>>(ipcFdResult.ipc);17expectType<Array<Message<'advanced'>>>(ipcFdResult.ipcOutput);1819const advancedResult = await execa('unicorns', {ipc: true, serialization: 'advanced'});20expectType<Array<Message<'advanced'>>>(advancedResult.ipc);20expectType<Array<Message<'advanced'>>>(advancedResult.ipcOutput);2122const jsonResult = await execa('unicorns', {ipc: true, serialization: 'json'});23expectType<Array<Message<'json'>>>(jsonResult.ipc);23expectType<Array<Message<'json'>>>(jsonResult.ipcOutput);2425const inputResult = await execa('unicorns', {ipcInput: ''});26expectType<Array<Message<'advanced'>>>(inputResult.ipc);26expectType<Array<Message<'advanced'>>>(inputResult.ipcOutput);2728const genericInputResult = await execa('unicorns', {ipcInput: '' as Message});29expectType<Array<Message<'advanced'>>>(genericInputResult.ipc);29expectType<Array<Message<'advanced'>>>(genericInputResult.ipcOutput);3031const genericResult = await execa('unicorns', {} as Options);32expectType<Message[] | []>(genericResult.ipc);32expectType<Message[] | []>(genericResult.ipcOutput);3334const genericIpc = await execa('unicorns', {ipc: true as boolean});35expectType<Array<Message<'advanced'>> | []>(genericIpc.ipc);35expectType<Array<Message<'advanced'>> | []>(genericIpc.ipcOutput);3637const maybeInputResult = await execa('unicorns', {ipcInput: '' as '' | undefined});38expectType<Array<Message<'advanced'>> | []>(maybeInputResult.ipc);38expectType<Array<Message<'advanced'>> | []>(maybeInputResult.ipcOutput);3940const falseIpcResult = await execa('unicorns', {ipc: false});41expectType<[]>(falseIpcResult.ipc);41expectType<[]>(falseIpcResult.ipcOutput);4243const noIpcResult = await execa('unicorns');44expectType<[]>(noIpcResult.ipc);44expectType<[]>(noIpcResult.ipcOutput);4546const emptyIpcResult = await execa('unicorns', {});47expectType<[]>(emptyIpcResult.ipc);47expectType<[]>(emptyIpcResult.ipcOutput);4849const undefinedInputResult = await execa('unicorns', {ipcInput: undefined});50expectType<[]>(undefinedInputResult.ipc);50expectType<[]>(undefinedInputResult.ipcOutput);5152const inputNoIpcResult = await execa('unicorns', {ipc: false, ipcInput: ''});53expectType<[]>(inputNoIpcResult.ipc);53expectType<[]>(inputNoIpcResult.ipcOutput);5455const noBufferResult = await execa('unicorns', {ipc: true, buffer: false});56expectType<[]>(noBufferResult.ipc);56expectType<[]>(noBufferResult.ipcOutput);5758const noBufferFdResult = await execa('unicorns', {ipc: true, buffer: {ipc: false}});59expectType<[]>(noBufferFdResult.ipc);59expectType<[]>(noBufferFdResult.ipcOutput);6061const syncResult = execaSync('unicorns');62expectType<[]>(syncResult.ipc);62expectType<[]>(syncResult.ipcOutput);6364expectType<Message[] | []>({} as Result['ipc']);65expectAssignable<Message[]>({} as Result['ipc']);66expectType<[]>({} as unknown as SyncResult['ipc']);64expectType<Message[] | []>({} as Result['ipcOutput']);65expectAssignable<Message[]>({} as Result['ipcOutput']);66expectType<[]>({} as unknown as SyncResult['ipcOutput']);6768const ipcError = new Error('.') as ExecaError<{ipc: true}>;69expectType<Array<Message<'advanced'>>>(ipcError.ipc);69expectType<Array<Message<'advanced'>>>(ipcError.ipcOutput);7071const ipcFalseError = new Error('.') as ExecaError<{ipc: false}>;72expectType<[]>(ipcFalseError.ipc);72expectType<[]>(ipcFalseError.ipcOutput);7374const asyncError = new Error('.') as ExecaError;75expectType<Message[] | []>(asyncError.ipc);76expectAssignable<Message[]>(asyncError.ipc);75expectType<Message[] | []>(asyncError.ipcOutput);76expectAssignable<Message[]>(asyncError.ipcOutput);7778const syncError = new Error('.') as ExecaSyncError;79expectType<[]>(syncError.ipc);79expectType<[]>(syncError.ipcOutput);
modified:types/methods/main-async.d.ts+3 added-3 removed
224 unmodified lines
225```226// main.js227import {execaNode} from 'execa';228229const {ipc} = await execaNode`build.js`;230console.log(ipc[0]); // {kind: 'start', timestamp: date}231console.log(ipc[1]); // {kind: 'stop', timestamp: date}229const {ipcOutput} = await execaNode`build.js`;230console.log(ipcOutput[0]); // {kind: 'start', timestamp: date}231console.log(ipcOutput[1]); // {kind: 'stop', timestamp: date}232```233234```235// build.js
74 unmodified lines
modified:types/return/result-ipc.d.ts+2 added-2 removed
1import type {FdSpecificOption} from '../arguments/specific.js';2import type {CommonOptions, Options, StricterOptions} from '../arguments/options.js';3import type {Message, HasIpc} from '../ipc.js';45// `result.ipc`5// `result.ipcOutput`6// This is empty unless the `ipc` option is `true`.7// Also, this is empty if the `buffer` option is `false`.8export type ResultIpc<8export type ResultIpcOutput<9 IsSync extends boolean,10 OptionsType extends CommonOptions,11> = IsSync extends true12 ? []
15 unmodified lines
modified:types/return/result.d.ts+2 added-2 removed
3 unmodified lines
4import type {ErrorProperties} from './final-error.js';5import type {ResultAll} from './result-all.js';6import type {ResultStdioArray} from './result-stdio.js';7import type {ResultStdioNotAll} from './result-stdout.js';8import type {ResultIpc} from './result-ipc.js';8import type {ResultIpcOutput} from './result-ipc.js';910export declare abstract class CommonResult<11 IsSync extends boolean,12 OptionsType extends CommonOptions,
40 unmodified lines
53 All the messages sent by the subprocess to the current process.5455 This is empty unless the `ipc` option is `true`. Also, this is empty if the `buffer` option is `false`.56 */57 ipc: ResultIpc<IsSync, OptionsType>;57 ipcOutput: ResultIpcOutput<IsSync, OptionsType>;5859 /**60 Results of the other subprocesses that were piped into this subprocess.61
132 unmodified lines
modified:readme.md+3 added-3 removed
307 unmodified lines
308```js309// main.js310import {execaNode} from 'execa';311312const {ipc} = await execaNode`build.js`;313console.log(ipc[0]); // {kind: 'start', timestamp: date}314console.log(ipc[1]); // {kind: 'stop', timestamp: date}312const {ipcOutput} = await execaNode`build.js`;313console.log(ipcOutput[0]); // {kind: 'start', timestamp: date}314console.log(ipcOutput[1]); // {kind: 'stop', timestamp: date}315```316317```js318// build.js
73 unmodified lines