Skip to content
Myr

Fix passing `undefined` options (#712)

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

authored by ehmicky · committed by GitHub · parent ed8b2ce · Browse files · 2 files+51 added−26 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+51 added−26 removed

  • tests:+13 added−7 removed
  • other:+38 added−19 removed

2 files+51 added−26 removed

modified:test/test.js+13 added-7 removed
74 unmodified lines
75});7677const testStripFinalNewline = async (t, index, stripFinalNewline, execaCommand) => {78 const {stdio} = await execaCommand('noop-fd.js', [`${index}`, 'foobar\n'], {...fullStdio, stripFinalNewline});79 t.is(stdio[index], `foobar${stripFinalNewline ? '' : '\n'}`);79 t.is(stdio[index], `foobar${stripFinalNewline === false ? '\n' : ''}`);80};8182test('stripFinalNewline: true with stdout', testStripFinalNewline, 1, undefined, execa);82test('stripFinalNewline: undefined with stdout', testStripFinalNewline, 1, undefined, execa);83test('stripFinalNewline: true with stdout', testStripFinalNewline, 1, true, execa);84test('stripFinalNewline: false with stdout', testStripFinalNewline, 1, false, execa);84test('stripFinalNewline: true with stderr', testStripFinalNewline, 2, undefined, execa);85test('stripFinalNewline: undefined with stderr', testStripFinalNewline, 2, undefined, execa);86test('stripFinalNewline: true with stderr', testStripFinalNewline, 2, true, execa);87test('stripFinalNewline: false with stderr', testStripFinalNewline, 2, false, execa);86test('stripFinalNewline: true with stdio[*]', testStripFinalNewline, 3, undefined, execa);88test('stripFinalNewline: undefined with stdio[*]', testStripFinalNewline, 3, undefined, execa);89test('stripFinalNewline: true with stdio[*]', testStripFinalNewline, 3, true, execa);90test('stripFinalNewline: false with stdio[*]', testStripFinalNewline, 3, false, execa);88test('stripFinalNewline: true with stdout - sync', testStripFinalNewline, 1, undefined, execaSync);91test('stripFinalNewline: undefined with stdout - sync', testStripFinalNewline, 1, undefined, execaSync);92test('stripFinalNewline: true with stdout - sync', testStripFinalNewline, 1, true, execaSync);93test('stripFinalNewline: false with stdout - sync', testStripFinalNewline, 1, false, execaSync);90test('stripFinalNewline: true with stderr - sync', testStripFinalNewline, 2, undefined, execaSync);94test('stripFinalNewline: undefined with stderr - sync', testStripFinalNewline, 2, undefined, execaSync);95test('stripFinalNewline: true with stderr - sync', testStripFinalNewline, 2, true, execaSync);96test('stripFinalNewline: false with stderr - sync', testStripFinalNewline, 2, false, execaSync);92test('stripFinalNewline: true with stdio[*] - sync', testStripFinalNewline, 3, undefined, execaSync);97test('stripFinalNewline: undefined with stdio[*] - sync', testStripFinalNewline, 3, undefined, execaSync);98test('stripFinalNewline: true with stdio[*] - sync', testStripFinalNewline, 3, true, execaSync);99test('stripFinalNewline: false with stdio[*] - sync', testStripFinalNewline, 3, false, execaSync);100101test('stripFinalNewline is not used in objectMode', async t => {102 const {stdout} = await execa('noop-fd.js', ['1', 'foobar\n'], {stripFinalNewline: true, stdout: noopGenerator(true)});
214 unmodified lines
modified:index.js+38 added-19 removed
47 unmodified lines
48 const escapedCommand = getEscapedCommand(filePath, rawArgs);4950 const {command: file, args, options: initialOptions} = crossSpawn._parse(filePath, rawArgs, rawOptions);5152 const options = {53 maxBuffer: DEFAULT_MAX_BUFFER,54 buffer: true,55 stripFinalNewline: true,56 extendEnv: true,57 preferLocal: false,58 localDir: initialOptions.cwd || process.cwd(),59 execPath: process.execPath,60 encoding: 'utf8',61 reject: true,62 cleanup: true,63 all: false,64 windowsHide: true,65 verbose: verboseDefault,66 killSignal: 'SIGTERM',67 ...initialOptions,68 shell: normalizeFileUrl(initialOptions.shell),69 };7052 const options = addDefaultOptions(initialOptions);53 options.shell = normalizeFileUrl(options.shell);54 options.env = getEnv(options);5556 if (process.platform === 'win32' && path.basename(file, '.exe') === 'cmd') {57 // #116
4 unmodified lines
6263 return {file, args, command, escapedCommand, options};64};6566const addDefaultOptions = ({67 maxBuffer = DEFAULT_MAX_BUFFER,68 buffer = true,69 stripFinalNewline = true,70 extendEnv = true,71 preferLocal = false,72 cwd = process.cwd(),73 localDir = cwd,74 execPath = process.execPath,75 encoding = 'utf8',76 reject = true,77 cleanup = true,78 all = false,79 windowsHide = true,80 verbose = verboseDefault,81 killSignal = 'SIGTERM',82 ...options83}) => ({84 ...options,85 maxBuffer,86 buffer,87 stripFinalNewline,88 extendEnv,89 preferLocal,90 cwd,91 localDir,92 execPath,93 encoding,94 reject,95 cleanup,96 all,97 windowsHide,98 verbose,99 killSignal,100});101102const handleOutput = (options, value) => {103 if (value === undefined || value === null) {104 return;105 }
234 unmodified lines