Skip to content
Myr

Add support for `verbose` option to `execaSync()` (#950)

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

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

  • tests:+25 added−15 removed
  • other:+11 added−10 removed

5 files+36 added−25 removed

modified:lib/stdio/handle.js+1 added-1 removed
modified:lib/verbose/output.js+7 added-6 removed
modified:test/verbose/output.js+25 added-15 removed
27 unmodified lines
28 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);29};3031test('Prints stdout, verbose "full"', testPrintOutput, 1, nestedExecaAsync);32test('Prints stdout, verbose "full", sync', testPrintOutput, 1, nestedExecaSync);33test('Prints stderr, verbose "full"', testPrintOutput, 2, nestedExecaAsync);34test('Prints stderr, verbose "full", sync', testPrintOutput, 2, nestedExecaSync);3536const testNoPrintOutput = async (t, verbose, fdNumber, execaMethod) => {37 const {stderr} = await execaMethod('noop-fd.js', [`${fdNumber}`, foobarString], {verbose, ...fullStdio});38 t.is(getOutputLine(stderr), undefined);39};4041test('Does not print stdout, verbose "none"', testNoPrintOutput, 'none', 1, nestedExecaAsync);42test('Does not print stdout, verbose "short"', testNoPrintOutput, 'short', 1, nestedExecaAsync);41test('Does not print stdout, verbose "full", sync', testNoPrintOutput, 'full', 1, nestedExecaSync);43test('Does not print stdout, verbose "none", sync', testNoPrintOutput, 'none', 1, nestedExecaSync);44test('Does not print stdout, verbose "short", sync', testNoPrintOutput, 'short', 1, nestedExecaSync);45test('Does not print stderr, verbose "none"', testNoPrintOutput, 'none', 2, nestedExecaAsync);46test('Does not print stderr, verbose "short"', testNoPrintOutput, 'short', 2, nestedExecaAsync);46test('Does not print stderr, verbose "full", sync', testNoPrintOutput, 'full', 2, nestedExecaSync);47test('Does not print stderr, verbose "none", sync', testNoPrintOutput, 'none', 2, nestedExecaSync);48test('Does not print stderr, verbose "short", sync', testNoPrintOutput, 'short', 2, nestedExecaSync);49test('Does not print stdio[*], verbose "none"', testNoPrintOutput, 'none', 3, nestedExecaAsync);50test('Does not print stdio[*], verbose "short"', testNoPrintOutput, 'short', 3, nestedExecaAsync);
1 unmodified line
52test('Does not print stdio[*], verbose "none", sync', testNoPrintOutput, 'none', 3, nestedExecaSync);53test('Does not print stdio[*], verbose "short", sync', testNoPrintOutput, 'short', 3, nestedExecaSync);54test('Does not print stdio[*], verbose "full", sync', testNoPrintOutput, 'full', 3, nestedExecaSync);5556test('Prints stdout after errors', async t => {57 const stderr = await runErrorSubprocess(t, 'full', nestedExecaAsync);56const testPrintError = async (t, execaMethod) => {57 const stderr = await runErrorSubprocess(t, 'full', execaMethod);58 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);59});59};6061test('Prints stdout after errors', testPrintError, nestedExecaAsync);62test('Prints stdout after errors, sync', testPrintError, nestedExecaSync);6364const testPipeOutput = async (t, fixtureName, sourceVerbose, destinationVerbose) => {65 const {stderr} = await execa(`nested-pipe-${fixtureName}.js`, [66 JSON.stringify(getVerboseOption(sourceVerbose, 'full')),67 'noop.js',
118 unmodified lines
186 subprocess.kill();187 await t.throwsAsync(subprocess);188});189187test('Prints stdout, single newline', async t => {188 const {stderr} = await nestedExecaAsync('noop-fd.js', ['1', '\n'], {verbose: 'full'});190const testSingleNewline = async (t, execaMethod) => {191 const {stderr} = await execaMethod('noop-fd.js', ['1', '\n'], {verbose: 'full'});192 t.deepEqual(getOutputLines(stderr), [`${testTimestamp} [0] `]);190});193};194195test('Prints stdout, single newline', testSingleNewline, nestedExecaAsync);196test('Prints stdout, single newline, sync', testSingleNewline, nestedExecaSync);197198test('Can use encoding UTF16, verbose "full"', async t => {199 const {stderr} = await nestedExeca('nested-input.js', 'stdin.js', {verbose: 'full', encoding: 'utf16le'});200 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);201});
25 unmodified lines
227228test('Does not print stdout, stdout { file }', testStdoutFile, 'nested.js', file => ({file}));229test('Does not print stdout, stdout fileUrl', testStdoutFile, 'nested-file-url.js', file => file);230225const testPrintOutputOptions = async (t, options) => {226 const {stderr} = await nestedExecaAsync('noop.js', [foobarString], {verbose: 'full', ...options});231const testPrintOutputOptions = async (t, options, execaMethod) => {232 const {stderr} = await execaMethod('noop.js', [foobarString], {verbose: 'full', ...options});233 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);234};235230test('Prints stdout, stdout "pipe"', testPrintOutputOptions, {stdout: 'pipe'});231test('Prints stdout, stdout "overlapped"', testPrintOutputOptions, {stdout: 'overlapped'});232test('Prints stdout, stdout null', testPrintOutputOptions, {stdout: null});233test('Prints stdout, stdout ["pipe"]', testPrintOutputOptions, {stdout: ['pipe']});234test('Prints stdout, buffer false', testPrintOutputOptions, {buffer: false});236test('Prints stdout, stdout "pipe"', testPrintOutputOptions, {stdout: 'pipe'}, nestedExecaAsync);237test('Prints stdout, stdout "overlapped"', testPrintOutputOptions, {stdout: 'overlapped'}, nestedExecaAsync);238test('Prints stdout, stdout null', testPrintOutputOptions, {stdout: null}, nestedExecaAsync);239test('Prints stdout, stdout ["pipe"]', testPrintOutputOptions, {stdout: ['pipe']}, nestedExecaAsync);240test('Prints stdout, buffer false', testPrintOutputOptions, {buffer: false}, nestedExecaAsync);241test('Prints stdout, stdout "pipe", sync', testPrintOutputOptions, {stdout: 'pipe'}, nestedExecaSync);242test('Prints stdout, stdout null, sync', testPrintOutputOptions, {stdout: null}, nestedExecaSync);243test('Prints stdout, stdout ["pipe"], sync', testPrintOutputOptions, {stdout: ['pipe']}, nestedExecaSync);244test('Prints stdout, buffer false, sync', testPrintOutputOptions, {buffer: false}, nestedExecaSync);245246const testPrintOutputFixture = async (t, fixtureName, ...args) => {247 const {stderr} = await nestedExeca(fixtureName, 'noop.js', [foobarString, ...args], {verbose: 'full'});248 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);
4 unmodified lines
modified:index.d.ts+2 added-2 removed
1401 unmodified lines
1402Same as `execa()` but synchronous.14031404Returns 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.14051406Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `ipc`, `serialization`, `cancelSignal`, `forceKillAfterDelay`, `lines` and `verbose: 'full'`. 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.1406Cannot 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.14071408@param file - The program/script to execute, as a string or file URL1409@param arguments - Arguments to pass to `file` on execution.1410@returns A `subprocessResult` object
105 unmodified lines
1516Same as `execaCommand()` but synchronous.15171518Returns 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.15191520Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `ipc`, `serialization`, `cancelSignal`, `forceKillAfterDelay`, `lines` and `verbose: 'full'`. 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.1520Cannot 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.15211522@param command - The program/script to execute and its arguments.1523@returns A `subprocessResult` object1524@throws A `subprocessResult` error
128 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), [`lines`](#lines) and [`verbose: 'full'`](#verbose). 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), [`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.323324#### $(file, arguments?, options?)325326`file`: `string | URL`\
899 unmodified lines