Skip to content
Myr

Add support for `lines` option with `execaSync()` (#951)

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

authored by ehmicky · committed by GitHub · parent 6233874 · Browse files · 10 files+188 added−95 removed
This commit

State

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

Diff stats

10 files+188 added−95 removed

  • tests:+139 added−66 removed
  • other:+49 added−29 removed

10 files+188 added−95 removed

modified:lib/stdio/lines.js+6 added-7 removed
modified:lib/stdio/output-sync.js+14 added-12 removed
modified:test/return/error.js+13 added-7 removed
75 unmodified lines
76test('error.message contains stdout/stderr/stdio even with encoding "buffer", objectMode', testStdioMessage, 'buffer', false, true);77test('error.message contains all if available, objectMode', testStdioMessage, 'utf8', true, true);78test('error.message contains all even with encoding "buffer", objectMode', testStdioMessage, 'buffer', true, true);7980const testLinesMessage = async (t, encoding, stripFinalNewline) => {81 const {message} = await t.throwsAsync(execa('noop-fail.js', ['1', `${foobarString}\n${foobarString}\n`], {80const testLinesMessage = async (t, encoding, stripFinalNewline, execaMethod) => {81 const {failed, message} = await execaMethod('noop-fail.js', ['1', `${foobarString}\n${foobarString}\n`], {82 lines: true,83 encoding,84 stripFinalNewline,85 reject: false,85 }));86 });87 t.true(failed);88 t.true(message.endsWith(`noop-fail.js 1 ${QUOTE}${foobarString}\\n${foobarString}\\n${QUOTE}\n\n${foobarString}\n${foobarString}`));89};9089test('error.message handles "lines: true"', testLinesMessage, 'utf8', false);90test('error.message handles "lines: true", stripFinalNewline', testLinesMessage, 'utf8', true);91test('error.message handles "lines: true", buffer', testLinesMessage, 'buffer', false);92test('error.message handles "lines: true", buffer, stripFinalNewline', testLinesMessage, 'buffer', true);91test('error.message handles "lines: true"', testLinesMessage, 'utf8', false, execa);92test('error.message handles "lines: true", stripFinalNewline', testLinesMessage, 'utf8', true, execa);93test('error.message handles "lines: true", buffer', testLinesMessage, 'buffer', false, execa);94test('error.message handles "lines: true", buffer, stripFinalNewline', testLinesMessage, 'buffer', true, execa);95test('error.message handles "lines: true", sync', testLinesMessage, 'utf8', false, execaSync);96test('error.message handles "lines: true", stripFinalNewline, sync', testLinesMessage, 'utf8', true, execaSync);97test('error.message handles "lines: true", buffer, sync', testLinesMessage, 'buffer', false, execaSync);98test('error.message handles "lines: true", buffer, stripFinalNewline, sync', testLinesMessage, 'buffer', true, execaSync);99100const testPartialIgnoreMessage = async (t, fdNumber, stdioOption, output) => {101 const {message} = await t.throwsAsync(execa('echo-fail.js', getStdio(fdNumber, stdioOption, 4)));102 t.true(message.endsWith(`echo-fail.js\n\n${output}\n\nfd3`));
109 unmodified lines
modified:test/stdio/encoding-final.js+26 added-12 removed
155 unmodified lines
156test('Is not ignored with other encodings and ["overlapped"]', testIgnoredEncoding, ['overlapped'], false, base64Options, execa);157test('Is not ignored with other encodings and ["inherit", "pipe"]', testIgnoredEncoding, ['inherit', 'pipe'], false, base64Options, execa);158test('Is not ignored with other encodings and undefined', testIgnoredEncoding, undefined, false, base64Options, execa);159test('Is not ignored with other encodings and null', testIgnoredEncoding, null, false, base64Options, execa);160test('Is ignored with other encodings and "ignore", sync', testIgnoredEncoding, 'ignore', true, base64Options, execaSync);161test('Is ignored with other encodings and ["ignore"], sync', testIgnoredEncoding, ['ignore'], true, base64Options, execaSync);162test('Is ignored with other encodings and "inherit", sync', testIgnoredEncoding, 'inherit', true, base64Options, execaSync);163test('Is ignored with other encodings and ["inherit"], sync', testIgnoredEncoding, ['inherit'], true, base64Options, execaSync);164test('Is ignored with other encodings and 1, sync', testIgnoredEncoding, 1, true, base64Options, execaSync);165test('Is ignored with other encodings and [1], sync', testIgnoredEncoding, [1], true, base64Options, execaSync);166test('Is ignored with other encodings and process.stdout, sync', testIgnoredEncoding, process.stdout, true, base64Options, execaSync);167test('Is ignored with other encodings and [process.stdout], sync', testIgnoredEncoding, [process.stdout], true, base64Options, execaSync);168test('Is not ignored with other encodings and "pipe", sync', testIgnoredEncoding, 'pipe', false, base64Options, execaSync);169test('Is not ignored with other encodings and ["pipe"], sync', testIgnoredEncoding, ['pipe'], false, base64Options, execaSync);170test('Is not ignored with other encodings and undefined, sync', testIgnoredEncoding, undefined, false, base64Options, execaSync);171test('Is not ignored with other encodings and null, sync', testIgnoredEncoding, null, false, base64Options, execaSync);160test('Is ignored with "lines: true" and "ignore"', testIgnoredEncoding, 'ignore', true, linesOptions, execa);161test('Is ignored with "lines: true" and ["ignore"]', testIgnoredEncoding, ['ignore'], true, linesOptions, execa);162test('Is ignored with "lines: true" and "ipc"', testIgnoredEncoding, 'ipc', true, linesOptions, execa);163test('Is ignored with "lines: true" and ["ipc"]', testIgnoredEncoding, ['ipc'], true, linesOptions, execa);
11 unmodified lines
175test('Is not ignored with "lines: true" and undefined', testIgnoredEncoding, undefined, false, linesOptions, execa);176test('Is not ignored with "lines: true" and null', testIgnoredEncoding, null, false, linesOptions, execa);177test('Is ignored with "lines: true", other encodings and "ignore"', testIgnoredEncoding, 'ignore', true, {...base64Options, ...linesOptions}, execa);178test('Is not ignored with "lines: true", other encodings and "pipe"', testIgnoredEncoding, 'pipe', false, {...base64Options, ...linesOptions}, execa);179test('Is ignored with other encodings and "ignore", sync', testIgnoredEncoding, 'ignore', true, base64Options, execaSync);180test('Is ignored with other encodings and ["ignore"], sync', testIgnoredEncoding, ['ignore'], true, base64Options, execaSync);181test('Is ignored with other encodings and "inherit", sync', testIgnoredEncoding, 'inherit', true, base64Options, execaSync);182test('Is ignored with other encodings and ["inherit"], sync', testIgnoredEncoding, ['inherit'], true, base64Options, execaSync);183test('Is ignored with other encodings and 1, sync', testIgnoredEncoding, 1, true, base64Options, execaSync);184test('Is ignored with other encodings and [1], sync', testIgnoredEncoding, [1], true, base64Options, execaSync);185test('Is ignored with other encodings and process.stdout, sync', testIgnoredEncoding, process.stdout, true, base64Options, execaSync);186test('Is ignored with other encodings and [process.stdout], sync', testIgnoredEncoding, [process.stdout], true, base64Options, execaSync);187test('Is not ignored with other encodings and "pipe", sync', testIgnoredEncoding, 'pipe', false, base64Options, execaSync);188test('Is not ignored with other encodings and ["pipe"], sync', testIgnoredEncoding, ['pipe'], false, base64Options, execaSync);189test('Is not ignored with other encodings and undefined, sync', testIgnoredEncoding, undefined, false, base64Options, execaSync);190test('Is not ignored with other encodings and null, sync', testIgnoredEncoding, null, false, base64Options, execaSync);191test('Is ignored with "lines: true" and "ignore", sync', testIgnoredEncoding, 'ignore', true, linesOptions, execaSync);192test('Is ignored with "lines: true" and ["ignore"], sync', testIgnoredEncoding, ['ignore'], true, linesOptions, execaSync);193test('Is ignored with "lines: true" and "inherit", sync', testIgnoredEncoding, 'inherit', true, linesOptions, execaSync);194test('Is ignored with "lines: true" and ["inherit"], sync', testIgnoredEncoding, ['inherit'], true, linesOptions, execaSync);195test('Is ignored with "lines: true" and 1, sync', testIgnoredEncoding, 1, true, linesOptions, execaSync);196test('Is ignored with "lines: true" and [1], sync', testIgnoredEncoding, [1], true, linesOptions, execaSync);197test('Is ignored with "lines: true" and process.stdout, sync', testIgnoredEncoding, process.stdout, true, linesOptions, execaSync);198test('Is ignored with "lines: true" and [process.stdout], sync', testIgnoredEncoding, [process.stdout], true, linesOptions, execaSync);199test('Is not ignored with "lines: true" and "pipe", sync', testIgnoredEncoding, 'pipe', false, linesOptions, execaSync);200test('Is not ignored with "lines: true" and ["pipe"], sync', testIgnoredEncoding, ['pipe'], false, linesOptions, execaSync);201test('Is not ignored with "lines: true" and undefined, sync', testIgnoredEncoding, undefined, false, linesOptions, execaSync);202test('Is not ignored with "lines: true" and null, sync', testIgnoredEncoding, null, false, linesOptions, execaSync);203test('Is ignored with "lines: true", other encodings and "ignore", sync', testIgnoredEncoding, 'ignore', true, {...base64Options, ...linesOptions}, execaSync);204test('Is not ignored with "lines: true", other encodings and "pipe", sync', testIgnoredEncoding, 'pipe', false, {...base64Options, ...linesOptions}, execaSync);205206// eslint-disable-next-line max-params207const testEncodingInput = async (t, input, expectedStdout, encoding, execaMethod) => {208 const {stdout} = await execaMethod('stdin.js', {input, encoding});
15 unmodified lines
modified:test/stdio/file-path.js+24 added
296 unmodified lines
297test('stderr can use generators together with output file URLs, sync', testOutputFileTransform, 2, pathToFileURL, execaSync);298test('stdio[*] can use generators together with output file paths, sync', testOutputFileTransform, 3, getAbsolutePath, execaSync);299test('stdio[*] can use generators together with output file URLs, sync', testOutputFileTransform, 3, pathToFileURL, execaSync);300301const testOutputFileLines = async (t, fdNumber, mapFile, execaMethod) => {302 const filePath = tempfile();303 const {stdio} = await execaMethod('noop-fd.js', [`${fdNumber}`, foobarString], {304 ...getStdio(fdNumber, mapFile(filePath)),305 lines: true,306 });307 t.deepEqual(stdio[fdNumber], [foobarString]);308 t.is(await readFile(filePath, 'utf8'), foobarString);309 await rm(filePath);310};311312test('stdout can use "lines: true" together with output file paths', testOutputFileLines, 1, getAbsolutePath, execa);313test('stdout can use "lines: true" together with output file URLs', testOutputFileLines, 1, pathToFileURL, execa);314test('stderr can use "lines: true" together with output file paths', testOutputFileLines, 2, getAbsolutePath, execa);315test('stderr can use "lines: true" together with output file URLs', testOutputFileLines, 2, pathToFileURL, execa);316test('stdio[*] can use "lines: true" together with output file paths', testOutputFileLines, 3, getAbsolutePath, execa);317test('stdio[*] can use "lines: true" together with output file URLs', testOutputFileLines, 3, pathToFileURL, execa);318test('stdout can use "lines: true" together with output file paths, sync', testOutputFileLines, 1, getAbsolutePath, execaSync);319test('stdout can use "lines: true" together with output file URLs, sync', testOutputFileLines, 1, pathToFileURL, execaSync);320test('stderr can use "lines: true" together with output file paths, sync', testOutputFileLines, 2, getAbsolutePath, execaSync);321test('stderr can use "lines: true" together with output file URLs, sync', testOutputFileLines, 2, pathToFileURL, execaSync);322test('stdio[*] can use "lines: true" together with output file paths, sync', testOutputFileLines, 3, getAbsolutePath, execaSync);323test('stdio[*] can use "lines: true" together with output file URLs, sync', testOutputFileLines, 3, pathToFileURL, execaSync);324325const testOutputFileObject = async (t, fdNumber, mapFile, execaMethod) => {326 const filePath = tempfile();327 t.throws(() => {328 execaMethod('noop-fd.js', [`${fdNumber}`, foobarString], getStdio(fdNumber, [
52 unmodified lines
modified:test/stdio/lines.js+65 added-41 removed
20 unmodified lines
21} from '../helpers/lines.js';2223setFixtureDir();2425const getSimpleChunkSubprocess = options => execa('noop-fd.js', ['1', simpleFull], {lines: true, ...options});25const getSimpleChunkSubprocessAsync = options => getSimpleChunkSubprocess(execa, options);26const getSimpleChunkSubprocess = (execaMethod, options) => execaMethod('noop-fd.js', ['1', simpleFull], {lines: true, ...options});2728// eslint-disable-next-line max-params28const testStreamLines = async (t, fdNumber, input, expectedOutput, stripFinalNewline) => {29 const {stdio} = await execa('noop-fd.js', [`${fdNumber}`, input], {29const testStreamLines = async (t, fdNumber, input, expectedOutput, stripFinalNewline, execaMethod) => {30 const {stdio} = await execaMethod('noop-fd.js', [`${fdNumber}`, input], {31 ...fullStdio,32 lines: true,33 stripFinalNewline,34 });35 t.deepEqual(stdio[fdNumber], expectedOutput);36};3737test('"lines: true" splits lines, stdout, string', testStreamLines, 1, simpleFull, simpleLines, false);38test('"lines: true" splits lines, stderr, string', testStreamLines, 2, simpleFull, simpleLines, false);39test('"lines: true" splits lines, stdio[*], string', testStreamLines, 3, simpleFull, simpleLines, false);40test('"lines: true" splits lines, stdout, string, stripFinalNewline', testStreamLines, 1, simpleFull, noNewlinesChunks, true);41test('"lines: true" splits lines, stderr, string, stripFinalNewline', testStreamLines, 2, simpleFull, noNewlinesChunks, true);42test('"lines: true" splits lines, stdio[*], string, stripFinalNewline', testStreamLines, 3, simpleFull, noNewlinesChunks, true);38test('"lines: true" splits lines, stdout, string', testStreamLines, 1, simpleFull, simpleLines, false, execa);39test('"lines: true" splits lines, stderr, string', testStreamLines, 2, simpleFull, simpleLines, false, execa);40test('"lines: true" splits lines, stdio[*], string', testStreamLines, 3, simpleFull, simpleLines, false, execa);41test('"lines: true" splits lines, stdout, string, stripFinalNewline', testStreamLines, 1, simpleFull, noNewlinesChunks, true, execa);42test('"lines: true" splits lines, stderr, string, stripFinalNewline', testStreamLines, 2, simpleFull, noNewlinesChunks, true, execa);43test('"lines: true" splits lines, stdio[*], string, stripFinalNewline', testStreamLines, 3, simpleFull, noNewlinesChunks, true, execa);44test('"lines: true" splits lines, stdout, string, sync', testStreamLines, 1, simpleFull, simpleLines, false, execaSync);45test('"lines: true" splits lines, stderr, string, sync', testStreamLines, 2, simpleFull, simpleLines, false, execaSync);46test('"lines: true" splits lines, stdio[*], string, sync', testStreamLines, 3, simpleFull, simpleLines, false, execaSync);47test('"lines: true" splits lines, stdout, string, stripFinalNewline, sync', testStreamLines, 1, simpleFull, noNewlinesChunks, true, execaSync);48test('"lines: true" splits lines, stderr, string, stripFinalNewline, sync', testStreamLines, 2, simpleFull, noNewlinesChunks, true, execaSync);49test('"lines: true" splits lines, stdio[*], string, stripFinalNewline, sync', testStreamLines, 3, simpleFull, noNewlinesChunks, true, execaSync);5051const testStreamLinesNoop = async (t, lines, execaMethod) => {52 const {stdout} = await execaMethod('noop-fd.js', ['1', simpleFull], {lines});53 t.is(stdout, simpleFull);54};5556test('"lines: false" is a noop with execa()', testStreamLinesNoop, false, execa);57test('"lines: false" is a noop with execaSync()', testStreamLinesNoop, false, execaSync);51test('"lines: true" is a noop with execaSync()', testStreamLinesNoop, true, execaSync);5859const bigArray = Array.from({length: 1e5}).fill('.\n');60const bigString = bigArray.join('');61const bigStringNoNewlines = '.'.repeat(1e6);62const bigStringNoNewlinesEnd = `${bigStringNoNewlines}\n`;6364// eslint-disable-next-line max-params59const testStreamLinesGenerator = async (t, input, expectedLines, objectMode, binary) => {60 const {stdout} = await execa('noop.js', {65const testStreamLinesGenerator = async (t, input, expectedLines, objectMode, binary, execaMethod) => {66 const {stdout} = await execaMethod('noop.js', {67 stdout: getOutputsGenerator(input)(objectMode, binary),68 lines: true,69 stripFinalNewline: false,70 });71 t.deepEqual(stdout, expectedLines);72};7368test('"lines: true" works with strings generators', testStreamLinesGenerator, simpleChunks, simpleFullEndLines, false, false);69test('"lines: true" works with strings generators, binary', testStreamLinesGenerator, simpleChunks, simpleLines, false, true);70test('"lines: true" works with big strings generators', testStreamLinesGenerator, [bigString], bigArray, false, false);71test('"lines: true" works with big strings generators without newlines', testStreamLinesGenerator, [bigStringNoNewlines], [bigStringNoNewlinesEnd], false, false);72test('"lines: true" is a noop with strings generators, objectMode', testStreamLinesGenerator, simpleChunks, simpleChunks, true, false);73test('"lines: true" is a noop with strings generators, binary, objectMode', testStreamLinesGenerator, simpleChunks, simpleChunks, true, true);74test('"lines: true" is a noop big strings generators, objectMode', testStreamLinesGenerator, [bigString], [bigString], true, false);75test('"lines: true" is a noop big strings generators without newlines, objectMode', testStreamLinesGenerator, [bigStringNoNewlines], [bigStringNoNewlines], true, false);74test('"lines: true" works with strings generators', testStreamLinesGenerator, simpleChunks, simpleFullEndLines, false, false, execa);75test('"lines: true" works with strings generators, binary', testStreamLinesGenerator, simpleChunks, simpleLines, false, true, execa);76test('"lines: true" works with big strings generators', testStreamLinesGenerator, [bigString], bigArray, false, false, execa);77test('"lines: true" works with big strings generators without newlines', testStreamLinesGenerator, [bigStringNoNewlines], [bigStringNoNewlinesEnd], false, false, execa);78test('"lines: true" is a noop with strings generators, objectMode', testStreamLinesGenerator, simpleChunks, simpleChunks, true, false, execa);79test('"lines: true" is a noop with strings generators, binary, objectMode', testStreamLinesGenerator, simpleChunks, simpleChunks, true, true, execa);80test('"lines: true" is a noop big strings generators, objectMode', testStreamLinesGenerator, [bigString], [bigString], true, false, execa);81test('"lines: true" is a noop big strings generators without newlines, objectMode', testStreamLinesGenerator, [bigStringNoNewlines], [bigStringNoNewlines], true, false, execa);82test('"lines: true" works with strings generators, sync', testStreamLinesGenerator, simpleChunks, simpleFullEndLines, false, false, execaSync);83test('"lines: true" works with strings generators, binary, sync', testStreamLinesGenerator, simpleChunks, simpleLines, false, true, execaSync);84test('"lines: true" works with big strings generators, sync', testStreamLinesGenerator, [bigString], bigArray, false, false, execaSync);85test('"lines: true" works with big strings generators without newlines, sync', testStreamLinesGenerator, [bigStringNoNewlines], [bigStringNoNewlinesEnd], false, false, execaSync);86test('"lines: true" is a noop with strings generators, objectMode, sync', testStreamLinesGenerator, simpleChunks, simpleChunks, true, false, execaSync);87test('"lines: true" is a noop with strings generators, binary, objectMode, sync', testStreamLinesGenerator, simpleChunks, simpleChunks, true, true, execaSync);88test('"lines: true" is a noop big strings generators, objectMode, sync', testStreamLinesGenerator, [bigString], [bigString], true, false, execaSync);89test('"lines: true" is a noop big strings generators without newlines, objectMode, sync', testStreamLinesGenerator, [bigStringNoNewlines], [bigStringNoNewlines], true, false, execaSync);9077test('"lines: true" is a noop with objects generators, objectMode', async t => {78 const {stdout} = await execa('noop.js', {91const testLinesObjectMode = async (t, execaMethod) => {92 const {stdout} = await execaMethod('noop.js', {93 stdout: getOutputsGenerator([foobarObject])(true),94 lines: true,95 });96 t.deepEqual(stdout, [foobarObject]);83});97};9899test('"lines: true" is a noop with objects generators, objectMode', testLinesObjectMode, execa);100test('"lines: true" is a noop with objects generators, objectMode, sync', testLinesObjectMode, execaSync);101102// eslint-disable-next-line max-params85const testBinaryEncoding = async (t, expectedOutput, encoding, stripFinalNewline) => {86 const {stdout} = await getSimpleChunkSubprocess({encoding, stripFinalNewline});103const testBinaryEncoding = async (t, expectedOutput, encoding, stripFinalNewline, execaMethod) => {104 const {stdout} = await getSimpleChunkSubprocess(execaMethod, {encoding, stripFinalNewline});105 t.deepEqual(stdout, expectedOutput);106};10790test('"lines: true" is a noop with "encoding: buffer"', testBinaryEncoding, simpleFullUint8Array, 'buffer', false);91test('"lines: true" is a noop with "encoding: buffer", stripFinalNewline', testBinaryEncoding, simpleFullUint8Array, 'buffer', false);92test('"lines: true" is a noop with "encoding: hex"', testBinaryEncoding, simpleFullHex, 'hex', false);93test('"lines: true" is a noop with "encoding: hex", stripFinalNewline', testBinaryEncoding, simpleFullHex, 'hex', true);108test('"lines: true" is a noop with "encoding: buffer"', testBinaryEncoding, simpleFullUint8Array, 'buffer', false, execa);109test('"lines: true" is a noop with "encoding: buffer", stripFinalNewline', testBinaryEncoding, simpleFullUint8Array, 'buffer', false, execa);110test('"lines: true" is a noop with "encoding: hex"', testBinaryEncoding, simpleFullHex, 'hex', false, execa);111test('"lines: true" is a noop with "encoding: hex", stripFinalNewline', testBinaryEncoding, simpleFullHex, 'hex', true, execa);112test('"lines: true" is a noop with "encoding: buffer", sync', testBinaryEncoding, simpleFullUint8Array, 'buffer', false, execaSync);113test('"lines: true" is a noop with "encoding: buffer", stripFinalNewline, sync', testBinaryEncoding, simpleFullUint8Array, 'buffer', false, execaSync);114test('"lines: true" is a noop with "encoding: hex", sync', testBinaryEncoding, simpleFullHex, 'hex', false, execaSync);115test('"lines: true" is a noop with "encoding: hex", stripFinalNewline, sync', testBinaryEncoding, simpleFullHex, 'hex', true, execaSync);11695const testTextEncoding = async (t, expectedLines, stripFinalNewline) => {96 const {stdout} = await execa('stdin.js', {117const testTextEncoding = async (t, expectedLines, stripFinalNewline, execaMethod) => {118 const {stdout} = await execaMethod('stdin.js', {119 lines: true,120 stripFinalNewline,121 encoding: 'utf16le',122 input: simpleFullUtf16Uint8Array,123 });124 t.deepEqual(stdout, expectedLines);125};126105test('"lines: true" is a noop with "encoding: utf16"', testTextEncoding, simpleLines, false);106test('"lines: true" is a noop with "encoding: utf16", stripFinalNewline', testTextEncoding, noNewlinesChunks, true);127test('"lines: true" is a noop with "encoding: utf16"', testTextEncoding, simpleLines, false, execa);128test('"lines: true" is a noop with "encoding: utf16", stripFinalNewline', testTextEncoding, noNewlinesChunks, true, execa);129test('"lines: true" is a noop with "encoding: utf16", sync', testTextEncoding, simpleLines, false, execaSync);130test('"lines: true" is a noop with "encoding: utf16", stripFinalNewline, sync', testTextEncoding, noNewlinesChunks, true, execaSync);131132test('"lines: true" is a noop with "buffer: false"', async t => {109 const {stdout} = await getSimpleChunkSubprocess({buffer: false});133 const {stdout} = await getSimpleChunkSubprocessAsync({buffer: false});134 t.is(stdout, undefined);135});136137test('"lines: true" can be below "maxBuffer"', async t => {138 const maxBuffer = simpleLines.length;115 const {stdout} = await getSimpleChunkSubprocess({maxBuffer});139 const {stdout} = await getSimpleChunkSubprocessAsync({maxBuffer});140 t.deepEqual(stdout, noNewlinesChunks);141});142143test('"lines: true" can be above "maxBuffer"', async t => {144 const maxBuffer = simpleLines.length - 1;121 const {cause, stdout} = await t.throwsAsync(getSimpleChunkSubprocess({maxBuffer}));145 const {cause, stdout} = await t.throwsAsync(getSimpleChunkSubprocessAsync({maxBuffer}));146 t.true(cause instanceof MaxBufferError);147 t.deepEqual(stdout, noNewlinesChunks.slice(0, maxBuffer));148});149150test('"lines: true" stops on stream error', async t => {151 const cause = new Error(foobarString);128 const error = await t.throwsAsync(getSimpleChunkSubprocess({152 const error = await t.throwsAsync(getSimpleChunkSubprocessAsync({153 * stdout(line) {154 if (line === noNewlinesChunks[2]) {155 throw cause;156 }
5 unmodified lines
162 t.deepEqual(error.stdout, noNewlinesChunks.slice(0, 2));163});164165const testAsyncIteration = async (t, expectedLines, stripFinalNewline) => {142 const subprocess = getSimpleChunkSubprocess({stripFinalNewline});166 const subprocess = getSimpleChunkSubprocessAsync({stripFinalNewline});167 t.false(subprocess.stdout.readableObjectMode);168 await assertStreamOutput(t, subprocess.stdout, simpleFull);169 const {stdout} = await subprocess;170 t.deepEqual(stdout, expectedLines);
2 unmodified lines
173test('"lines: true" works with stream async iteration', testAsyncIteration, simpleLines, false);174test('"lines: true" works with stream async iteration, stripFinalNewline', testAsyncIteration, noNewlinesChunks, true);175176const testDataEvents = async (t, expectedLines, stripFinalNewline) => {153 const subprocess = getSimpleChunkSubprocess({stripFinalNewline});177 const subprocess = getSimpleChunkSubprocessAsync({stripFinalNewline});178 const [firstLine] = await once(subprocess.stdout, 'data');179 t.deepEqual(firstLine, Buffer.from(simpleLines[0]));180 const {stdout} = await subprocess;181 t.deepEqual(stdout, expectedLines);
10 unmodified lines
192 done();193 },194 decodeStrings: false,195 });172 const {stdout} = await getSimpleChunkSubprocess({stripFinalNewline, stdout: ['pipe', writable]});196 const {stdout} = await getSimpleChunkSubprocessAsync({stripFinalNewline, stdout: ['pipe', writable]});197 t.deepEqual(lines, simpleLines);198 t.deepEqual(stdout, expectedLines);199};200201test('"lines: true" works with writable streams targets', testWritableStream, simpleLines, false);202test('"lines: true" works with writable streams targets, stripFinalNewline', testWritableStream, noNewlinesChunks, true);203204const testIterable = async (t, expectedLines, stripFinalNewline) => {181 const subprocess = getSimpleChunkSubprocess({stripFinalNewline});205 const subprocess = getSimpleChunkSubprocessAsync({stripFinalNewline});206 await assertIterableChunks(t, subprocess, noNewlinesChunks);207 const {stdout} = await subprocess;208 t.deepEqual(stdout, expectedLines);209};
3 unmodified lines
modified:test/stdio/split.js+11 added-6 removed
243 unmodified lines
244 lines.push(chunk);245 yield new TextEncoder().encode(chunk);246};247248// eslint-disable-next-line max-params248const testStringToUint8Array = async (t, expectedOutput, objectMode, preserveNewlines) => {249const testStringToUint8Array = async (t, expectedOutput, objectMode, preserveNewlines, execaMethod) => {250 const lines = [];250 const {stdout} = await execa('noop-fd.js', ['1', foobarString], {251 const {stdout} = await execaMethod('noop-fd.js', ['1', foobarString], {252 stdout: {253 transform: resultUint8ArrayGenerator.bind(undefined, lines),254 objectMode,255 preserveNewlines,
3 unmodified lines
259 t.deepEqual(lines, [foobarString]);260 t.deepEqual(stdout, expectedOutput);261};262262test('Line splitting when converting from string to Uint8Array', testStringToUint8Array, [foobarString], false, true);263test('Line splitting when converting from string to Uint8Array, objectMode', testStringToUint8Array, [foobarUint8Array], true, true);264test('Line splitting when converting from string to Uint8Array, preserveNewlines', testStringToUint8Array, [foobarString], false, false);265test('Line splitting when converting from string to Uint8Array, objectMode, preserveNewlines', testStringToUint8Array, [foobarUint8Array], true, false);263test('Line splitting when converting from string to Uint8Array', testStringToUint8Array, [foobarString], false, true, execa);264test('Line splitting when converting from string to Uint8Array, objectMode', testStringToUint8Array, [foobarUint8Array], true, true, execa);265test('Line splitting when converting from string to Uint8Array, preserveNewlines', testStringToUint8Array, [foobarString], false, false, execa);266test('Line splitting when converting from string to Uint8Array, objectMode, preserveNewlines', testStringToUint8Array, [foobarUint8Array], true, false, execa);267test('Line splitting when converting from string to Uint8Array, sync', testStringToUint8Array, [foobarString], false, true, execaSync);268test('Line splitting when converting from string to Uint8Array, objectMode, sync', testStringToUint8Array, [foobarUint8Array], true, true, execaSync);269test('Line splitting when converting from string to Uint8Array, preserveNewlines, sync', testStringToUint8Array, [foobarString], false, false, execaSync);270test('Line splitting when converting from string to Uint8Array, objectMode, preserveNewlines, sync', testStringToUint8Array, [foobarUint8Array], true, false, execaSync);271272const testStripNewline = async (t, input, expectedOutput, execaMethod) => {273 const {stdout} = await execaMethod('noop.js', {274 stdout: getOutputsGenerator([input])(),
65 unmodified lines
modified:index.d.ts+3 added-3 removed
482 unmodified lines
483 This cannot be used if the `encoding` option is binary.484485 @default false486 */487 readonly lines?: Unless<IsSync, boolean>;487 readonly lines?: boolean;488489 /**490 Setting this to `false` resolves the promise with the error instead of rejecting it.491
916 unmodified lines
1408Same as `execa()` but synchronous.14091410Returns or throws a `subprocessResult`. The `subprocess` is not returned: its methods and properties are not available. This includes [`.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal), [`.pid`](https://nodejs.org/api/child_process.html#subprocesspid), `.pipe()`, `.iterable()`, `.readable()`, `.writable()`, `.duplex()` and the [`.stdin`/`.stdout`/`.stderr`](https://nodejs.org/api/child_process.html#subprocessstdout) streams.14111412Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `ipc`, `serialization`, `cancelSignal`, `forceKillAfterDelay` and `lines`. Also, the `stdin`, `stdout`, `stderr` and `stdio` options cannot be a `['pipe', 'inherit']` array, [`'overlapped'`](https://nodejs.org/api/child_process.html#optionsstdio), an async iterable, an async transform, a `Duplex`, or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.1412Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `ipc`, `serialization`, `cancelSignal` and `forceKillAfterDelay`. Also, the `stdin`, `stdout`, `stderr` and `stdio` options cannot be a `['pipe', 'inherit']` array, [`'overlapped'`](https://nodejs.org/api/child_process.html#optionsstdio), an async iterable, an async transform, a `Duplex`, or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.14131414@param file - The program/script to execute, as a string or file URL1415@param arguments - Arguments to pass to `file` on execution.1416@returns A `subprocessResult` object
105 unmodified lines
1522Same as `execaCommand()` but synchronous.15231524Returns or throws a `subprocessResult`. The `subprocess` is not returned: its methods and properties are not available. This includes [`.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal), [`.pid`](https://nodejs.org/api/child_process.html#subprocesspid), `.pipe()`, `.iterable()`, `.readable()`, `.writable()`, `.duplex()` and the [`.stdin`/`.stdout`/`.stderr`](https://nodejs.org/api/child_process.html#subprocessstdout) streams.15251526Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `ipc`, `serialization`, `cancelSignal`, `forceKillAfterDelay` and `lines`. Also, the `stdin`, `stdout`, `stderr` and `stdio` options cannot be a `['pipe', 'inherit']` array, [`'overlapped'`](https://nodejs.org/api/child_process.html#optionsstdio), an async iterable, an async transform, a `Duplex`, or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.1526Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `ipc`, `serialization`, `cancelSignal` and `forceKillAfterDelay`. Also, the `stdin`, `stdout`, `stderr` and `stdio` options cannot be a `['pipe', 'inherit']` array, [`'overlapped'`](https://nodejs.org/api/child_process.html#optionsstdio), an async iterable, an async transform, a `Duplex`, or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.15271528@param command - The program/script to execute and its arguments.1529@returns A `subprocessResult` object1530@throws A `subprocessResult` error
128 unmodified lines
modified:index.test-d.ts+25 added-6 removed
160 unmodified lines
161const preserveNewlinesOnly = {preserveNewlines: true} as const;162const objectModeOnly = {objectMode: true} as const;163const finalOnly = {final: unknownFinal} as const;164165type AnySyncChunk = string | Uint8Array | unknown[] | undefined;166type AnyChunk = AnySyncChunk | string[];165type AnyChunk = string | Uint8Array | string[] | unknown[] | undefined;166expectType<Writable | null>({} as ExecaSubprocess['stdin']);167expectType<Readable | null>({} as ExecaSubprocess['stdout']);168expectType<Readable | null>({} as ExecaSubprocess['stderr']);169expectType<Readable | undefined>({} as ExecaSubprocess['all']);170expectType<AnyChunk>({} as ExecaResult['stdout']);171expectType<AnyChunk>({} as ExecaResult['stderr']);172expectType<AnyChunk>({} as ExecaResult['all']);173expectAssignable<[undefined, AnyChunk, AnyChunk, ...AnyChunk[]]>({} as ExecaResult['stdio']);175expectType<AnySyncChunk>({} as ExecaSyncResult['stdout']);176expectType<AnySyncChunk>({} as ExecaSyncResult['stderr']);177expectAssignable<[undefined, AnySyncChunk, AnySyncChunk, ...AnySyncChunk[]]>({} as ExecaSyncResult['stdio']);174expectType<AnyChunk>({} as ExecaSyncResult['stdout']);175expectType<AnyChunk>({} as ExecaSyncResult['stderr']);176expectAssignable<[undefined, AnyChunk, AnyChunk, ...AnyChunk[]]>({} as ExecaSyncResult['stdio']);177178try {179 const execaPromise = execa('unicorns', {all: true});180 const unicornsResult = await execaPromise;
940 unmodified lines
1121 expectType<Uint8Array>(bufferResult.stderr);1122 expectType<Uint8Array>(bufferResult.stdio[2]);1123 expectError(bufferResult.all.toString());11241125 const linesResult = execaSync('unicorns', {lines: true});1126 expectType<string[]>(linesResult.stdout);1127 expectType<string[]>(linesResult.stderr);11281129 const linesBufferResult = execaSync('unicorns', {lines: true, encoding: 'buffer'});1130 expectType<Uint8Array>(linesBufferResult.stdout);1131 expectType<Uint8Array>(linesBufferResult.stderr);11321133 const linesHexResult = execaSync('unicorns', {lines: true, encoding: 'hex'});1134 expectType<string>(linesHexResult.stdout);1135 expectType<string>(linesHexResult.stderr);11361137 const ignoreStdoutResult = execaSync('unicorns', {stdout: 'ignore'});1138 expectType<undefined>(ignoreStdoutResult.stdout);1139 expectType<undefined>(ignoreStdoutResult.stdio[1]);1140 expectType<string>(ignoreStdoutResult.stderr);
59 unmodified lines
1200 expectType<Uint8Array>(execaBufferError.stderr);1201 expectType<Uint8Array>(execaBufferError.stdio[2]);1202 expectError(execaBufferError.all.toString());12031204 const execaLinesError = error as ExecaSyncError<{lines: true}>;1205 expectType<string[]>(execaLinesError.stdout);1206 expectType<string[]>(execaLinesError.stderr);12071208 const execaLinesBufferError = error as ExecaSyncError<{lines: true; encoding: 'buffer'}>;1209 expectType<Uint8Array>(execaLinesBufferError.stdout);1210 expectType<Uint8Array>(execaLinesBufferError.stderr);12111212 const ignoreStdoutError = error as ExecaSyncError<{stdout: 'ignore'}>;1213 expectType<undefined>(ignoreStdoutError.stdout);1214 expectType<undefined>(ignoreStdoutError.stdio[1]);1215 expectType<string>(ignoreStdoutError.stderr);
83 unmodified lines
1299execaSync('unicorns', {inputFile: fileUrl});1300expectError(execa('unicorns', {inputFile: false}));1301expectError(execaSync('unicorns', {inputFile: false}));1302execa('unicorns', {lines: false});1284expectError(execaSync('unicorns', {lines: false}));1303execaSync('unicorns', {lines: false});1304expectError(execa('unicorns', {lines: 'false'}));1305expectError(execaSync('unicorns', {lines: 'false'}));1306execa('unicorns', {reject: false});1307execaSync('unicorns', {reject: false});
2409 unmodified lines
modified:readme.md+1 added-1 removed
317 unmodified lines
318Same as [`execa()`](#execafile-arguments-options) but synchronous.319320Returns or throws a [`subprocessResult`](#subprocessResult). The [`subprocess`](#subprocess) is not returned: its methods and properties are not available. This includes [`.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal), [`.pid`](https://nodejs.org/api/child_process.html#subprocesspid), [`.pipe()`](#pipefile-arguments-options), [`.iterable()`](#iterablereadableoptions), [`.readable()`](#readablereadableoptions), [`.writable()`](#writablewritableoptions), [`.duplex()`](#duplexduplexoptions) and the [`.stdin`/`.stdout`/`.stderr`](https://nodejs.org/api/child_process.html#subprocessstdout) streams.321322Cannot use the following options: [`all`](#all-2), [`cleanup`](#cleanup), [`buffer`](#buffer), [`detached`](#detached), [`ipc`](#ipc), [`serialization`](#serialization), [`cancelSignal`](#cancelsignal), [`forceKillAfterDelay`](#forcekillafterdelay) and [`lines`](#lines). Also, the [`stdin`](#stdin), [`stdout`](#stdout-1), [`stderr`](#stderr-1) and [`stdio`](#stdio-1) cannot be a [`['pipe', 'inherit']`](#redirect-stdinstdoutstderr-to-multiple-destinations) array, [`'overlapped'`](https://nodejs.org/api/child_process.html#optionsstdio), an async iterable, an async [transform](docs/transform.md), a [`Duplex`](docs/transform.md#duplextransform-streams), or a web stream. Node.js streams [must have a file descriptor](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr) unless the `input` option is used.322Cannot use the following options: [`all`](#all-2), [`cleanup`](#cleanup), [`buffer`](#buffer), [`detached`](#detached), [`ipc`](#ipc), [`serialization`](#serialization), [`cancelSignal`](#cancelsignal) and [`forceKillAfterDelay`](#forcekillafterdelay). Also, the [`stdin`](#stdin), [`stdout`](#stdout-1), [`stderr`](#stderr-1) and [`stdio`](#stdio-1) cannot be a [`['pipe', 'inherit']`](#redirect-stdinstdoutstderr-to-multiple-destinations) array, [`'overlapped'`](https://nodejs.org/api/child_process.html#optionsstdio), an async iterable, an async [transform](docs/transform.md), a [`Duplex`](docs/transform.md#duplextransform-streams), or a web stream. Node.js streams [must have a file descriptor](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr) unless the `input` option is used.323324#### $(file, arguments?, options?)325326`file`: `string | URL`\
899 unmodified lines