Re-order return value properties (#801)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent 3bd96ba · Browse files · 4 files·+92 added−49 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+92 added−49 removed
- tests:+41 added−0 removed
- other:+51 added−49 removed
Provenance
- Commit
72836f3- Tree
246ecbb- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
3bd96ba
4 files changed+92 added−49 removed
modified:lib/error.js+9 added-7 removed
82 unmodified lines8384858687888990919293949590969798939910010110210310410510610710810910310410510610711011111211382 unmodified lines
error.shortMessage = shortMessage; error.command = command; error.escapedCommand = escapedCommand; error.cwd = cwd;
error.failed = true; error.timedOut = Boolean(timedOut); error.isCanceled = isCanceled; error.isTerminated = signal !== undefined; error.exitCode = exitCode; error.signal = signal; error.signalDescription = signalDescription; error.stdio = stdio;
error.stdout = stdio[1]; error.stderr = stdio[2]; error.cwd = cwd;
if (all !== undefined) { error.all = all; }
error.stdio = stdio;
if ('bufferedData' in error) { delete error.bufferedData; }
error.failed = true; error.timedOut = Boolean(timedOut); error.isCanceled = isCanceled; error.isTerminated = signal !== undefined;
return error;};
const previousErrors = new WeakSet();modified:test/error.js+41 added
10 unmodified lines11 setFixtureDir();12 13 const TIMEOUT_REGEXP = /timed out after/;14 15+test('Return value properties are not missing and are ordered', async t => {16+ const result = await execa('empty.js', {...fullStdio, all: true});17+ t.deepEqual(Reflect.ownKeys(result), [18+ 'command',19+ 'escapedCommand',20+ 'failed',21+ 'timedOut',22+ 'isCanceled',23+ 'isTerminated',24+ 'exitCode',25+ 'stdout',26+ 'stderr',27+ 'all',28+ 'stdio',29+ ]);30+});31+32+test('Error properties are not missing and are ordered', async t => {33+ const error = await t.throwsAsync(execa('fail.js', {...fullStdio, all: true}));34+ t.deepEqual(Reflect.ownKeys(error), [35+ 'stack',36+ 'message',37+ 'originalMessage',38+ 'shortMessage',39+ 'command',40+ 'escapedCommand',41+ 'cwd',42+ 'failed',43+ 'timedOut',44+ 'isCanceled',45+ 'isTerminated',46+ 'exitCode',47+ 'signal',48+ 'signalDescription',49+ 'stdout',50+ 'stderr',51+ 'all',52+ 'stdio',53+ ]);54+});55+56 const testEmptyErrorStdio = async (t, execaMethod) => {57 const {failed, stdout, stderr, stdio} = await execaMethod('fail.js', {reject: false});58 t.true(failed);59 t.is(stdout, '');340 unmodified linesmodified:index.js+9 added-9 removed
208 unmodified lines209 210 return {211 command,212 escapedCommand,213- exitCode: 0,214- stdio,215- stdout: stdio[1],216- stderr: stdio[2],217- all,213 failed: false,214 timedOut: false,215 isCanceled: false,216 isTerminated: false,217+ exitCode: 0,218+ stdout: stdio[1],219+ stderr: stdio[2],220+ all,221+ stdio,222 };223 };224 225 export function execaSync(rawFile, rawArgs, rawOptions) {50 unmodified lines276 277 return {278 command,279 escapedCommand,280- exitCode: 0,281- stdio,282- stdout: stdio[1],283- stderr: stdio[2],280 failed: false,281 timedOut: false,282 isCanceled: false,283 isTerminated: false,284+ exitCode: 0,285+ stdout: stdio[1],286+ stderr: stdio[2],287+ stdio,288 };289 }290 291 const validateSyncOptions = ({ipc}) => {69 unmodified linesmodified:readme.md+33 added-33 removed
360 unmodified lines361 362 This is meant to be copied and pasted into a shell, for debugging purposes.363 Since the escaping is fairly basic, this should not be executed directly as a process, including using [`execa()`](#execafile-arguments-options) or [`execaCommand()`](#execacommandcommand-options).364 365-#### exitCode365+#### cwd366 367-Type: `number | undefined`367+Type: `string`368 369-The numeric exit code of the process that was run.369+The `cwd` of the command if provided in the [command options](#cwd-1). Otherwise it is `process.cwd()`.370 371-This is `undefined` when the process could not be spawned or was terminated by a [signal](#signal-1).372-371 #### stdout372 373 Type: `string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined`374 28 unmodified lines403 The output of the process on [`stdin`](#stdin), [`stdout`](#stdout-1), [`stderr`](#stderr-1) and [other file descriptors](#stdio-1).404 405 Items are `undefined` when their corresponding [`stdio`](#stdio-1) option is set to [`'inherit'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio). Items are arrays when their corresponding `stdio` option is a [transform in object mode](docs/transform.md#object-mode).406 407+#### message408+409+Type: `string`410+411+Error message when the child process failed to run. In addition to the [underlying error message](#originalMessage), it also contains some information related to why the child process errored.412+413+The child process [`stderr`](#stderr), [`stdout`](#stdout) and other [file descriptors' output](#stdio) are appended to the end, separated with newlines and not interleaved.414+415+#### shortMessage416+417+Type: `string`418+419+This is the same as the [`message` property](#message) except it does not include the child process [`stdout`](#stdout)/[`stderr`](#stderr)/[`stdio`](#stdio).420+421+#### originalMessage422+423+Type: `string | undefined`424+425+Original error message. This is the same as the `message` property excluding the child process [`stdout`](#stdout)/[`stderr`](#stderr)/[`stdio`](#stdio) and some additional information added by Execa.426+427+This is `undefined` unless the child process exited due to an `error` event or a timeout.428+429 #### failed430 431 Type: `boolean`432 18 unmodified lines451 Whether the process was terminated by a signal (like `SIGTERM`) sent by either:452 - The current process.453 - Another process. This case is [not supported on Windows](https://nodejs.org/api/process.html#signal-events).454 455+#### exitCode456+457+Type: `number | undefined`458+459+The numeric exit code of the process that was run.460+461+This is `undefined` when the process could not be spawned or was terminated by a [signal](#signal-1).462+463 #### signal464 465 Type: `string | undefined`466 10 unmodified lines477 A human-friendly description of the signal that was used to terminate the process. For example, `Floating point arithmetic error`.478 479 If a signal terminated the process, this property is defined and included in the error message. Otherwise it is `undefined`. It is also `undefined` when the signal is very uncommon which should seldomly happen.480 453-#### cwd454-455-Type: `string`456-457-The `cwd` of the command if provided in the [command options](#cwd-1). Otherwise it is `process.cwd()`.458-459-#### message460-461-Type: `string`462-463-Error message when the child process failed to run. In addition to the [underlying error message](#originalMessage), it also contains some information related to why the child process errored.464-465-The child process [`stderr`](#stderr), [`stdout`](#stdout) and other [file descriptors' output](#stdio) are appended to the end, separated with newlines and not interleaved.466-467-#### shortMessage468-469-Type: `string`470-471-This is the same as the [`message` property](#message) except it does not include the child process [`stdout`](#stdout)/[`stderr`](#stderr)/[`stdio`](#stdio).472-473-#### originalMessage474-475-Type: `string | undefined`476-477-Original error message. This is the same as the `message` property excluding the child process [`stdout`](#stdout)/[`stderr`](#stderr)/[`stdio`](#stdio) and some additional information added by Execa.478-479-This is `undefined` unless the child process exited due to an `error` event or a timeout.480-481 ### options482 483 Type: `object`484 465 unmodified lines