Skip to content
Myr

Fix `execaSync()` returning `undefined` output when the subprocess fails to spawn

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

Fixes #1263

authored by Sindre Sorhus · committed by Sindre Sorhus · parent 93bddc4 · Browse files · 2 files+27 added−6 removed
This commit

State

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

Diff stats

2 files+27 added−6 removed

  • tests:+19 added−0 removed
  • other:+8 added−6 removed

2 files+27 added−6 removed

modified:lib/io/output-sync.js+8 added-6 removed
modified:test/return/early-error.js+19 added
13 unmodified lines
14} from '../../index.js';15import {setFixtureDirectory} from '../helpers/fixtures-directory.js';16import {foobarString, foobarUint8Array} from '../helpers/input.js';17import {fullStdio} from '../helpers/stdio.js';18import {getOutputGenerator, convertTransformToFinal} from '../helpers/generator.js';19import {20 earlyErrorOptions,21 getEarlyErrorSubprocess,22 getEarlyErrorSubprocessSync,
20 unmodified lines
43 execaSync('foo');44 }, {message: ENOENT_REGEXP});45});4647// The subprocess never started, so its output is empty, but it must have the same shape as with the asynchronous methods48const testSpawnFailureOutput = async options => {49 const {stdio, all} = await execa('nonexistent-command-for-execa', {...options, reject: false});50 const {stdio: stdioSync, all: allSync} = execaSync('nonexistent-command-for-execa', {...options, reject: false});51 assert.deepEqual(stdioSync, stdio);52 assert.deepEqual(allSync, all);53};5455test('execaSync() output is empty when the command does not exist', () => testSpawnFailureOutput({}));56test('execaSync() output is empty when the command does not exist, with encoding: buffer', () => testSpawnFailureOutput({encoding: 'buffer'}));57test('execaSync() output is empty when the command does not exist, with lines: true', () => testSpawnFailureOutput({lines: true}));58test('execaSync() output is empty when the command does not exist, with all: true', () => testSpawnFailureOutput({all: true}));59test('execaSync() output is empty when the command does not exist, with an additional file descriptor', () => testSpawnFailureOutput(fullStdio));60test('execaSync() output is undefined when the command does not exist, with stdout: ignore', () => testSpawnFailureOutput({stdout: 'ignore'}));61test('execaSync() output is undefined when the command does not exist, with buffer: false', () => testSpawnFailureOutput({buffer: false}));62test('execaSync() output is empty when the cwd does not exist', () => testSpawnFailureOutput({cwd: '/nonexistent-directory-for-execa'}));63test('execaSync() output runs the final of transforms when the command does not exist', () => testSpawnFailureOutput({stdout: convertTransformToFinal(getOutputGenerator(foobarString)(), true)}));6465const testEarlyErrorShape = async reject => {66 const subprocess = getEarlyErrorSubprocess({reject});67 assert.doesNotThrow(() => {68 subprocess.catch(() => {});
211 unmodified lines