Refactor test helpers for the `verbose` option (#1128)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent 37e0024 · Browse files · 41 files·+712 added−709 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
41 files+712 added−709 removed
- tests:+712 added−709 removed
Provenance
- Commit
18d320f- Tree
997c3ed- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
37e0024
41 files changed+712 added−709 removed
added:test/fixtures/nested/file-url.js+3 added
123import {pathToFileURL} from 'node:url';
export const getOptions = ({stdout: {file}}) => ({stdout: pathToFileURL(file)});added:test/fixtures/nested/generator-big-array.js+4 added
1234import {getOutputGenerator} from '../../helpers/generator.js';
const bigArray = Array.from({length: 100}, (_, index) => index);export const getOptions = () => ({stdout: getOutputGenerator(bigArray)(true)});added:test/fixtures/nested/generator-duplex.js+3 added
123import {uppercaseBufferDuplex} from '../../helpers/duplex.js';
export const getOptions = () => ({stdout: uppercaseBufferDuplex()});added:test/fixtures/nested/generator-object.js+3 added
123import {outputObjectGenerator} from '../../helpers/generator.js';
export const getOptions = () => ({stdout: outputObjectGenerator()});added:test/fixtures/nested/generator-string-object.js+4 added
1234import {getOutputGenerator} from '../../helpers/generator.js';import {simpleFull} from '../../helpers/lines.js';
export const getOptions = () => ({stdout: getOutputGenerator(simpleFull)(true)});added:test/fixtures/nested/generator-uppercase.js+3 added
123import {uppercaseGenerator} from '../../helpers/generator.js';
export const getOptions = () => ({stdout: uppercaseGenerator()});added:test/fixtures/nested/writable-web.js+1 added
1export const getOptions = () => ({stdout: new WritableStream()});added:test/fixtures/nested/writable.js+3 added
123import process from 'node:process';
export const getOptions = () => ({stdout: process.stdout});modified:test/fixtures/nested-double.js+4 added-5 removed
1 #!/usr/bin/env node2-import process from 'node:process';3-import {execa} from '../../index.js';2+import {execa, getOneMessage} from '../../index.js';3 5-const [options, file, ...commandArguments] = process.argv.slice(2);4+const {file, commandArguments, options} = await getOneMessage();5 const firstArguments = commandArguments.slice(0, -1);6 const lastArgument = commandArguments.at(-1);7 await Promise.all([9- execa(file, [...firstArguments, lastArgument], JSON.parse(options)),10- execa(file, [...firstArguments, lastArgument.toUpperCase()], JSON.parse(options)),8+ execa(file, [...firstArguments, lastArgument], options),9+ execa(file, [...firstArguments, lastArgument.toUpperCase()], options),10 ]);modified:test/fixtures/nested-fail.js+3 added-4 removed
1 #!/usr/bin/env node2-import process from 'node:process';3-import {execa} from '../../index.js';2+import {execa, getOneMessage} from '../../index.js';3 5-const [options, file, ...commandArguments] = process.argv.slice(2);6-const subprocess = execa(file, commandArguments, JSON.parse(options));4+const {file, commandArguments, options} = await getOneMessage();5+const subprocess = execa(file, commandArguments, options);6 subprocess.kill(new Error(commandArguments[0]));7 await subprocess;deleted:test/fixtures/nested-file-url.js-8 removed
1-#!/usr/bin/env node2-import process from 'node:process';3-import {pathToFileURL} from 'node:url';4-import {execa} from '../../index.js';5-6-const [options, file, commandArgument] = process.argv.slice(2);7-const parsedOptions = JSON.parse(options);8-await execa(file, [commandArgument], {...parsedOptions, stdout: pathToFileURL(parsedOptions.stdout)});deleted:test/fixtures/nested-input.js-12 removed
1-#!/usr/bin/env node2-import process from 'node:process';3-import {execa, execaSync} from '../../index.js';4-import {foobarUtf16Uint8Array} from '../helpers/input.js';5-6-const [optionsString, file, isSync, ...commandArguments] = process.argv.slice(2);7-const options = {...JSON.parse(optionsString), input: foobarUtf16Uint8Array};8-if (isSync === 'true') {9- execaSync(file, commandArguments, options);10-} else {11- await execa(file, commandArguments, options);12-}modified:test/fixtures/nested-pipe-file.js+13 added-12 removed
1 #!/usr/bin/env node2-import process from 'node:process';3-import {execa} from '../../index.js';2+import {execa, getOneMessage} from '../../index.js';3 5-const [6- sourceOptions,7- sourceFile,8- sourceArgument,9- destinationOptions,10- destinationFile,11- destinationArgument,12-] = process.argv.slice(2);13-await execa(sourceFile, [sourceArgument], JSON.parse(sourceOptions))14- .pipe(destinationFile, destinationArgument === undefined ? [] : [destinationArgument], JSON.parse(destinationOptions));4+const {5+ file,6+ commandArguments = [],7+ options: {8+ sourceOptions = {},9+ destinationFile,10+ destinationArguments = [],11+ destinationOptions = {},12+ },13+} = await getOneMessage();14+await execa(file, commandArguments, sourceOptions)15+ .pipe(destinationFile, destinationArguments, destinationOptions);modified:test/fixtures/nested-pipe-script.js+13 added-12 removed
1 #!/usr/bin/env node2-import process from 'node:process';3-import {$} from '../../index.js';2+import {$, getOneMessage} from '../../index.js';3 5-const [6- sourceOptions,7- sourceFile,8- sourceArgument,9- destinationOptions,10- destinationFile,11- destinationArgument,12-] = process.argv.slice(2);13-await $(JSON.parse(sourceOptions))`${sourceFile} ${sourceArgument}`14- .pipe(JSON.parse(destinationOptions))`${destinationFile} ${destinationArgument === undefined ? [] : [destinationArgument]}`;4+const {5+ file,6+ commandArguments = [],7+ options: {8+ sourceOptions = {},9+ destinationFile,10+ destinationArguments = [],11+ destinationOptions = {},12+ },13+} = await getOneMessage();14+await $(sourceOptions)`${file} ${commandArguments}`15+ .pipe(destinationOptions)`${destinationFile} ${destinationArguments}`;modified:test/fixtures/nested-pipe-stream.js+4 added-4 removed
1 #!/usr/bin/env node2 import process from 'node:process';3-import {execa} from '../../index.js';3+import {execa, getOneMessage} from '../../index.js';4 5-const [options, file, commandArgument, unpipe] = process.argv.slice(2);6-const subprocess = execa(file, [commandArgument], JSON.parse(options));5+const {file, commandArguments, options: {unpipe, ...options}} = await getOneMessage();6+const subprocess = execa(file, commandArguments, options);7 subprocess.stdout.pipe(process.stdout);8-if (unpipe === 'true') {8+if (unpipe) {9 subprocess.stdout.unpipe(process.stdout);10 }11 12 await subprocess;modified:test/fixtures/nested-pipe-subprocess.js+8 added-7 removed
1 #!/usr/bin/env node2-import process from 'node:process';3-import {execa} from '../../index.js';2+import {execa, getOneMessage} from '../../index.js';3 5-const [options, file, commandArgument, unpipe] = process.argv.slice(2);6-const source = execa(file, [commandArgument], JSON.parse(options));4+const {file, commandArguments, options: {unpipe, ...options}} = await getOneMessage();5+const source = execa(file, commandArguments, options);6 const destination = execa('stdin.js');7 const controller = new AbortController();9-const pipePromise = source.pipe(destination, {unpipeSignal: controller.signal});10-if (unpipe === 'true') {8+const subprocess = source.pipe(destination, {unpipeSignal: controller.signal});9+if (unpipe) {10 controller.abort();11 destination.stdin.end();12 }13 15-await Promise.allSettled([source, destination, pipePromise]);14+try {15+ await subprocess;16+} catch {}modified:test/fixtures/nested-pipe-subprocesses.js+13 added-12 removed
1 #!/usr/bin/env node2-import process from 'node:process';3-import {execa} from '../../index.js';2+import {execa, getOneMessage} from '../../index.js';3 5-const [6- sourceOptions,7- sourceFile,8- sourceArgument,9- destinationOptions,10- destinationFile,11- destinationArgument,12-] = process.argv.slice(2);13-await execa(sourceFile, [sourceArgument], JSON.parse(sourceOptions))14- .pipe(execa(destinationFile, destinationArgument === undefined ? [] : [destinationArgument], JSON.parse(destinationOptions)));4+const {5+ file,6+ commandArguments = [],7+ options: {8+ sourceOptions = {},9+ destinationFile,10+ destinationArguments = [],11+ destinationOptions = {},12+ },13+} = await getOneMessage();14+await execa(file, commandArguments, sourceOptions)15+ .pipe(execa(destinationFile, destinationArguments, destinationOptions));deleted:test/fixtures/nested-sync.js-11 removed
1-#!/usr/bin/env node2-import process from 'node:process';3-import {execaSync, sendMessage} from '../../index.js';4-5-const [options, file, ...commandArguments] = process.argv.slice(2);6-try {7- const result = execaSync(file, commandArguments, JSON.parse(options));8- await sendMessage({result});9-} catch (error) {10- await sendMessage({error});11-}deleted:test/fixtures/nested-transform.js-34 removed
1-#!/usr/bin/env node2-import process from 'node:process';3-import {execa, execaSync} from '../../index.js';4-import {generatorsMap} from '../helpers/map.js';5-import {outputObjectGenerator, getOutputGenerator} from '../helpers/generator.js';6-import {simpleFull} from '../helpers/lines.js';7-8-const getTransform = (type, transformName) => {9- if (type !== undefined) {10- return generatorsMap[type].uppercase();11- }12-13- if (transformName === 'object') {14- return outputObjectGenerator();15- }16-17- if (transformName === 'stringObject') {18- return getOutputGenerator(simpleFull)(true);19- }20-21- if (transformName === 'bigArray') {22- const bigArray = Array.from({length: 100}, (_, index) => index);23- return getOutputGenerator(bigArray)(true);24- }25-};26-27-const [optionsString, file, ...commandArguments] = process.argv.slice(2);28-const {type, transformName, isSync, ...options} = JSON.parse(optionsString);29-const newOptions = {stdout: getTransform(type, transformName), ...options};30-if (isSync) {31- execaSync(file, commandArguments, newOptions);32-} else {33- await execa(file, commandArguments, newOptions);34-}deleted:test/fixtures/nested-writable-web.js-6 removed
1-#!/usr/bin/env node2-import process from 'node:process';3-import {execa} from '../../index.js';4-5-const [options, file, commandArgument] = process.argv.slice(2);6-await execa(file, [commandArgument], {...JSON.parse(options), stdout: new WritableStream()});deleted:test/fixtures/nested-writable.js-6 removed
1-#!/usr/bin/env node2-import process from 'node:process';3-import {execa} from '../../index.js';4-5-const [options, file, commandArgument] = process.argv.slice(2);6-await execa(file, [commandArgument], {...JSON.parse(options), stdout: process.stdout});modified:test/fixtures/nested.js+29 added-6 removed
1 #!/usr/bin/env node2-import process from 'node:process';3-import {execa, sendMessage} from '../../index.js';2+import {3+ execa,4+ execaSync,5+ getOneMessage,6+ sendMessage,7+} from '../../index.js';8 5-const [options, file, ...commandArguments] = process.argv.slice(2);9+const {10+ isSync,11+ file,12+ commandArguments,13+ options,14+ optionsFixture,15+ optionsInput,16+} = await getOneMessage();17+18+let commandOptions = options;19+20+// Some subprocess options cannot be serialized between processes.21+// For those, we pass a fixture filename instead, which dynamically creates the options.22+if (optionsFixture !== undefined) {23+ const {getOptions} = await import(`./nested/${optionsFixture}`);24+ commandOptions = {...commandOptions, ...getOptions({...commandOptions, ...optionsInput})};25+}26+27 try {7- const result = await execa(file, commandArguments, JSON.parse(options));8- await sendMessage({result});28+ const result = isSync29+ ? execaSync(file, commandArguments, commandOptions)30+ : await execa(file, commandArguments, commandOptions);31+ await sendMessage(result);32 } catch (error) {10- await sendMessage({error});33+ await sendMessage(error);34 }modified:test/fixtures/worker.js+6 added-10 removed
1+#!/usr/bin/env node2 import {workerData, parentPort} from 'node:worker_threads';2-import {execa} from '../../index.js';3-import {setFixtureDirectory} from '../helpers/fixtures-directory.js';3+import {spawnParentProcess} from '../helpers/nested.js';4 5-setFixtureDirectory();6-7-const {nodeFile, commandArguments, options} = workerData;5 try {9- const subprocess = execa(nodeFile, commandArguments, options);10- const [parentResult, {result, error}] = await Promise.all([subprocess, subprocess.getOneMessage()]);11- parentPort.postMessage({parentResult, result, error});12-} catch (parentError) {13- parentPort.postMessage({parentError});6+ const result = await spawnParentProcess(workerData);7+ parentPort.postMessage(result);8+} catch (error) {9+ parentPort.postMessage(error);10 }modified:test/helpers/nested.js+39 added-35 removed
3 unmodified lines4 import {FIXTURES_DIRECTORY_URL} from './fixtures-directory.js';5 6 const WORKER_URL = new URL('worker.js', FIXTURES_DIRECTORY_URL);7 8-const runWorker = (nodeFile, commandArguments, options) => {9- [commandArguments, options] = Array.isArray(commandArguments)10- ? [commandArguments, options]11- : [[], commandArguments];12- return new Worker(WORKER_URL, {workerData: {nodeFile, commandArguments, options}});8+// Like `execa(file, commandArguments, options)` but spawns inside another parent process.9+// This is useful when testing logic where Execa modifies the global state.10+// For example, when it prints to the console, with the `verbose` option.11+// The parent process calls `execa(options.parentFixture, parentOptions)`12+// When `options.isSync` is `true`, `execaSync()` is called instead.13+// When `options.worker` is `true`, the whole flow happens inside a Worker.14+export const nestedSubprocess = async (file, commandArguments, options, parentOptions) => {15+ const result = await nestedInstance(file, commandArguments, options, parentOptions);16+ const nestedResult = result.ipcOutput[0];17+ return {...result, nestedResult};18 };19 15-// eslint-disable-next-line max-params16-const nestedCall = (isWorker, fixtureName, execaMethod, file, commandArguments, options, parentOptions) => {20+export const nestedInstance = (file, commandArguments, options, parentOptions) => {21 [commandArguments, options = {}, parentOptions = {}] = Array.isArray(commandArguments)22 ? [commandArguments, options, parentOptions]23 : [[], commandArguments, options];20- const subprocessOrWorker = execaMethod(fixtureName, [JSON.stringify(options), file, ...commandArguments], {...parentOptions, ipc: true});21- const onMessage = once(subprocessOrWorker, 'message');22- const promise = getNestedResult(onMessage);23- promise.parent = isWorker ? getParentResult(onMessage) : subprocessOrWorker;24- return promise;24+ const {25+ parentFixture = 'nested.js',26+ worker = false,27+ isSync = false,28+ optionsFixture,29+ optionsInput = {},30+ ...otherOptions31+ } = options;32+ const normalizedArguments = {33+ parentFixture,34+ parentOptions,35+ isSync,36+ file,37+ commandArguments,38+ options: otherOptions,39+ optionsFixture,40+ optionsInput,41+ };42+ return worker43+ ? spawnWorker(normalizedArguments)44+ : spawnParentProcess(normalizedArguments);45 };46 27-const getNestedResult = async onMessage => {28- const {result} = await getMessage(onMessage);29- return result;30-};31-32-const getParentResult = async onMessage => {33- const {parentResult} = await getMessage(onMessage);34- return parentResult;35-};36-37-const getMessage = async onMessage => {38- const [{error, parentError = error, result, parentResult}] = await onMessage;39- if (parentError) {40- throw parentError;47+const spawnWorker = async workerData => {48+ const worker = new Worker(WORKER_URL, {workerData});49+ const [result] = await once(worker, 'message');50+ if (result instanceof Error) {51+ throw result;52 }53 43- return {result, parentResult};54+ return result;55 };56 46-export const nestedWorker = (...commandArguments) => nestedCall(true, 'nested.js', runWorker, ...commandArguments);47-const nestedExeca = (fixtureName, ...commandArguments) => nestedCall(false, fixtureName, execa, ...commandArguments);48-export const nestedExecaAsync = (...commandArguments) => nestedExeca('nested.js', ...commandArguments);49-export const nestedExecaSync = (...commandArguments) => nestedExeca('nested-sync.js', ...commandArguments);50-export const parentWorker = (...commandArguments) => nestedWorker(...commandArguments).parent;51-export const parentExeca = (...commandArguments) => nestedExeca(...commandArguments).parent;52-export const parentExecaAsync = (...commandArguments) => nestedExecaAsync(...commandArguments).parent;53-export const parentExecaSync = (...commandArguments) => nestedExecaSync(...commandArguments).parent;57+export const spawnParentProcess = ({parentFixture, parentOptions, ...ipcInput}) => execa(parentFixture, {...parentOptions, ipcInput});modified:test/helpers/verbose.js+10 added-20 removed
1 import {platform} from 'node:process';2 import {stripVTControlCharacters} from 'node:util';3 import {replaceSymbols} from 'figures';4 import {foobarString} from './input.js';5-import {nestedExecaAsync, nestedExecaSync} from './nested.js';5+import {nestedSubprocess} from './nested.js';6 7 const isWindows = platform === 'win32';8 export const QUOTE = isWindows ? '"' : '\'';9 10-const runErrorSubprocess = async (execaMethod, t, verbose, expectExitCode = true) => {11- const subprocess = execaMethod('noop-fail.js', ['1', foobarString], {verbose});12- await t.throwsAsync(subprocess);13- const {stderr} = await subprocess.parent;10+export const runErrorSubprocess = async (t, verbose, isSync = false, expectExitCode = true) => {11+ const {stderr, nestedResult} = await nestedSubprocess('noop-fail.js', ['1', foobarString], {verbose, isSync});12+ t.true(nestedResult instanceof Error);13 if (expectExitCode) {14 t.true(stderr.includes('exit code 2'));15 }16 17 return stderr;18 };19 21-export const runErrorSubprocessAsync = runErrorSubprocess.bind(undefined, nestedExecaAsync);22-export const runErrorSubprocessSync = runErrorSubprocess.bind(undefined, nestedExecaSync);23-24-const runWarningSubprocess = async (execaMethod, t) => {25- const {stderr} = await execaMethod('noop-fail.js', ['1', foobarString], {verbose: 'short', reject: false}).parent;20+export const runWarningSubprocess = async (t, isSync) => {21+ const {stderr, nestedResult} = await nestedSubprocess('noop-fail.js', ['1', foobarString], {verbose: 'short', reject: false, isSync});22+ t.true(nestedResult instanceof Error);23 t.true(stderr.includes('exit code 2'));24 return stderr;25 };26 30-export const runWarningSubprocessAsync = runWarningSubprocess.bind(undefined, nestedExecaAsync);31-export const runWarningSubprocessSync = runWarningSubprocess.bind(undefined, nestedExecaSync);32-33-const runEarlyErrorSubprocess = async (execaMethod, t) => {34- const subprocess = execaMethod('noop.js', [foobarString], {verbose: 'short', cwd: true});35- await t.throwsAsync(subprocess);36- const {stderr} = await subprocess.parent;27+export const runEarlyErrorSubprocess = async (t, isSync) => {28+ const {stderr, nestedResult} = await nestedSubprocess('noop.js', [foobarString], {verbose: 'short', cwd: true, isSync});29+ t.true(nestedResult instanceof Error);30 t.true(stderr.includes('The "cwd" option must'));31 return stderr;32 };33 41-export const runEarlyErrorSubprocessAsync = runEarlyErrorSubprocess.bind(undefined, nestedExecaAsync);42-export const runEarlyErrorSubprocessSync = runEarlyErrorSubprocess.bind(undefined, nestedExecaSync);43-34 export const getCommandLine = stderr => getCommandLines(stderr)[0];35 export const getCommandLines = stderr => getNormalizedLines(stderr).filter(line => isCommandLine(line));36 const isCommandLine = line => line.includes(' $ ') || line.includes(' | ');37 export const getOutputLine = stderr => getOutputLines(stderr)[0];33 unmodified linesmodified:test/stdio/duplicate.js+5 added-5 removed
15 unmodified lines16 import {appendDuplex} from '../helpers/duplex.js';17 import {appendWebTransform} from '../helpers/web-transform.js';18 import {foobarString, foobarUint8Array, foobarUppercase} from '../helpers/input.js';19 import {fullStdio} from '../helpers/stdio.js';20-import {nestedExecaAsync, nestedExecaSync} from '../helpers/nested.js';20+import {nestedSubprocess} from '../helpers/nested.js';21 import {getAbsolutePath} from '../helpers/file-path.js';22 import {noopDuplex} from '../helpers/stream.js';23 24 setFixtureDirectory();119 unmodified lines144 test('Can re-use same native Writable stream on different output file descriptors', testMultipleStreamOutput, getNativeStream);145 test('Can re-use same non-native Writable stream on different output file descriptors', testMultipleStreamOutput, getNonNativeStream);146 test('Can re-use same web Writable stream on different output file descriptors', testMultipleStreamOutput, getWebWritableStream);147 148-const testMultipleInheritOutput = async (t, execaMethod) => {149- const {stdout} = await execaMethod('noop-both.js', [foobarString], getDifferentOutputs(1)).parent;148+const testMultipleInheritOutput = async (t, isSync) => {149+ const {stdout} = await nestedSubprocess('noop-both.js', [foobarString], {...getDifferentOutputs(1), isSync});150 t.is(stdout, `${foobarString}\n${foobarString}`);151 };152 153-test('Can re-use same parent file descriptor on different output file descriptors', testMultipleInheritOutput, nestedExecaAsync);154-test('Can re-use same parent file descriptor on different output file descriptors, sync', testMultipleInheritOutput, nestedExecaSync);153+test('Can re-use same parent file descriptor on different output file descriptors', testMultipleInheritOutput, false);154+test('Can re-use same parent file descriptor on different output file descriptors, sync', testMultipleInheritOutput, true);155 156 const testMultipleFileInput = async (t, mapFile) => {157 const filePath = tempfile();158 await writeFile(filePath, foobarString);55 unmodified linesmodified:test/stdio/native-fd.js+25 added-25 removed
2 unmodified lines3 import {execa, execaSync} from '../../index.js';4 import {getStdio, fullStdio} from '../helpers/stdio.js';5 import {setFixtureDirectory} from '../helpers/fixtures-directory.js';6 import {foobarString} from '../helpers/input.js';7-import {parentExecaAsync, parentExecaSync} from '../helpers/nested.js';7+import {nestedSubprocess} from '../helpers/nested.js';8 9 setFixtureDirectory();10 11 const isLinux = platform === 'linux';12 const isWindows = platform === 'win32';13 14-const testFd3InheritOutput = async (t, stdioOption, execaMethod) => {15- const {stdio} = await execaMethod('noop-fd.js', ['3', foobarString], getStdio(3, stdioOption), fullStdio);14+const testFd3InheritOutput = async (t, stdioOption, isSync) => {15+ const {stdio} = await nestedSubprocess('noop-fd.js', ['3', foobarString], {...getStdio(3, stdioOption), isSync}, fullStdio);16 t.is(stdio[3], foobarString);17 };18 19-test('stdio[*] output can use "inherit"', testFd3InheritOutput, 'inherit', parentExecaAsync);20-test('stdio[*] output can use ["inherit"]', testFd3InheritOutput, ['inherit'], parentExecaAsync);21-test('stdio[*] output can use "inherit", sync', testFd3InheritOutput, 'inherit', parentExecaSync);22-test('stdio[*] output can use ["inherit"], sync', testFd3InheritOutput, ['inherit'], parentExecaSync);19+test('stdio[*] output can use "inherit"', testFd3InheritOutput, 'inherit', false);20+test('stdio[*] output can use ["inherit"]', testFd3InheritOutput, ['inherit'], false);21+test('stdio[*] output can use "inherit", sync', testFd3InheritOutput, 'inherit', true);22+test('stdio[*] output can use ["inherit"], sync', testFd3InheritOutput, ['inherit'], true);23 24 if (isLinux) {25- const testOverflowStream = async (t, fdNumber, stdioOption, execaMethod) => {26- const {stdout} = await execaMethod('empty.js', getStdio(fdNumber, stdioOption), fullStdio);25+ const testOverflowStream = async (t, fdNumber, stdioOption, isSync) => {26+ const {stdout} = await nestedSubprocess('empty.js', {...getStdio(fdNumber, stdioOption), isSync}, fullStdio);27 t.is(stdout, '');28 };29 30- test('stdin can use 4+', testOverflowStream, 0, 4, parentExecaAsync);31- test('stdin can use [4+]', testOverflowStream, 0, [4], parentExecaAsync);32- test('stdout can use 4+', testOverflowStream, 1, 4, parentExecaAsync);33- test('stdout can use [4+]', testOverflowStream, 1, [4], parentExecaAsync);34- test('stderr can use 4+', testOverflowStream, 2, 4, parentExecaAsync);35- test('stderr can use [4+]', testOverflowStream, 2, [4], parentExecaAsync);36- test('stdio[*] can use 4+', testOverflowStream, 3, 4, parentExecaAsync);37- test('stdio[*] can use [4+]', testOverflowStream, 3, [4], parentExecaAsync);38- test('stdin can use 4+, sync', testOverflowStream, 0, 4, parentExecaSync);39- test('stdin can use [4+], sync', testOverflowStream, 0, [4], parentExecaSync);40- test('stdout can use 4+, sync', testOverflowStream, 1, 4, parentExecaSync);41- test('stdout can use [4+], sync', testOverflowStream, 1, [4], parentExecaSync);42- test('stderr can use 4+, sync', testOverflowStream, 2, 4, parentExecaSync);43- test('stderr can use [4+], sync', testOverflowStream, 2, [4], parentExecaSync);44- test('stdio[*] can use 4+, sync', testOverflowStream, 3, 4, parentExecaSync);45- test('stdio[*] can use [4+], sync', testOverflowStream, 3, [4], parentExecaSync);30+ test('stdin can use 4+', testOverflowStream, 0, 4, false);31+ test('stdin can use [4+]', testOverflowStream, 0, [4], false);32+ test('stdout can use 4+', testOverflowStream, 1, 4, false);33+ test('stdout can use [4+]', testOverflowStream, 1, [4], false);34+ test('stderr can use 4+', testOverflowStream, 2, 4, false);35+ test('stderr can use [4+]', testOverflowStream, 2, [4], false);36+ test('stdio[*] can use 4+', testOverflowStream, 3, 4, false);37+ test('stdio[*] can use [4+]', testOverflowStream, 3, [4], false);38+ test('stdin can use 4+, sync', testOverflowStream, 0, 4, true);39+ test('stdin can use [4+], sync', testOverflowStream, 0, [4], true);40+ test('stdout can use 4+, sync', testOverflowStream, 1, 4, true);41+ test('stdout can use [4+], sync', testOverflowStream, 1, [4], true);42+ test('stderr can use 4+, sync', testOverflowStream, 2, 4, true);43+ test('stderr can use [4+], sync', testOverflowStream, 2, [4], true);44+ test('stdio[*] can use 4+, sync', testOverflowStream, 3, 4, true);45+ test('stdio[*] can use [4+], sync', testOverflowStream, 3, [4], true);46 }47 48 const testOverflowStreamArray = (t, fdNumber, stdioOption) => {49 t.throws(() => {27 unmodified linesmodified:test/stdio/native-inherit-pipe.js+7 added-7 removed
3 unmodified lines4 import {execa} from '../../index.js';5 import {getStdio, fullStdio} from '../helpers/stdio.js';6 import {setFixtureDirectory} from '../helpers/fixtures-directory.js';7 import {foobarString} from '../helpers/input.js';8-import {parentExecaAsync, parentExecaSync} from '../helpers/nested.js';8+import {nestedSubprocess} from '../helpers/nested.js';9 10 setFixtureDirectory();11 12 const testInheritStdin = async (t, stdioOption, isSync) => {43 unmodified lines56 test('stderr can be [process.stderr, "pipe"], encoding "buffer", sync', testInheritStdioOutput, 2, 1, ['stderr', 'pipe'], true, 'buffer');57 test('stdio[*] output can be ["inherit", "pipe"], encoding "buffer", sync', testInheritStdioOutput, 3, 1, ['inherit', 'pipe'], true, 'buffer');58 test('stdio[*] output can be [3, "pipe"], encoding "buffer", sync', testInheritStdioOutput, 3, 1, [3, 'pipe'], true, 'buffer');59 60-const testInheritNoBuffer = async (t, stdioOption, execaMethod) => {60+const testInheritNoBuffer = async (t, stdioOption, isSync) => {61 const filePath = tempfile();62- await execaMethod('nested-write.js', [filePath, foobarString], {stdin: stdioOption, buffer: false}, {input: foobarString});62+ await nestedSubprocess('nested-write.js', [filePath, foobarString], {stdin: stdioOption, buffer: false, isSync}, {input: foobarString});63 t.is(await readFile(filePath, 'utf8'), `${foobarString} ${foobarString}`);64 await rm(filePath);65 };66 67-test('stdin can be ["inherit", "pipe"], buffer: false', testInheritNoBuffer, ['inherit', 'pipe'], parentExecaAsync);68-test('stdin can be [0, "pipe"], buffer: false', testInheritNoBuffer, [0, 'pipe'], parentExecaAsync);69-test.serial('stdin can be ["inherit", "pipe"], buffer: false, sync', testInheritNoBuffer, ['inherit', 'pipe'], parentExecaSync);70-test.serial('stdin can be [0, "pipe"], buffer: false, sync', testInheritNoBuffer, [0, 'pipe'], parentExecaSync);67+test('stdin can be ["inherit", "pipe"], buffer: false', testInheritNoBuffer, ['inherit', 'pipe'], false);68+test('stdin can be [0, "pipe"], buffer: false', testInheritNoBuffer, [0, 'pipe'], false);69+test.serial('stdin can be ["inherit", "pipe"], buffer: false, sync', testInheritNoBuffer, ['inherit', 'pipe'], true);70+test.serial('stdin can be [0, "pipe"], buffer: false, sync', testInheritNoBuffer, [0, 'pipe'], true);71 72 test('stdin can use ["inherit", "pipe"] in a TTY', async t => {73 const stdioOption = [['inherit', 'pipe'], 'inherit', 'pipe'];74 const {stdout} = await execa('nested-sync-tty.js', [JSON.stringify({stdio: stdioOption}), 'false', 'stdin-fd.js', '0'], {input: foobarString});23 unmodified linesmodified:test/terminate/cleanup.js+11 added-11 removed
2 unmodified lines3 import test from 'ava';4 import isRunning from 'is-running';5 import {execa, execaSync} from '../../index.js';6 import {setFixtureDirectory} from '../helpers/fixtures-directory.js';7-import {nestedExecaAsync, nestedWorker} from '../helpers/nested.js';7+import {nestedSubprocess} from '../helpers/nested.js';8 import {foobarString} from '../helpers/input.js';9 10 setFixtureDirectory();11 12 const isWindows = process.platform === 'win32';13 14 // When subprocess exits before current process15-const spawnAndExit = async (t, execaMethod, cleanup, detached) => {16- const {stdout} = await execaMethod('noop-fd.js', ['1', foobarString], {cleanup, detached});15+const spawnAndExit = async (t, worker, cleanup, detached) => {16+ const {nestedResult: {stdout}} = await nestedSubprocess('noop-fd.js', ['1', foobarString], {worker, cleanup, detached});17 t.is(stdout, foobarString);18 };19 20-test('spawnAndExit', spawnAndExit, nestedExecaAsync, false, false);21-test('spawnAndExit cleanup', spawnAndExit, nestedExecaAsync, true, false);22-test('spawnAndExit detached', spawnAndExit, nestedExecaAsync, false, true);23-test('spawnAndExit cleanup detached', spawnAndExit, nestedExecaAsync, true, true);24-test('spawnAndExit, worker', spawnAndExit, nestedWorker, false, false);25-test('spawnAndExit cleanup, worker', spawnAndExit, nestedWorker, true, false);26-test('spawnAndExit detached, worker', spawnAndExit, nestedWorker, false, true);27-test('spawnAndExit cleanup detached, worker', spawnAndExit, nestedWorker, true, true);20+test('spawnAndExit', spawnAndExit, false, false, false);21+test('spawnAndExit cleanup', spawnAndExit, false, true, false);22+test('spawnAndExit detached', spawnAndExit, false, false, true);23+test('spawnAndExit cleanup detached', spawnAndExit, false, true, true);24+test('spawnAndExit, worker', spawnAndExit, true, false, false);25+test('spawnAndExit cleanup, worker', spawnAndExit, true, true, false);26+test('spawnAndExit detached, worker', spawnAndExit, true, false, true);27+test('spawnAndExit cleanup detached, worker', spawnAndExit, true, true, true);28 29 // When current process exits before subprocess30 const spawnAndKill = async (t, [signal, cleanup, detached, isKilled]) => {31 const subprocess = execa('ipc-send-pid.js', [cleanup, detached], {stdio: 'ignore', ipc: true});70 unmodified linesmodified:test/verbose/complete.js+74 added-79 removed
1 import {stripVTControlCharacters} from 'node:util';2 import test from 'ava';3-import {execa} from '../../index.js';3 import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4 import {foobarString} from '../helpers/input.js';6-import {parentExecaAsync, parentExecaSync} from '../helpers/nested.js';5+import {nestedSubprocess} from '../helpers/nested.js';6 import {8- runErrorSubprocessAsync,9- runErrorSubprocessSync,10- runWarningSubprocessAsync,11- runWarningSubprocessSync,12- runEarlyErrorSubprocessAsync,13- runEarlyErrorSubprocessSync,7+ runErrorSubprocess,8+ runWarningSubprocess,9+ runEarlyErrorSubprocess,10 getCompletionLine,11 getCompletionLines,12 testTimestamp,13 getVerboseOption,12 unmodified lines26 } from '../helpers/verbose.js';27 28 setFixtureDirectory();29 34-const testPrintCompletion = async (t, verbose, execaMethod) => {35- const {stderr} = await execaMethod('noop.js', [foobarString], {verbose});30+const testPrintCompletion = async (t, verbose, isSync) => {31+ const {stderr} = await nestedSubprocess('noop.js', [foobarString], {verbose, isSync});32 t.is(getCompletionLine(stderr), `${testTimestamp} [0] √ (done in 0ms)`);33 };34 39-test('Prints completion, verbose "short"', testPrintCompletion, 'short', parentExecaAsync);40-test('Prints completion, verbose "full"', testPrintCompletion, 'full', parentExecaAsync);41-test('Prints completion, verbose "short", fd-specific stdout', testPrintCompletion, stdoutShortOption, parentExecaAsync);42-test('Prints completion, verbose "full", fd-specific stdout', testPrintCompletion, stdoutFullOption, parentExecaAsync);43-test('Prints completion, verbose "short", fd-specific stderr', testPrintCompletion, stderrShortOption, parentExecaAsync);44-test('Prints completion, verbose "full", fd-specific stderr', testPrintCompletion, stderrFullOption, parentExecaAsync);45-test('Prints completion, verbose "short", fd-specific fd3', testPrintCompletion, fd3ShortOption, parentExecaAsync);46-test('Prints completion, verbose "full", fd-specific fd3', testPrintCompletion, fd3FullOption, parentExecaAsync);47-test('Prints completion, verbose "short", fd-specific ipc', testPrintCompletion, ipcShortOption, parentExecaAsync);48-test('Prints completion, verbose "full", fd-specific ipc', testPrintCompletion, ipcFullOption, parentExecaAsync);49-test('Prints completion, verbose "short", sync', testPrintCompletion, 'short', parentExecaSync);50-test('Prints completion, verbose "full", sync', testPrintCompletion, 'full', parentExecaSync);51-test('Prints completion, verbose "short", fd-specific stdout, sync', testPrintCompletion, stdoutShortOption, parentExecaSync);52-test('Prints completion, verbose "full", fd-specific stdout, sync', testPrintCompletion, stdoutFullOption, parentExecaSync);53-test('Prints completion, verbose "short", fd-specific stderr, sync', testPrintCompletion, stderrShortOption, parentExecaSync);54-test('Prints completion, verbose "full", fd-specific stderr, sync', testPrintCompletion, stderrFullOption, parentExecaSync);55-test('Prints completion, verbose "short", fd-specific fd3, sync', testPrintCompletion, fd3ShortOption, parentExecaSync);56-test('Prints completion, verbose "full", fd-specific fd3, sync', testPrintCompletion, fd3FullOption, parentExecaSync);57-test('Prints completion, verbose "short", fd-specific ipc, sync', testPrintCompletion, ipcShortOption, parentExecaSync);58-test('Prints completion, verbose "full", fd-specific ipc, sync', testPrintCompletion, ipcFullOption, parentExecaSync);35+test('Prints completion, verbose "short"', testPrintCompletion, 'short', false);36+test('Prints completion, verbose "full"', testPrintCompletion, 'full', false);37+test('Prints completion, verbose "short", fd-specific stdout', testPrintCompletion, stdoutShortOption, false);38+test('Prints completion, verbose "full", fd-specific stdout', testPrintCompletion, stdoutFullOption, false);39+test('Prints completion, verbose "short", fd-specific stderr', testPrintCompletion, stderrShortOption, false);40+test('Prints completion, verbose "full", fd-specific stderr', testPrintCompletion, stderrFullOption, false);41+test('Prints completion, verbose "short", fd-specific fd3', testPrintCompletion, fd3ShortOption, false);42+test('Prints completion, verbose "full", fd-specific fd3', testPrintCompletion, fd3FullOption, false);43+test('Prints completion, verbose "short", fd-specific ipc', testPrintCompletion, ipcShortOption, false);44+test('Prints completion, verbose "full", fd-specific ipc', testPrintCompletion, ipcFullOption, false);45+test('Prints completion, verbose "short", sync', testPrintCompletion, 'short', true);46+test('Prints completion, verbose "full", sync', testPrintCompletion, 'full', true);47+test('Prints completion, verbose "short", fd-specific stdout, sync', testPrintCompletion, stdoutShortOption, true);48+test('Prints completion, verbose "full", fd-specific stdout, sync', testPrintCompletion, stdoutFullOption, true);49+test('Prints completion, verbose "short", fd-specific stderr, sync', testPrintCompletion, stderrShortOption, true);50+test('Prints completion, verbose "full", fd-specific stderr, sync', testPrintCompletion, stderrFullOption, true);51+test('Prints completion, verbose "short", fd-specific fd3, sync', testPrintCompletion, fd3ShortOption, true);52+test('Prints completion, verbose "full", fd-specific fd3, sync', testPrintCompletion, fd3FullOption, true);53+test('Prints completion, verbose "short", fd-specific ipc, sync', testPrintCompletion, ipcShortOption, true);54+test('Prints completion, verbose "full", fd-specific ipc, sync', testPrintCompletion, ipcFullOption, true);55 60-const testNoPrintCompletion = async (t, verbose, execaMethod) => {61- const {stderr} = await execaMethod('noop.js', [foobarString], {verbose});56+const testNoPrintCompletion = async (t, verbose, isSync) => {57+ const {stderr} = await nestedSubprocess('noop.js', [foobarString], {verbose, isSync});58 t.is(stderr, '');59 };60 65-test('Does not print completion, verbose "none"', testNoPrintCompletion, 'none', parentExecaAsync);66-test('Does not print completion, verbose default"', testNoPrintCompletion, undefined, parentExecaAsync);67-test('Does not print completion, verbose "none", fd-specific stdout', testNoPrintCompletion, stdoutNoneOption, parentExecaAsync);68-test('Does not print completion, verbose "none", fd-specific stderr', testNoPrintCompletion, stderrNoneOption, parentExecaAsync);69-test('Does not print completion, verbose "none", fd-specific fd3', testNoPrintCompletion, fd3NoneOption, parentExecaAsync);70-test('Does not print completion, verbose "none", fd-specific ipc', testNoPrintCompletion, ipcNoneOption, parentExecaAsync);71-test('Does not print completion, verbose default", fd-specific', testNoPrintCompletion, {}, parentExecaAsync);72-test('Does not print completion, verbose "none", sync', testNoPrintCompletion, 'none', parentExecaSync);73-test('Does not print completion, verbose default", sync', testNoPrintCompletion, undefined, parentExecaSync);74-test('Does not print completion, verbose "none", fd-specific stdout, sync', testNoPrintCompletion, stdoutNoneOption, parentExecaSync);75-test('Does not print completion, verbose "none", fd-specific stderr, sync', testNoPrintCompletion, stderrNoneOption, parentExecaSync);76-test('Does not print completion, verbose "none", fd-specific fd3, sync', testNoPrintCompletion, fd3NoneOption, parentExecaSync);77-test('Does not print completion, verbose "none", fd-specific ipc, sync', testNoPrintCompletion, ipcNoneOption, parentExecaSync);78-test('Does not print completion, verbose default", fd-specific, sync', testNoPrintCompletion, {}, parentExecaSync);61+test('Does not print completion, verbose "none"', testNoPrintCompletion, 'none', false);62+test('Does not print completion, verbose default"', testNoPrintCompletion, undefined, false);63+test('Does not print completion, verbose "none", fd-specific stdout', testNoPrintCompletion, stdoutNoneOption, false);64+test('Does not print completion, verbose "none", fd-specific stderr', testNoPrintCompletion, stderrNoneOption, false);65+test('Does not print completion, verbose "none", fd-specific fd3', testNoPrintCompletion, fd3NoneOption, false);66+test('Does not print completion, verbose "none", fd-specific ipc', testNoPrintCompletion, ipcNoneOption, false);67+test('Does not print completion, verbose default", fd-specific', testNoPrintCompletion, {}, false);68+test('Does not print completion, verbose "none", sync', testNoPrintCompletion, 'none', true);69+test('Does not print completion, verbose default", sync', testNoPrintCompletion, undefined, true);70+test('Does not print completion, verbose "none", fd-specific stdout, sync', testNoPrintCompletion, stdoutNoneOption, true);71+test('Does not print completion, verbose "none", fd-specific stderr, sync', testNoPrintCompletion, stderrNoneOption, true);72+test('Does not print completion, verbose "none", fd-specific fd3, sync', testNoPrintCompletion, fd3NoneOption, true);73+test('Does not print completion, verbose "none", fd-specific ipc, sync', testNoPrintCompletion, ipcNoneOption, true);74+test('Does not print completion, verbose default", fd-specific, sync', testNoPrintCompletion, {}, true);75 80-const testPrintCompletionError = async (t, execaMethod) => {81- const stderr = await execaMethod(t, 'short');76+const testPrintCompletionError = async (t, isSync) => {77+ const stderr = await runErrorSubprocess(t, 'short', isSync);78 t.is(getCompletionLine(stderr), `${testTimestamp} [0] × (done in 0ms)`);79 };80 85-test('Prints completion after errors', testPrintCompletionError, runErrorSubprocessAsync);86-test('Prints completion after errors, sync', testPrintCompletionError, runErrorSubprocessSync);81+test('Prints completion after errors', testPrintCompletionError, false);82+test('Prints completion after errors, sync', testPrintCompletionError, true);83 88-const testPrintCompletionWarning = async (t, execaMethod) => {89- const stderr = await execaMethod(t);84+const testPrintCompletionWarning = async (t, isSync) => {85+ const stderr = await runWarningSubprocess(t, isSync);86 t.is(getCompletionLine(stderr), `${testTimestamp} [0] ‼ (done in 0ms)`);87 };88 93-test('Prints completion after errors, "reject" false', testPrintCompletionWarning, runWarningSubprocessAsync);94-test('Prints completion after errors, "reject" false, sync', testPrintCompletionWarning, runWarningSubprocessSync);89+test('Prints completion after errors, "reject" false', testPrintCompletionWarning, false);90+test('Prints completion after errors, "reject" false, sync', testPrintCompletionWarning, true);91 96-const testPrintCompletionEarly = async (t, execaMethod) => {97- const stderr = await execaMethod(t);92+const testPrintCompletionEarly = async (t, isSync) => {93+ const stderr = await runEarlyErrorSubprocess(t, isSync);94 t.is(getCompletionLine(stderr), `${testTimestamp} [0] × (done in 0ms)`);95 };96 101-test('Prints completion after early validation errors', testPrintCompletionEarly, runEarlyErrorSubprocessAsync);102-test('Prints completion after early validation errors, sync', testPrintCompletionEarly, runEarlyErrorSubprocessSync);97+test('Prints completion after early validation errors', testPrintCompletionEarly, false);98+test('Prints completion after early validation errors, sync', testPrintCompletionEarly, true);99 100 test.serial('Prints duration', async t => {105- const {stderr} = await parentExecaAsync('delay.js', ['1000'], {verbose: 'short'});101+ const {stderr} = await nestedSubprocess('delay.js', ['1000'], {verbose: 'short'});102 t.regex(stripVTControlCharacters(stderr).split('\n').at(-1), /\(done in [\d.]+s\)/);103 });104 109-const testPipeDuration = async (t, fixtureName, sourceVerbose, destinationVerbose) => {110- const {stderr} = await execa(`nested-pipe-${fixtureName}.js`, [111- JSON.stringify(getVerboseOption(sourceVerbose)),112- 'noop.js',113- foobarString,114- JSON.stringify(getVerboseOption(destinationVerbose)),115- 'stdin.js',116- ]);105+const testPipeDuration = async (t, parentFixture, sourceVerbose, destinationVerbose) => {106+ const {stderr} = await nestedSubprocess('noop.js', [foobarString], {107+ parentFixture,108+ sourceOptions: getVerboseOption(sourceVerbose),109+ destinationFile: 'stdin.js',110+ destinationOptions: getVerboseOption(destinationVerbose),111+ });112 113 const lines = getCompletionLines(stderr);114 t.is(lines.includes(`${testTimestamp} [0] √ (done in 0ms)`), sourceVerbose || destinationVerbose);115 t.is(lines.includes(`${testTimestamp} [1] √ (done in 0ms)`), sourceVerbose && destinationVerbose);116 };117 123-test('Prints both durations piped with .pipe("file")', testPipeDuration, 'file', true, true);124-test('Prints both durations piped with .pipe`command`', testPipeDuration, 'script', true, true);125-test('Prints both durations piped with .pipe(subprocess)', testPipeDuration, 'subprocesses', true, true);126-test('Prints first duration piped with .pipe("file")', testPipeDuration, 'file', true, false);127-test('Prints first duration piped with .pipe`command`', testPipeDuration, 'script', true, false);128-test('Prints first duration piped with .pipe(subprocess)', testPipeDuration, 'subprocesses', true, false);129-test('Prints second duration piped with .pipe("file")', testPipeDuration, 'file', false, true);130-test('Prints second duration piped with .pipe`command`', testPipeDuration, 'script', false, true);131-test('Prints second duration piped with .pipe(subprocess)', testPipeDuration, 'subprocesses', false, true);132-test('Prints neither durations piped with .pipe("file")', testPipeDuration, 'file', false, false);133-test('Prints neither durations piped with .pipe`command`', testPipeDuration, 'script', false, false);134-test('Prints neither durations piped with .pipe(subprocess)', testPipeDuration, 'subprocesses', false, false);118+test('Prints both durations piped with .pipe("file")', testPipeDuration, 'nested-pipe-file.js', true, true);119+test('Prints both durations piped with .pipe`command`', testPipeDuration, 'nested-pipe-script.js', true, true);120+test('Prints both durations piped with .pipe(subprocess)', testPipeDuration, 'nested-pipe-subprocesses.js', true, true);121+test('Prints first duration piped with .pipe("file")', testPipeDuration, 'nested-pipe-file.js', true, false);122+test('Prints first duration piped with .pipe`command`', testPipeDuration, 'nested-pipe-script.js', true, false);123+test('Prints first duration piped with .pipe(subprocess)', testPipeDuration, 'nested-pipe-subprocesses.js', true, false);124+test('Prints second duration piped with .pipe("file")', testPipeDuration, 'nested-pipe-file.js', false, true);125+test('Prints second duration piped with .pipe`command`', testPipeDuration, 'nested-pipe-script.js', false, true);126+test('Prints second duration piped with .pipe(subprocess)', testPipeDuration, 'nested-pipe-subprocesses.js', false, true);127+test('Prints neither durations piped with .pipe("file")', testPipeDuration, 'nested-pipe-file.js', false, false);128+test('Prints neither durations piped with .pipe`command`', testPipeDuration, 'nested-pipe-script.js', false, false);129+test('Prints neither durations piped with .pipe(subprocess)', testPipeDuration, 'nested-pipe-subprocesses.js', false, false);modified:test/verbose/error.js+75 added-81 removed
1 import test from 'ava';2 import {red} from 'yoctocolors';3-import {execa} from '../../index.js';3 import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4 import {foobarString} from '../helpers/input.js';6-import {parentExeca, parentExecaAsync, parentExecaSync} from '../helpers/nested.js';5+import {nestedSubprocess} from '../helpers/nested.js';6 import {7 QUOTE,9- runErrorSubprocessAsync,10- runErrorSubprocessSync,11- runEarlyErrorSubprocessAsync,12- runEarlyErrorSubprocessSync,8+ runErrorSubprocess,9+ runEarlyErrorSubprocess,10 getErrorLine,11 getErrorLines,12 testTimestamp,13 getVerboseOption,12 unmodified lines26 } from '../helpers/verbose.js';27 28 setFixtureDirectory();29 33-const parentExecaFail = parentExeca.bind(undefined, 'nested-fail.js');34-35-const testPrintError = async (t, verbose, execaMethod) => {36- const stderr = await execaMethod(t, verbose);30+const testPrintError = async (t, verbose, isSync) => {31+ const stderr = await runErrorSubprocess(t, verbose, isSync);32 t.is(getErrorLine(stderr), `${testTimestamp} [0] × Command failed with exit code 2: noop-fail.js 1 ${foobarString}`);33 };34 40-test('Prints error, verbose "short"', testPrintError, 'short', runErrorSubprocessAsync);41-test('Prints error, verbose "full"', testPrintError, 'full', runErrorSubprocessAsync);42-test('Prints error, verbose "short", fd-specific stdout', testPrintError, stdoutShortOption, runErrorSubprocessAsync);43-test('Prints error, verbose "full", fd-specific stdout', testPrintError, stdoutFullOption, runErrorSubprocessAsync);44-test('Prints error, verbose "short", fd-specific stderr', testPrintError, stderrShortOption, runErrorSubprocessAsync);45-test('Prints error, verbose "full", fd-specific stderr', testPrintError, stderrFullOption, runErrorSubprocessAsync);46-test('Prints error, verbose "short", fd-specific fd3', testPrintError, fd3ShortOption, runErrorSubprocessAsync);47-test('Prints error, verbose "full", fd-specific fd3', testPrintError, fd3FullOption, runErrorSubprocessAsync);48-test('Prints error, verbose "short", fd-specific ipc', testPrintError, ipcShortOption, runErrorSubprocessAsync);49-test('Prints error, verbose "full", fd-specific ipc', testPrintError, ipcFullOption, runErrorSubprocessAsync);50-test('Prints error, verbose "short", sync', testPrintError, 'short', runErrorSubprocessSync);51-test('Prints error, verbose "full", sync', testPrintError, 'full', runErrorSubprocessSync);52-test('Prints error, verbose "short", fd-specific stdout, sync', testPrintError, stdoutShortOption, runErrorSubprocessSync);53-test('Prints error, verbose "full", fd-specific stdout, sync', testPrintError, stdoutFullOption, runErrorSubprocessSync);54-test('Prints error, verbose "short", fd-specific stderr, sync', testPrintError, stderrShortOption, runErrorSubprocessSync);55-test('Prints error, verbose "full", fd-specific stderr, sync', testPrintError, stderrFullOption, runErrorSubprocessSync);56-test('Prints error, verbose "short", fd-specific fd3, sync', testPrintError, fd3ShortOption, runErrorSubprocessSync);57-test('Prints error, verbose "full", fd-specific fd3, sync', testPrintError, fd3FullOption, runErrorSubprocessSync);58-test('Prints error, verbose "short", fd-specific ipc, sync', testPrintError, ipcShortOption, runErrorSubprocessSync);59-test('Prints error, verbose "full", fd-specific ipc, sync', testPrintError, ipcFullOption, runErrorSubprocessSync);35+test('Prints error, verbose "short"', testPrintError, 'short', false);36+test('Prints error, verbose "full"', testPrintError, 'full', false);37+test('Prints error, verbose "short", fd-specific stdout', testPrintError, stdoutShortOption, false);38+test('Prints error, verbose "full", fd-specific stdout', testPrintError, stdoutFullOption, false);39+test('Prints error, verbose "short", fd-specific stderr', testPrintError, stderrShortOption, false);40+test('Prints error, verbose "full", fd-specific stderr', testPrintError, stderrFullOption, false);41+test('Prints error, verbose "short", fd-specific fd3', testPrintError, fd3ShortOption, false);42+test('Prints error, verbose "full", fd-specific fd3', testPrintError, fd3FullOption, false);43+test('Prints error, verbose "short", fd-specific ipc', testPrintError, ipcShortOption, false);44+test('Prints error, verbose "full", fd-specific ipc', testPrintError, ipcFullOption, false);45+test('Prints error, verbose "short", sync', testPrintError, 'short', true);46+test('Prints error, verbose "full", sync', testPrintError, 'full', true);47+test('Prints error, verbose "short", fd-specific stdout, sync', testPrintError, stdoutShortOption, true);48+test('Prints error, verbose "full", fd-specific stdout, sync', testPrintError, stdoutFullOption, true);49+test('Prints error, verbose "short", fd-specific stderr, sync', testPrintError, stderrShortOption, true);50+test('Prints error, verbose "full", fd-specific stderr, sync', testPrintError, stderrFullOption, true);51+test('Prints error, verbose "short", fd-specific fd3, sync', testPrintError, fd3ShortOption, true);52+test('Prints error, verbose "full", fd-specific fd3, sync', testPrintError, fd3FullOption, true);53+test('Prints error, verbose "short", fd-specific ipc, sync', testPrintError, ipcShortOption, true);54+test('Prints error, verbose "full", fd-specific ipc, sync', testPrintError, ipcFullOption, true);55 61-const testNoPrintError = async (t, verbose, execaMethod) => {62- const stderr = await execaMethod(t, verbose, false);56+const testNoPrintError = async (t, verbose, isSync) => {57+ const stderr = await runErrorSubprocess(t, verbose, isSync, false);58 t.is(getErrorLine(stderr), undefined);59 };60 66-test('Does not print error, verbose "none"', testNoPrintError, 'none', runErrorSubprocessAsync);67-test('Does not print error, verbose default', testNoPrintError, undefined, runErrorSubprocessAsync);68-test('Does not print error, verbose "none", fd-specific stdout', testNoPrintError, stdoutNoneOption, runErrorSubprocessAsync);69-test('Does not print error, verbose "none", fd-specific stderr', testNoPrintError, stderrNoneOption, runErrorSubprocessAsync);70-test('Does not print error, verbose "none", fd-specific fd3', testNoPrintError, fd3NoneOption, runErrorSubprocessAsync);71-test('Does not print error, verbose "none", fd-specific ipc', testNoPrintError, ipcNoneOption, runErrorSubprocessAsync);72-test('Does not print error, verbose default, fd-specific', testNoPrintError, {}, runErrorSubprocessAsync);73-test('Does not print error, verbose "none", sync', testNoPrintError, 'none', runErrorSubprocessSync);74-test('Does not print error, verbose default, sync', testNoPrintError, undefined, runErrorSubprocessSync);75-test('Does not print error, verbose "none", fd-specific stdout, sync', testNoPrintError, stdoutNoneOption, runErrorSubprocessSync);76-test('Does not print error, verbose "none", fd-specific stderr, sync', testNoPrintError, stderrNoneOption, runErrorSubprocessSync);77-test('Does not print error, verbose "none", fd-specific fd3, sync', testNoPrintError, fd3NoneOption, runErrorSubprocessSync);78-test('Does not print error, verbose "none", fd-specific ipc, sync', testNoPrintError, ipcNoneOption, runErrorSubprocessSync);79-test('Does not print error, verbose default, fd-specific, sync', testNoPrintError, {}, runErrorSubprocessSync);61+test('Does not print error, verbose "none"', testNoPrintError, 'none', false);62+test('Does not print error, verbose default', testNoPrintError, undefined, false);63+test('Does not print error, verbose "none", fd-specific stdout', testNoPrintError, stdoutNoneOption, false);64+test('Does not print error, verbose "none", fd-specific stderr', testNoPrintError, stderrNoneOption, false);65+test('Does not print error, verbose "none", fd-specific fd3', testNoPrintError, fd3NoneOption, false);66+test('Does not print error, verbose "none", fd-specific ipc', testNoPrintError, ipcNoneOption, false);67+test('Does not print error, verbose default, fd-specific', testNoPrintError, {}, false);68+test('Does not print error, verbose "none", sync', testNoPrintError, 'none', true);69+test('Does not print error, verbose default, sync', testNoPrintError, undefined, true);70+test('Does not print error, verbose "none", fd-specific stdout, sync', testNoPrintError, stdoutNoneOption, true);71+test('Does not print error, verbose "none", fd-specific stderr, sync', testNoPrintError, stderrNoneOption, true);72+test('Does not print error, verbose "none", fd-specific fd3, sync', testNoPrintError, fd3NoneOption, true);73+test('Does not print error, verbose "none", fd-specific ipc, sync', testNoPrintError, ipcNoneOption, true);74+test('Does not print error, verbose default, fd-specific, sync', testNoPrintError, {}, true);75 81-const testPrintNoError = async (t, execaMethod) => {82- const {stderr} = await execaMethod('noop.js', [foobarString], {verbose: 'short'});76+const testPrintNoError = async (t, isSync) => {77+ const {stderr} = await nestedSubprocess('noop.js', [foobarString], {verbose: 'short', isSync});78 t.is(getErrorLine(stderr), undefined);79 };80 86-test('Does not print error if none', testPrintNoError, parentExecaAsync);87-test('Does not print error if none, sync', testPrintNoError, parentExecaSync);81+test('Does not print error if none', testPrintNoError, false);82+test('Does not print error if none, sync', testPrintNoError, true);83 89-const testPrintErrorEarly = async (t, execaMethod) => {90- const stderr = await execaMethod(t);84+const testPrintErrorEarly = async (t, isSync) => {85+ const stderr = await runEarlyErrorSubprocess(t, isSync);86 t.is(getErrorLine(stderr), `${testTimestamp} [0] × TypeError: The "cwd" option must be a string or a file URL: true.`);87 };88 94-test('Prints early validation error', testPrintErrorEarly, runEarlyErrorSubprocessAsync);95-test('Prints early validation error, sync', testPrintErrorEarly, runEarlyErrorSubprocessSync);89+test('Prints early validation error', testPrintErrorEarly, false);90+test('Prints early validation error, sync', testPrintErrorEarly, true);91 92 test('Does not repeat stdout|stderr with error', async t => {98- const stderr = await runErrorSubprocessAsync(t, 'short');93+ const stderr = await runErrorSubprocess(t, 'short');94 t.deepEqual(getErrorLines(stderr), [`${testTimestamp} [0] × Command failed with exit code 2: noop-fail.js 1 ${foobarString}`]);95 });96 97 test('Prints error differently if "reject" is false', async t => {103- const {stderr} = await parentExecaAsync('noop-fail.js', ['1', foobarString], {verbose: 'short', reject: false});98+ const {stderr} = await nestedSubprocess('noop-fail.js', ['1', foobarString], {verbose: 'short', reject: false});99 t.deepEqual(getErrorLines(stderr), [`${testTimestamp} [0] ‼ Command failed with exit code 2: noop-fail.js 1 ${foobarString}`]);100 });101 107-const testPipeError = async (t, fixtureName, sourceVerbose, destinationVerbose) => {108- const {stderr} = await t.throwsAsync(execa(`nested-pipe-${fixtureName}.js`, [109- JSON.stringify(getVerboseOption(sourceVerbose)),110- 'noop-fail.js',111- '1',112- JSON.stringify(getVerboseOption(destinationVerbose)),113- 'stdin-fail.js',114- ]));102+const testPipeError = async (t, parentFixture, sourceVerbose, destinationVerbose) => {103+ const {stderr} = await t.throwsAsync(nestedSubprocess('noop-fail.js', ['1'], {104+ parentFixture,105+ sourceOptions: getVerboseOption(sourceVerbose),106+ destinationFile: 'stdin-fail.js',107+ destinationOptions: getVerboseOption(destinationVerbose),108+ }));109 110 const lines = getErrorLines(stderr);111 t.is(lines.includes(`${testTimestamp} [0] × Command failed with exit code 2: noop-fail.js 1`), sourceVerbose);112 t.is(lines.includes(`${testTimestamp} [${sourceVerbose ? 1 : 0}] × Command failed with exit code 2: stdin-fail.js`), destinationVerbose);113 };114 121-test('Prints both errors piped with .pipe("file")', testPipeError, 'file', true, true);122-test('Prints both errors piped with .pipe`command`', testPipeError, 'script', true, true);123-test('Prints both errors piped with .pipe(subprocess)', testPipeError, 'subprocesses', true, true);124-test('Prints first error piped with .pipe("file")', testPipeError, 'file', true, false);125-test('Prints first error piped with .pipe`command`', testPipeError, 'script', true, false);126-test('Prints first error piped with .pipe(subprocess)', testPipeError, 'subprocesses', true, false);127-test('Prints second error piped with .pipe("file")', testPipeError, 'file', false, true);128-test('Prints second error piped with .pipe`command`', testPipeError, 'script', false, true);129-test('Prints second error piped with .pipe(subprocess)', testPipeError, 'subprocesses', false, true);130-test('Prints neither errors piped with .pipe("file")', testPipeError, 'file', false, false);131-test('Prints neither errors piped with .pipe`command`', testPipeError, 'script', false, false);132-test('Prints neither errors piped with .pipe(subprocess)', testPipeError, 'subprocesses', false, false);115+test('Prints both errors piped with .pipe("file")', testPipeError, 'nested-pipe-file.js', true, true);116+test('Prints both errors piped with .pipe`command`', testPipeError, 'nested-pipe-script.js', true, true);117+test('Prints both errors piped with .pipe(subprocess)', testPipeError, 'nested-pipe-subprocesses.js', true, true);118+test('Prints first error piped with .pipe("file")', testPipeError, 'nested-pipe-file.js', true, false);119+test('Prints first error piped with .pipe`command`', testPipeError, 'nested-pipe-script.js', true, false);120+test('Prints first error piped with .pipe(subprocess)', testPipeError, 'nested-pipe-subprocesses.js', true, false);121+test('Prints second error piped with .pipe("file")', testPipeError, 'nested-pipe-file.js', false, true);122+test('Prints second error piped with .pipe`command`', testPipeError, 'nested-pipe-script.js', false, true);123+test('Prints second error piped with .pipe(subprocess)', testPipeError, 'nested-pipe-subprocesses.js', false, true);124+test('Prints neither errors piped with .pipe("file")', testPipeError, 'nested-pipe-file.js', false, false);125+test('Prints neither errors piped with .pipe`command`', testPipeError, 'nested-pipe-script.js', false, false);126+test('Prints neither errors piped with .pipe(subprocess)', testPipeError, 'nested-pipe-subprocesses.js', false, false);127 128 test('Quotes spaces from error', async t => {135- const {stderr} = await t.throwsAsync(parentExecaFail('noop-forever.js', ['foo bar'], {verbose: 'short'}));129+ const {stderr} = await t.throwsAsync(nestedSubprocess('noop-forever.js', ['foo bar'], {parentFixture: 'nested-fail.js', verbose: 'short'}));130 t.deepEqual(getErrorLines(stderr), [131 `${testTimestamp} [0] × Command was killed with SIGTERM (Termination): noop-forever.js ${QUOTE}foo bar${QUOTE}`,132 `${testTimestamp} [0] × foo bar`,133 ]);134 });135 136 test('Quotes special punctuation from error', async t => {143- const {stderr} = await t.throwsAsync(parentExecaFail('noop-forever.js', ['%'], {verbose: 'short'}));137+ const {stderr} = await t.throwsAsync(nestedSubprocess('noop-forever.js', ['%'], {parentFixture: 'nested-fail.js', verbose: 'short'}));138 t.deepEqual(getErrorLines(stderr), [139 `${testTimestamp} [0] × Command was killed with SIGTERM (Termination): noop-forever.js ${QUOTE}%${QUOTE}`,140 `${testTimestamp} [0] × %`,141 ]);142 });143 144 test('Does not escape internal characters from error', async t => {151- const {stderr} = await t.throwsAsync(parentExecaFail('noop-forever.js', ['ã'], {verbose: 'short'}));145+ const {stderr} = await t.throwsAsync(nestedSubprocess('noop-forever.js', ['ã'], {parentFixture: 'nested-fail.js', verbose: 'short'}));146 t.deepEqual(getErrorLines(stderr), [147 `${testTimestamp} [0] × Command was killed with SIGTERM (Termination): noop-forever.js ${QUOTE}ã${QUOTE}`,148 `${testTimestamp} [0] × ã`,149 ]);150 });151 152 test('Escapes and strips color sequences from error', async t => {159- const {stderr} = await t.throwsAsync(parentExecaFail('noop-forever.js', [red(foobarString)], {verbose: 'short'}, {env: {FORCE_COLOR: '1'}}));153+ const {stderr} = await t.throwsAsync(nestedSubprocess('noop-forever.js', [red(foobarString)], {parentFixture: 'nested-fail.js', verbose: 'short'}, {env: {FORCE_COLOR: '1'}}));154 t.deepEqual(getErrorLines(stderr), [155 `${testTimestamp} [0] × Command was killed with SIGTERM (Termination): noop-forever.js ${QUOTE}\\u001b[31m${foobarString}\\u001b[39m${QUOTE}`,156 `${testTimestamp} [0] × ${foobarString}`,157 ]);158 });159 160 test('Escapes control characters from error', async t => {167- const {stderr} = await t.throwsAsync(parentExecaFail('noop-forever.js', ['\u0001'], {verbose: 'short'}));161+ const {stderr} = await t.throwsAsync(nestedSubprocess('noop-forever.js', ['\u0001'], {parentFixture: 'nested-fail.js', verbose: 'short'}));162 t.deepEqual(getErrorLines(stderr), [163 `${testTimestamp} [0] × Command was killed with SIGTERM (Termination): noop-forever.js ${QUOTE}\\u0001${QUOTE}`,164 `${testTimestamp} [0] × \\u0001`,165 ]);1 unmodified linemodified:test/verbose/info.js+6 added-6 removed
1 import test from 'ava';2 import {setFixtureDirectory} from '../helpers/fixtures-directory.js';3 import {execa, execaSync} from '../../index.js';4 import {foobarString} from '../helpers/input.js';5-import {parentExecaAsync, parentExecaSync} from '../helpers/nested.js';5+import {nestedSubprocess} from '../helpers/nested.js';6 import {7 QUOTE,8 getCommandLine,9 getOutputLine,18 unmodified lines28 test('Prints command, NODE_DEBUG=execa + "inherit"', testVerboseGeneral, execa);29 test('Prints command, NODE_DEBUG=execa + "inherit", sync', testVerboseGeneral, execaSync);30 31 test('NODE_DEBUG=execa changes verbose default value to "full"', async t => {32- const {stderr} = await parentExecaAsync('noop.js', [foobarString], {}, {env: {NODE_DEBUG: 'execa'}});32+ const {stderr} = await nestedSubprocess('noop.js', [foobarString], {}, {env: {NODE_DEBUG: 'execa'}});33 t.is(getCommandLine(stderr), `${testTimestamp} [0] $ noop.js ${foobarString}`);34 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);35 });36 37-const testDebugEnvPriority = async (t, execaMethod) => {38- const {stderr} = await execaMethod('noop.js', [foobarString], {verbose: 'short'}, {env: {NODE_DEBUG: 'execa'}});37+const testDebugEnvPriority = async (t, isSync) => {38+ const {stderr} = await nestedSubprocess('noop.js', [foobarString], {verbose: 'short', isSync}, {env: {NODE_DEBUG: 'execa'}});39 t.is(getCommandLine(stderr), `${testTimestamp} [0] $ noop.js ${foobarString}`);40 t.is(getOutputLine(stderr), undefined);41 };42 43-test('NODE_DEBUG=execa has lower priority', testDebugEnvPriority, parentExecaAsync);44-test('NODE_DEBUG=execa has lower priority, sync', testDebugEnvPriority, parentExecaSync);43+test('NODE_DEBUG=execa has lower priority', testDebugEnvPriority, false);44+test('NODE_DEBUG=execa has lower priority, sync', testDebugEnvPriority, true);45 46 const invalidFalseMessage = 'renamed to "verbose: \'none\'"';47 const invalidTrueMessage = 'renamed to "verbose: \'short\'"';48 const invalidUnknownMessage = 'Allowed values are: \'none\', \'short\', \'full\'';14 unmodified linesmodified:test/verbose/ipc.js+15 added-15 removed
2 unmodified lines3 import test from 'ava';4 import {red} from 'yoctocolors';5 import {setFixtureDirectory} from '../helpers/fixtures-directory.js';6 import {foobarString, foobarObject} from '../helpers/input.js';7-import {nestedExecaAsync, parentExecaAsync} from '../helpers/nested.js';7+import {nestedSubprocess, nestedInstance} from '../helpers/nested.js';8 import {9 getIpcLine,10 getIpcLines,11 testTimestamp,4 unmodified lines16 17 setFixtureDirectory();18 19 const testPrintIpc = async (t, verbose) => {20- const {stderr} = await parentExecaAsync('ipc-send.js', {ipc: true, verbose});20+ const {stderr} = await nestedSubprocess('ipc-send.js', {ipc: true, verbose});21 t.is(getIpcLine(stderr), `${testTimestamp} [0] * ${foobarString}`);22 };23 24 test('Prints IPC, verbose "full"', testPrintIpc, 'full');25 test('Prints IPC, verbose "full", fd-specific', testPrintIpc, ipcFullOption);26 27 const testNoPrintIpc = async (t, verbose) => {28- const {stderr} = await parentExecaAsync('ipc-send.js', {ipc: true, verbose});28+ const {stderr} = await nestedSubprocess('ipc-send.js', {ipc: true, verbose});29 t.is(getIpcLine(stderr), undefined);30 };31 32 test('Does not print IPC, verbose default', testNoPrintIpc, undefined);3 unmodified lines36 test('Does not print IPC, verbose "none", fd-specific', testNoPrintIpc, ipcNoneOption);37 test('Does not print IPC, verbose "short", fd-specific', testNoPrintIpc, ipcShortOption);38 39 const testNoIpc = async (t, ipc) => {40- const subprocess = nestedExecaAsync('ipc-send.js', {ipc, verbose: 'full'});41- await t.throwsAsync(subprocess, {message: /sendMessage\(\) can only be used/});42- const {stderr} = await subprocess.parent;40+ const {nestedResult, stderr} = await nestedSubprocess('ipc-send.js', {ipc, verbose: 'full'});41+ t.true(nestedResult instanceof Error);42+ t.true(nestedResult.message.includes('sendMessage() can only be used'));43 t.is(getIpcLine(stderr), undefined);44 };45 46 test('Does not print IPC, ipc: false', testNoIpc, false);47 test('Does not print IPC, ipc: default', testNoIpc, undefined);48 49 test('Prints objects from IPC', async t => {50- const {stderr} = await parentExecaAsync('ipc-send-json.js', [JSON.stringify(foobarObject)], {ipc: true, verbose: 'full'});50+ const {stderr} = await nestedSubprocess('ipc-send-json.js', [JSON.stringify(foobarObject)], {ipc: true, verbose: 'full'});51 t.is(getIpcLine(stderr), `${testTimestamp} [0] * ${inspect(foobarObject)}`);52 });53 54 test('Prints multiline arrays from IPC', async t => {55 const bigArray = Array.from({length: 100}, (_, index) => index);56- const {stderr} = await parentExecaAsync('ipc-send-json.js', [JSON.stringify(bigArray)], {ipc: true, verbose: 'full'});56+ const {stderr} = await nestedSubprocess('ipc-send-json.js', [JSON.stringify(bigArray)], {ipc: true, verbose: 'full'});57 const ipcLines = getIpcLines(stderr);58 t.is(ipcLines[0], `${testTimestamp} [0] * [`);59 t.is(ipcLines.at(-2), `${testTimestamp} [0] * 96, 97, 98, 99`);60 t.is(ipcLines.at(-1), `${testTimestamp} [0] * ]`);61 });62 63 test('Does not quote spaces from IPC', async t => {64- const {stderr} = await parentExecaAsync('ipc-send.js', ['foo bar'], {ipc: true, verbose: 'full'});64+ const {stderr} = await nestedSubprocess('ipc-send.js', ['foo bar'], {ipc: true, verbose: 'full'});65 t.is(getIpcLine(stderr), `${testTimestamp} [0] * foo bar`);66 });67 68 test('Does not quote newlines from IPC', async t => {69- const {stderr} = await parentExecaAsync('ipc-send.js', ['foo\nbar'], {ipc: true, verbose: 'full'});69+ const {stderr} = await nestedSubprocess('ipc-send.js', ['foo\nbar'], {ipc: true, verbose: 'full'});70 t.deepEqual(getIpcLines(stderr), [71 `${testTimestamp} [0] * foo`,72 `${testTimestamp} [0] * bar`,73 ]);74 });75 76 test('Does not quote special punctuation from IPC', async t => {77- const {stderr} = await parentExecaAsync('ipc-send.js', ['%'], {ipc: true, verbose: 'full'});77+ const {stderr} = await nestedSubprocess('ipc-send.js', ['%'], {ipc: true, verbose: 'full'});78 t.is(getIpcLine(stderr), `${testTimestamp} [0] * %`);79 });80 81 test('Does not escape internal characters from IPC', async t => {82- const {stderr} = await parentExecaAsync('ipc-send.js', ['ã'], {ipc: true, verbose: 'full'});82+ const {stderr} = await nestedSubprocess('ipc-send.js', ['ã'], {ipc: true, verbose: 'full'});83 t.is(getIpcLine(stderr), `${testTimestamp} [0] * ã`);84 });85 86 test('Strips color sequences from IPC', async t => {87- const {stderr} = await parentExecaAsync('ipc-send.js', [red(foobarString)], {ipc: true, verbose: 'full'}, {env: {FORCE_COLOR: '1'}});87+ const {stderr} = await nestedSubprocess('ipc-send.js', [red(foobarString)], {ipc: true, verbose: 'full'}, {env: {FORCE_COLOR: '1'}});88 t.is(getIpcLine(stderr), `${testTimestamp} [0] * ${foobarString}`);89 });90 91 test('Escapes control characters from IPC', async t => {92- const {stderr} = await parentExecaAsync('ipc-send.js', ['\u0001'], {ipc: true, verbose: 'full'});92+ const {stderr} = await nestedSubprocess('ipc-send.js', ['\u0001'], {ipc: true, verbose: 'full'});93 t.is(getIpcLine(stderr), `${testTimestamp} [0] * \\u0001`);94 });95 96 test('Prints IPC progressively', async t => {97- const subprocess = parentExecaAsync('ipc-send-forever.js', {ipc: true, verbose: 'full'});97+ const subprocess = nestedInstance('ipc-send-forever.js', {ipc: true, verbose: 'full'});98 for await (const chunk of on(subprocess.stderr, 'data')) {99 const ipcLine = getIpcLine(chunk.toString());100 if (ipcLine !== undefined) {101 t.is(ipcLine, `${testTimestamp} [0] * ${foobarString}`);7 unmodified linesmodified:test/verbose/log.js+10 added-10 removed
1 import {stripVTControlCharacters} from 'node:util';2 import test from 'ava';3 import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4 import {foobarString} from '../helpers/input.js';5-import {parentExecaAsync, parentExecaSync} from '../helpers/nested.js';5+import {nestedSubprocess} from '../helpers/nested.js';6 7 setFixtureDirectory();8 9-const testNoStdout = async (t, verbose, execaMethod) => {10- const {stdout} = await execaMethod('noop.js', [foobarString], {verbose, stdio: 'inherit'});9+const testNoStdout = async (t, verbose, isSync) => {10+ const {stdout} = await nestedSubprocess('noop.js', [foobarString], {verbose, stdio: 'inherit', isSync});11 t.is(stdout, foobarString);12 };13 14-test('Logs on stderr not stdout, verbose "none"', testNoStdout, 'none', parentExecaAsync);15-test('Logs on stderr not stdout, verbose "short"', testNoStdout, 'short', parentExecaAsync);16-test('Logs on stderr not stdout, verbose "full"', testNoStdout, 'full', parentExecaAsync);17-test('Logs on stderr not stdout, verbose "none", sync', testNoStdout, 'none', parentExecaSync);18-test('Logs on stderr not stdout, verbose "short", sync', testNoStdout, 'short', parentExecaSync);19-test('Logs on stderr not stdout, verbose "full", sync', testNoStdout, 'full', parentExecaSync);14+test('Logs on stderr not stdout, verbose "none"', testNoStdout, 'none', false);15+test('Logs on stderr not stdout, verbose "short"', testNoStdout, 'short', false);16+test('Logs on stderr not stdout, verbose "full"', testNoStdout, 'full', false);17+test('Logs on stderr not stdout, verbose "none", sync', testNoStdout, 'none', true);18+test('Logs on stderr not stdout, verbose "short", sync', testNoStdout, 'short', true);19+test('Logs on stderr not stdout, verbose "full", sync', testNoStdout, 'full', true);20 21 const testColor = async (t, expectedResult, forceColor) => {22- const {stderr} = await parentExecaAsync('noop.js', [foobarString], {verbose: 'short'}, {env: {FORCE_COLOR: forceColor}});22+ const {stderr} = await nestedSubprocess('noop.js', [foobarString], {verbose: 'short'}, {env: {FORCE_COLOR: forceColor}});23 t.is(stderr !== stripVTControlCharacters(stderr), expectedResult);24 };25 26 test('Prints with colors if supported', testColor, true, '1');1 unmodified linemodified:test/verbose/output-buffer.js+19 added-19 removed
1 import test from 'ava';2 import {setFixtureDirectory} from '../helpers/fixtures-directory.js';3 import {foobarString, foobarUppercase} from '../helpers/input.js';4-import {parentExeca, parentExecaAsync, parentExecaSync} from '../helpers/nested.js';4+import {nestedSubprocess} from '../helpers/nested.js';5 import {6 getOutputLine,7 testTimestamp,8 stdoutNoneOption,2 unmodified lines11 } from '../helpers/verbose.js';12 13 setFixtureDirectory();14 15-const testPrintOutputNoBuffer = async (t, verbose, buffer, execaMethod) => {16- const {stderr} = await execaMethod('noop.js', [foobarString], {verbose, buffer});15+const testPrintOutputNoBuffer = async (t, verbose, buffer, isSync) => {16+ const {stderr} = await nestedSubprocess('noop.js', [foobarString], {verbose, buffer, isSync});17 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);18 };19 20-test('Prints stdout, buffer: false', testPrintOutputNoBuffer, 'full', false, parentExecaAsync);21-test('Prints stdout, buffer: false, fd-specific buffer', testPrintOutputNoBuffer, 'full', {stdout: false}, parentExecaAsync);22-test('Prints stdout, buffer: false, fd-specific verbose', testPrintOutputNoBuffer, stdoutFullOption, false, parentExecaAsync);23-test('Prints stdout, buffer: false, sync', testPrintOutputNoBuffer, 'full', false, parentExecaSync);24-test('Prints stdout, buffer: false, fd-specific buffer, sync', testPrintOutputNoBuffer, 'full', {stdout: false}, parentExecaSync);25-test('Prints stdout, buffer: false, fd-specific verbose, sync', testPrintOutputNoBuffer, stdoutFullOption, false, parentExecaSync);20+test('Prints stdout, buffer: false', testPrintOutputNoBuffer, 'full', false, false);21+test('Prints stdout, buffer: false, fd-specific buffer', testPrintOutputNoBuffer, 'full', {stdout: false}, false);22+test('Prints stdout, buffer: false, fd-specific verbose', testPrintOutputNoBuffer, stdoutFullOption, false, false);23+test('Prints stdout, buffer: false, sync', testPrintOutputNoBuffer, 'full', false, true);24+test('Prints stdout, buffer: false, fd-specific buffer, sync', testPrintOutputNoBuffer, 'full', {stdout: false}, true);25+test('Prints stdout, buffer: false, fd-specific verbose, sync', testPrintOutputNoBuffer, stdoutFullOption, false, true);26 27-const testPrintOutputNoBufferFalse = async (t, verbose, buffer, execaMethod) => {28- const {stderr} = await execaMethod('noop.js', [foobarString], {verbose, buffer});27+const testPrintOutputNoBufferFalse = async (t, verbose, buffer, isSync) => {28+ const {stderr} = await nestedSubprocess('noop.js', [foobarString], {verbose, buffer, isSync});29 t.is(getOutputLine(stderr), undefined);30 };31 32-test('Does not print stdout, buffer: false, fd-specific none', testPrintOutputNoBufferFalse, stdoutNoneOption, false, parentExecaAsync);33-test('Does not print stdout, buffer: false, different fd', testPrintOutputNoBufferFalse, stderrFullOption, false, parentExecaAsync);34-test('Does not print stdout, buffer: false, different fd, fd-specific buffer', testPrintOutputNoBufferFalse, stderrFullOption, {stdout: false}, parentExecaAsync);35-test('Does not print stdout, buffer: false, fd-specific none, sync', testPrintOutputNoBufferFalse, stdoutNoneOption, false, parentExecaSync);36-test('Does not print stdout, buffer: false, different fd, sync', testPrintOutputNoBufferFalse, stderrFullOption, false, parentExecaSync);37-test('Does not print stdout, buffer: false, different fd, fd-specific buffer, sync', testPrintOutputNoBufferFalse, stderrFullOption, {stdout: false}, parentExecaSync);32+test('Does not print stdout, buffer: false, fd-specific none', testPrintOutputNoBufferFalse, stdoutNoneOption, false, false);33+test('Does not print stdout, buffer: false, different fd', testPrintOutputNoBufferFalse, stderrFullOption, false, false);34+test('Does not print stdout, buffer: false, different fd, fd-specific buffer', testPrintOutputNoBufferFalse, stderrFullOption, {stdout: false}, false);35+test('Does not print stdout, buffer: false, fd-specific none, sync', testPrintOutputNoBufferFalse, stdoutNoneOption, false, true);36+test('Does not print stdout, buffer: false, different fd, sync', testPrintOutputNoBufferFalse, stderrFullOption, false, true);37+test('Does not print stdout, buffer: false, different fd, fd-specific buffer, sync', testPrintOutputNoBufferFalse, stderrFullOption, {stdout: false}, true);38 39 const testPrintOutputNoBufferTransform = async (t, buffer, isSync) => {40- const {stderr} = await parentExeca('nested-transform.js', 'noop.js', [foobarString], {40+ const {stderr} = await nestedSubprocess('noop.js', [foobarString], {41+ optionsFixture: 'generator-uppercase.js',42 verbose: 'full',43 buffer,43- type: 'generator',44 isSync,45 });46 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarUppercase}`);47 };5 unmodified linesmodified:test/verbose/output-enable.js+75 added-76 removed
1 import test from 'ava';2 import {red} from 'yoctocolors';3 import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4-import {foobarString} from '../helpers/input.js';4+import {foobarString, foobarUtf16Uint8Array} from '../helpers/input.js';5 import {fullStdio} from '../helpers/stdio.js';6+import {nestedSubprocess} from '../helpers/nested.js';7 import {7- nestedExecaAsync,8- parentExeca,9- parentExecaAsync,10- parentExecaSync,11-} from '../helpers/nested.js';12-import {13- runErrorSubprocessAsync,14- runErrorSubprocessSync,8+ runErrorSubprocess,9 getOutputLine,10 getOutputLines,11 testTimestamp,12 stdoutNoneOption,8 unmodified lines21 } from '../helpers/verbose.js';22 23 setFixtureDirectory();24 31-const testPrintOutput = async (t, verbose, fdNumber, execaMethod) => {32- const {stderr} = await execaMethod('noop-fd.js', [`${fdNumber}`, foobarString], {verbose});25+const testPrintOutput = async (t, verbose, fdNumber, isSync) => {26+ const {stderr} = await nestedSubprocess('noop-fd.js', [`${fdNumber}`, foobarString], {verbose, isSync});27 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);28 };29 36-test('Prints stdout, verbose "full"', testPrintOutput, 'full', 1, parentExecaAsync);37-test('Prints stderr, verbose "full"', testPrintOutput, 'full', 2, parentExecaAsync);38-test('Prints stdout, verbose "full", fd-specific', testPrintOutput, stdoutFullOption, 1, parentExecaAsync);39-test('Prints stderr, verbose "full", fd-specific', testPrintOutput, stderrFullOption, 2, parentExecaAsync);40-test('Prints stdout, verbose "full", sync', testPrintOutput, 'full', 1, parentExecaSync);41-test('Prints stderr, verbose "full", sync', testPrintOutput, 'full', 2, parentExecaSync);42-test('Prints stdout, verbose "full", fd-specific, sync', testPrintOutput, stdoutFullOption, 1, parentExecaSync);43-test('Prints stderr, verbose "full", fd-specific, sync', testPrintOutput, stderrFullOption, 2, parentExecaSync);30+test('Prints stdout, verbose "full"', testPrintOutput, 'full', 1, false);31+test('Prints stderr, verbose "full"', testPrintOutput, 'full', 2, false);32+test('Prints stdout, verbose "full", fd-specific', testPrintOutput, stdoutFullOption, 1, false);33+test('Prints stderr, verbose "full", fd-specific', testPrintOutput, stderrFullOption, 2, false);34+test('Prints stdout, verbose "full", sync', testPrintOutput, 'full', 1, true);35+test('Prints stderr, verbose "full", sync', testPrintOutput, 'full', 2, true);36+test('Prints stdout, verbose "full", fd-specific, sync', testPrintOutput, stdoutFullOption, 1, true);37+test('Prints stderr, verbose "full", fd-specific, sync', testPrintOutput, stderrFullOption, 2, true);38 45-const testNoPrintOutput = async (t, verbose, fdNumber, execaMethod) => {46- const {stderr} = await execaMethod('noop-fd.js', [`${fdNumber}`, foobarString], {verbose, ...fullStdio});39+const testNoPrintOutput = async (t, verbose, fdNumber, isSync) => {40+ const {stderr} = await nestedSubprocess('noop-fd.js', [`${fdNumber}`, foobarString], {verbose, ...fullStdio, isSync});41 t.is(getOutputLine(stderr), undefined);42 };43 50-test('Does not print stdout, verbose default', testNoPrintOutput, undefined, 1, parentExecaAsync);51-test('Does not print stdout, verbose "none"', testNoPrintOutput, 'none', 1, parentExecaAsync);52-test('Does not print stdout, verbose "short"', testNoPrintOutput, 'short', 1, parentExecaAsync);53-test('Does not print stderr, verbose default', testNoPrintOutput, undefined, 2, parentExecaAsync);54-test('Does not print stderr, verbose "none"', testNoPrintOutput, 'none', 2, parentExecaAsync);55-test('Does not print stderr, verbose "short"', testNoPrintOutput, 'short', 2, parentExecaAsync);56-test('Does not print stdio[*], verbose default', testNoPrintOutput, undefined, 3, parentExecaAsync);57-test('Does not print stdio[*], verbose "none"', testNoPrintOutput, 'none', 3, parentExecaAsync);58-test('Does not print stdio[*], verbose "short"', testNoPrintOutput, 'short', 3, parentExecaAsync);59-test('Does not print stdio[*], verbose "full"', testNoPrintOutput, 'full', 3, parentExecaAsync);60-test('Does not print stdout, verbose default, fd-specific', testNoPrintOutput, {}, 1, parentExecaAsync);61-test('Does not print stdout, verbose "none", fd-specific', testNoPrintOutput, stdoutNoneOption, 1, parentExecaAsync);62-test('Does not print stdout, verbose "short", fd-specific', testNoPrintOutput, stdoutShortOption, 1, parentExecaAsync);63-test('Does not print stderr, verbose default, fd-specific', testNoPrintOutput, {}, 2, parentExecaAsync);64-test('Does not print stderr, verbose "none", fd-specific', testNoPrintOutput, stderrNoneOption, 2, parentExecaAsync);65-test('Does not print stderr, verbose "short", fd-specific', testNoPrintOutput, stderrShortOption, 2, parentExecaAsync);66-test('Does not print stdio[*], verbose default, fd-specific', testNoPrintOutput, {}, 3, parentExecaAsync);67-test('Does not print stdio[*], verbose "none", fd-specific', testNoPrintOutput, fd3NoneOption, 3, parentExecaAsync);68-test('Does not print stdio[*], verbose "short", fd-specific', testNoPrintOutput, fd3ShortOption, 3, parentExecaAsync);69-test('Does not print stdio[*], verbose "full", fd-specific', testNoPrintOutput, fd3FullOption, 3, parentExecaAsync);70-test('Does not print stdout, verbose default, sync', testNoPrintOutput, undefined, 1, parentExecaSync);71-test('Does not print stdout, verbose "none", sync', testNoPrintOutput, 'none', 1, parentExecaSync);72-test('Does not print stdout, verbose "short", sync', testNoPrintOutput, 'short', 1, parentExecaSync);73-test('Does not print stderr, verbose default, sync', testNoPrintOutput, undefined, 2, parentExecaSync);74-test('Does not print stderr, verbose "none", sync', testNoPrintOutput, 'none', 2, parentExecaSync);75-test('Does not print stderr, verbose "short", sync', testNoPrintOutput, 'short', 2, parentExecaSync);76-test('Does not print stdio[*], verbose default, sync', testNoPrintOutput, undefined, 3, parentExecaSync);77-test('Does not print stdio[*], verbose "none", sync', testNoPrintOutput, 'none', 3, parentExecaSync);78-test('Does not print stdio[*], verbose "short", sync', testNoPrintOutput, 'short', 3, parentExecaSync);79-test('Does not print stdio[*], verbose "full", sync', testNoPrintOutput, 'full', 3, parentExecaSync);80-test('Does not print stdout, verbose default, fd-specific, sync', testNoPrintOutput, {}, 1, parentExecaSync);81-test('Does not print stdout, verbose "none", fd-specific, sync', testNoPrintOutput, stdoutNoneOption, 1, parentExecaSync);82-test('Does not print stdout, verbose "short", fd-specific, sync', testNoPrintOutput, stdoutShortOption, 1, parentExecaSync);83-test('Does not print stderr, verbose default, fd-specific, sync', testNoPrintOutput, {}, 2, parentExecaSync);84-test('Does not print stderr, verbose "none", fd-specific, sync', testNoPrintOutput, stderrNoneOption, 2, parentExecaSync);85-test('Does not print stderr, verbose "short", fd-specific, sync', testNoPrintOutput, stderrShortOption, 2, parentExecaSync);86-test('Does not print stdio[*], verbose default, fd-specific, sync', testNoPrintOutput, {}, 3, parentExecaSync);87-test('Does not print stdio[*], verbose "none", fd-specific, sync', testNoPrintOutput, fd3NoneOption, 3, parentExecaSync);88-test('Does not print stdio[*], verbose "short", fd-specific, sync', testNoPrintOutput, fd3ShortOption, 3, parentExecaSync);89-test('Does not print stdio[*], verbose "full", fd-specific, sync', testNoPrintOutput, fd3FullOption, 3, parentExecaSync);44+test('Does not print stdout, verbose default', testNoPrintOutput, undefined, 1, false);45+test('Does not print stdout, verbose "none"', testNoPrintOutput, 'none', 1, false);46+test('Does not print stdout, verbose "short"', testNoPrintOutput, 'short', 1, false);47+test('Does not print stderr, verbose default', testNoPrintOutput, undefined, 2, false);48+test('Does not print stderr, verbose "none"', testNoPrintOutput, 'none', 2, false);49+test('Does not print stderr, verbose "short"', testNoPrintOutput, 'short', 2, false);50+test('Does not print stdio[*], verbose default', testNoPrintOutput, undefined, 3, false);51+test('Does not print stdio[*], verbose "none"', testNoPrintOutput, 'none', 3, false);52+test('Does not print stdio[*], verbose "short"', testNoPrintOutput, 'short', 3, false);53+test('Does not print stdio[*], verbose "full"', testNoPrintOutput, 'full', 3, false);54+test('Does not print stdout, verbose default, fd-specific', testNoPrintOutput, {}, 1, false);55+test('Does not print stdout, verbose "none", fd-specific', testNoPrintOutput, stdoutNoneOption, 1, false);56+test('Does not print stdout, verbose "short", fd-specific', testNoPrintOutput, stdoutShortOption, 1, false);57+test('Does not print stderr, verbose default, fd-specific', testNoPrintOutput, {}, 2, false);58+test('Does not print stderr, verbose "none", fd-specific', testNoPrintOutput, stderrNoneOption, 2, false);59+test('Does not print stderr, verbose "short", fd-specific', testNoPrintOutput, stderrShortOption, 2, false);60+test('Does not print stdio[*], verbose default, fd-specific', testNoPrintOutput, {}, 3, false);61+test('Does not print stdio[*], verbose "none", fd-specific', testNoPrintOutput, fd3NoneOption, 3, false);62+test('Does not print stdio[*], verbose "short", fd-specific', testNoPrintOutput, fd3ShortOption, 3, false);63+test('Does not print stdio[*], verbose "full", fd-specific', testNoPrintOutput, fd3FullOption, 3, false);64+test('Does not print stdout, verbose default, sync', testNoPrintOutput, undefined, 1, true);65+test('Does not print stdout, verbose "none", sync', testNoPrintOutput, 'none', 1, true);66+test('Does not print stdout, verbose "short", sync', testNoPrintOutput, 'short', 1, true);67+test('Does not print stderr, verbose default, sync', testNoPrintOutput, undefined, 2, true);68+test('Does not print stderr, verbose "none", sync', testNoPrintOutput, 'none', 2, true);69+test('Does not print stderr, verbose "short", sync', testNoPrintOutput, 'short', 2, true);70+test('Does not print stdio[*], verbose default, sync', testNoPrintOutput, undefined, 3, true);71+test('Does not print stdio[*], verbose "none", sync', testNoPrintOutput, 'none', 3, true);72+test('Does not print stdio[*], verbose "short", sync', testNoPrintOutput, 'short', 3, true);73+test('Does not print stdio[*], verbose "full", sync', testNoPrintOutput, 'full', 3, true);74+test('Does not print stdout, verbose default, fd-specific, sync', testNoPrintOutput, {}, 1, true);75+test('Does not print stdout, verbose "none", fd-specific, sync', testNoPrintOutput, stdoutNoneOption, 1, true);76+test('Does not print stdout, verbose "short", fd-specific, sync', testNoPrintOutput, stdoutShortOption, 1, true);77+test('Does not print stderr, verbose default, fd-specific, sync', testNoPrintOutput, {}, 2, true);78+test('Does not print stderr, verbose "none", fd-specific, sync', testNoPrintOutput, stderrNoneOption, 2, true);79+test('Does not print stderr, verbose "short", fd-specific, sync', testNoPrintOutput, stderrShortOption, 2, true);80+test('Does not print stdio[*], verbose default, fd-specific, sync', testNoPrintOutput, {}, 3, true);81+test('Does not print stdio[*], verbose "none", fd-specific, sync', testNoPrintOutput, fd3NoneOption, 3, true);82+test('Does not print stdio[*], verbose "short", fd-specific, sync', testNoPrintOutput, fd3ShortOption, 3, true);83+test('Does not print stdio[*], verbose "full", fd-specific, sync', testNoPrintOutput, fd3FullOption, 3, true);84 91-const testPrintError = async (t, execaMethod) => {92- const stderr = await execaMethod(t, 'full');85+const testPrintError = async (t, isSync) => {86+ const stderr = await runErrorSubprocess(t, 'full', isSync);87 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);88 };89 96-test('Prints stdout after errors', testPrintError, runErrorSubprocessAsync);97-test('Prints stdout after errors, sync', testPrintError, runErrorSubprocessSync);90+test('Prints stdout after errors', testPrintError, false);91+test('Prints stdout after errors, sync', testPrintError, true);92 93 test('Does not quote spaces from stdout', async t => {100- const {stderr} = await parentExecaAsync('noop.js', ['foo bar'], {verbose: 'full'});94+ const {stderr} = await nestedSubprocess('noop.js', ['foo bar'], {verbose: 'full'});95 t.is(getOutputLine(stderr), `${testTimestamp} [0] foo bar`);96 });97 98 test('Does not quote special punctuation from stdout', async t => {105- const {stderr} = await parentExecaAsync('noop.js', ['%'], {verbose: 'full'});99+ const {stderr} = await nestedSubprocess('noop.js', ['%'], {verbose: 'full'});100 t.is(getOutputLine(stderr), `${testTimestamp} [0] %`);101 });102 103 test('Does not escape internal characters from stdout', async t => {110- const {stderr} = await parentExecaAsync('noop.js', ['ã'], {verbose: 'full'});104+ const {stderr} = await nestedSubprocess('noop.js', ['ã'], {verbose: 'full'});105 t.is(getOutputLine(stderr), `${testTimestamp} [0] ã`);106 });107 108 test('Strips color sequences from stdout', async t => {115- const {stderr} = await parentExecaAsync('noop.js', [red(foobarString)], {verbose: 'full'}, {env: {FORCE_COLOR: '1'}});109+ const {stderr} = await nestedSubprocess('noop.js', [red(foobarString)], {verbose: 'full'}, {env: {FORCE_COLOR: '1'}});110 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);111 });112 113 test('Escapes control characters from stdout', async t => {120- const {stderr} = await parentExecaAsync('noop.js', ['\u0001'], {verbose: 'full'});114+ const {stderr} = await nestedSubprocess('noop.js', ['\u0001'], {verbose: 'full'});115 t.is(getOutputLine(stderr), `${testTimestamp} [0] \\u0001`);116 });117 118 const testStdioSame = async (t, fdNumber) => {125- const {stdio} = await nestedExecaAsync('noop-fd.js', [`${fdNumber}`, foobarString], {verbose: 'full'});119+ const {nestedResult: {stdio}} = await nestedSubprocess('noop-fd.js', [`${fdNumber}`, foobarString], {verbose: 'full'});120 t.is(stdio[fdNumber], foobarString);121 };122 123 test('Does not change subprocess.stdout', testStdioSame, 1);124 test('Does not change subprocess.stderr', testStdioSame, 2);125 132-const testSingleNewline = async (t, execaMethod) => {133- const {stderr} = await execaMethod('noop-fd.js', ['1', '\n'], {verbose: 'full'});126+const testSingleNewline = async (t, isSync) => {127+ const {stderr} = await nestedSubprocess('noop-fd.js', ['1', '\n'], {verbose: 'full', isSync});128 t.deepEqual(getOutputLines(stderr), [`${testTimestamp} [0] `]);129 };130 137-test('Prints stdout, single newline', testSingleNewline, parentExecaAsync);138-test('Prints stdout, single newline, sync', testSingleNewline, parentExecaSync);131+test('Prints stdout, single newline', testSingleNewline, false);132+test('Prints stdout, single newline, sync', testSingleNewline, true);133 134 const testUtf16 = async (t, isSync) => {141- const {stderr} = await parentExeca('nested-input.js', 'stdin.js', [`${isSync}`], {verbose: 'full', encoding: 'utf16le'});135+ const {stderr} = await nestedSubprocess('stdin.js', {136+ verbose: 'full',137+ input: foobarUtf16Uint8Array,138+ encoding: 'utf16le',139+ isSync,140+ });141 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);142 };143 144 test('Can use encoding UTF16, verbose "full"', testUtf16, false);1 unmodified linemodified:test/verbose/output-mixed.js+45 added-17 removed
1 unmodified line2 import test from 'ava';3 import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4 import {foobarString, foobarObject} from '../helpers/input.js';5 import {simpleFull, noNewlinesChunks} from '../helpers/lines.js';6-import {parentExeca, parentExecaAsync, parentExecaSync} from '../helpers/nested.js';6+import {nestedSubprocess} from '../helpers/nested.js';7 import {getOutputLine, getOutputLines, testTimestamp} from '../helpers/verbose.js';8 9 setFixtureDirectory();10 11-const testLines = async (t, lines, stripFinalNewline, execaMethod) => {12- const {stderr} = await execaMethod('noop-fd.js', ['1', simpleFull], {verbose: 'full', lines, stripFinalNewline});11+const testLines = async (t, lines, stripFinalNewline, isSync) => {12+ const {stderr} = await nestedSubprocess('noop-fd.js', ['1', simpleFull], {13+ verbose: 'full',14+ lines,15+ stripFinalNewline,16+ isSync,17+ });18 t.deepEqual(getOutputLines(stderr), noNewlinesChunks.map(line => `${testTimestamp} [0] ${line}`));19 };20 16-test('Prints stdout, "lines: true"', testLines, true, false, parentExecaAsync);17-test('Prints stdout, "lines: true", fd-specific', testLines, {stdout: true}, false, parentExecaAsync);18-test('Prints stdout, "lines: true", stripFinalNewline', testLines, true, true, parentExecaAsync);19-test('Prints stdout, "lines: true", sync', testLines, true, false, parentExecaSync);20-test('Prints stdout, "lines: true", fd-specific, sync', testLines, {stdout: true}, false, parentExecaSync);21-test('Prints stdout, "lines: true", stripFinalNewline, sync', testLines, true, true, parentExecaSync);21+test('Prints stdout, "lines: true"', testLines, true, false, false);22+test('Prints stdout, "lines: true", fd-specific', testLines, {stdout: true}, false, false);23+test('Prints stdout, "lines: true", stripFinalNewline', testLines, true, true, false);24+test('Prints stdout, "lines: true", sync', testLines, true, false, true);25+test('Prints stdout, "lines: true", fd-specific, sync', testLines, {stdout: true}, false, true);26+test('Prints stdout, "lines: true", stripFinalNewline, sync', testLines, true, true, true);27 23-const testOnlyTransforms = async (t, type, isSync) => {24- const {stderr} = await parentExeca('nested-transform.js', 'noop.js', [foobarString], {verbose: 'full', type, isSync});28+const testOnlyTransforms = async (t, isSync) => {29+ const {stderr} = await nestedSubprocess('noop.js', [foobarString], {30+ optionsFixture: 'generator-uppercase.js',31+ verbose: 'full',32+ isSync,33+ });34 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString.toUpperCase()}`);35 };36 28-test('Prints stdout with only transforms', testOnlyTransforms, 'generator', false);29-test('Prints stdout with only transforms, sync', testOnlyTransforms, 'generator', true);30-test('Prints stdout with only duplexes', testOnlyTransforms, 'duplex', false);37+test('Prints stdout with only transforms', testOnlyTransforms, false);38+test('Prints stdout with only transforms, sync', testOnlyTransforms, true);39 40+test('Prints stdout with only duplexes', async t => {41+ const {stderr} = await nestedSubprocess('noop.js', [foobarString], {42+ optionsFixture: 'generator-duplex.js',43+ verbose: 'full',44+ });45+ t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString.toUpperCase()}`);46+});47+48 const testObjectMode = async (t, isSync) => {33- const {stderr} = await parentExeca('nested-transform.js', 'noop.js', {verbose: 'full', transformName: 'object', isSync});49+ const {stderr} = await nestedSubprocess('noop.js', {50+ optionsFixture: 'generator-object.js',51+ verbose: 'full',52+ isSync,53+ });54 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${inspect(foobarObject)}`);55 };56 57 test('Prints stdout with object transforms', testObjectMode, false);58 test('Prints stdout with object transforms, sync', testObjectMode, true);59 60 const testBigArray = async (t, isSync) => {41- const {stderr} = await parentExeca('nested-transform.js', 'noop.js', {verbose: 'full', transformName: 'bigArray', isSync});61+ const {stderr} = await nestedSubprocess('noop.js', {62+ optionsFixture: 'generator-big-array.js',63+ verbose: 'full',64+ isSync,65+ });66 const lines = getOutputLines(stderr);67 t.is(lines[0], `${testTimestamp} [0] [`);68 t.true(lines[1].startsWith(`${testTimestamp} [0] 0, 1,`));69 t.is(lines.at(-1), `${testTimestamp} [0] ]`);2 unmodified lines72 test('Prints stdout with big object transforms', testBigArray, false);73 test('Prints stdout with big object transforms, sync', testBigArray, true);74 75 const testObjectModeString = async (t, isSync) => {52- const {stderr} = await parentExeca('nested-transform.js', 'noop.js', {verbose: 'full', transformName: 'stringObject', isSync});76+ const {stderr} = await nestedSubprocess('noop.js', {77+ optionsFixture: 'generator-string-object.js',78+ verbose: 'full',79+ isSync,80+ });81 t.deepEqual(getOutputLines(stderr), noNewlinesChunks.map(line => `${testTimestamp} [0] ${line}`));82 };83 84 test('Prints stdout with string transforms in objectMode', testObjectModeString, false);1 unmodified linemodified:test/verbose/output-noop.js+53 added-33 removed
1 unmodified line2 import test from 'ava';3 import tempfile from 'tempfile';4 import {setFixtureDirectory} from '../helpers/fixtures-directory.js';5 import {foobarString} from '../helpers/input.js';6-import {parentExeca, parentExecaAsync, parentExecaSync} from '../helpers/nested.js';6+import {nestedSubprocess} from '../helpers/nested.js';7 import {getOutputLine, testTimestamp} from '../helpers/verbose.js';8 9 setFixtureDirectory();10 11-const testNoOutputOptions = async (t, fixtureName, options = {}) => {12- const {stderr} = await parentExeca(fixtureName, 'noop.js', [foobarString], {verbose: 'full', ...options});11+const testNoOutputOptions = async (t, isSync, options) => {12+ const {stderr} = await nestedSubprocess('noop.js', [foobarString], {verbose: 'full', isSync, ...options});13 t.is(getOutputLine(stderr), undefined);14 };15 16-test('Does not print stdout, encoding "buffer"', testNoOutputOptions, 'nested.js', {encoding: 'buffer'});17-test('Does not print stdout, encoding "hex"', testNoOutputOptions, 'nested.js', {encoding: 'hex'});18-test('Does not print stdout, encoding "base64"', testNoOutputOptions, 'nested.js', {encoding: 'base64'});19-test('Does not print stdout, stdout "ignore"', testNoOutputOptions, 'nested.js', {stdout: 'ignore'});20-test('Does not print stdout, stdout "inherit"', testNoOutputOptions, 'nested.js', {stdout: 'inherit'});21-test('Does not print stdout, stdout 1', testNoOutputOptions, 'nested.js', {stdout: 1});22-test('Does not print stdout, stdout Writable', testNoOutputOptions, 'nested-writable.js');23-test('Does not print stdout, stdout WritableStream', testNoOutputOptions, 'nested-writable-web.js');24-test('Does not print stdout, .pipe(stream)', testNoOutputOptions, 'nested-pipe-stream.js');25-test('Does not print stdout, .pipe(subprocess)', testNoOutputOptions, 'nested-pipe-subprocess.js');26-test('Does not print stdout, encoding "buffer", sync', testNoOutputOptions, 'nested-sync.js', {encoding: 'buffer'});27-test('Does not print stdout, encoding "hex", sync', testNoOutputOptions, 'nested-sync.js', {encoding: 'hex'});28-test('Does not print stdout, encoding "base64", sync', testNoOutputOptions, 'nested-sync.js', {encoding: 'base64'});29-test('Does not print stdout, stdout "ignore", sync', testNoOutputOptions, 'nested-sync.js', {stdout: 'ignore'});30-test('Does not print stdout, stdout "inherit", sync', testNoOutputOptions, 'nested-sync.js', {stdout: 'inherit'});31-test('Does not print stdout, stdout 1, sync', testNoOutputOptions, 'nested-sync.js', {stdout: 1});16+test('Does not print stdout, encoding "buffer"', testNoOutputOptions, false, {encoding: 'buffer'});17+test('Does not print stdout, encoding "hex"', testNoOutputOptions, false, {encoding: 'hex'});18+test('Does not print stdout, encoding "base64"', testNoOutputOptions, false, {encoding: 'base64'});19+test('Does not print stdout, stdout "ignore"', testNoOutputOptions, false, {stdout: 'ignore'});20+test('Does not print stdout, stdout "inherit"', testNoOutputOptions, false, {stdout: 'inherit'});21+test('Does not print stdout, stdout 1', testNoOutputOptions, false, {stdout: 1});22+test('Does not print stdout, encoding "buffer", sync', testNoOutputOptions, true, {encoding: 'buffer'});23+test('Does not print stdout, encoding "hex", sync', testNoOutputOptions, true, {encoding: 'hex'});24+test('Does not print stdout, encoding "base64", sync', testNoOutputOptions, true, {encoding: 'base64'});25+test('Does not print stdout, stdout "ignore", sync', testNoOutputOptions, true, {stdout: 'ignore'});26+test('Does not print stdout, stdout "inherit", sync', testNoOutputOptions, true, {stdout: 'inherit'});27+test('Does not print stdout, stdout 1, sync', testNoOutputOptions, true, {stdout: 1});28 33-const testStdoutFile = async (t, fixtureName, getStdout) => {29+const testNoOutputDynamic = async (t, isSync, optionsFixture) => {30+ const {stderr} = await nestedSubprocess('noop.js', [foobarString], {verbose: 'full', isSync, optionsFixture});31+ t.is(getOutputLine(stderr), undefined);32+};33+34+test('Does not print stdout, stdout Writable', testNoOutputDynamic, false, 'writable.js');35+test('Does not print stdout, stdout WritableStream', testNoOutputDynamic, false, 'writable-web.js');36+test('Does not print stdout, stdout Writable, sync', testNoOutputDynamic, true, 'writable.js');37+test('Does not print stdout, stdout WritableStream, sync', testNoOutputDynamic, true, 'writable-web.js');38+39+const testNoOutputStream = async (t, parentFixture) => {40+ const {stderr} = await nestedSubprocess('noop.js', [foobarString], {verbose: 'full', parentFixture});41+ t.is(getOutputLine(stderr), undefined);42+};43+44+test('Does not print stdout, .pipe(stream)', testNoOutputStream, 'nested-pipe-stream.js');45+test('Does not print stdout, .pipe(subprocess)', testNoOutputStream, 'nested-pipe-subprocess.js');46+47+const testStdoutFile = async (t, isSync, optionsFixture) => {48 const file = tempfile();35- const {stderr} = await parentExeca(fixtureName, 'noop.js', [foobarString], {verbose: 'full', stdout: getStdout(file)});49+ const {stderr} = await nestedSubprocess('noop.js', [foobarString], {50+ verbose: 'full',51+ stdout: {file},52+ isSync,53+ optionsFixture,54+ });55 t.is(getOutputLine(stderr), undefined);56 const contents = await readFile(file, 'utf8');57 t.is(contents.trim(), foobarString);58 await rm(file);59 };60 42-test('Does not print stdout, stdout { file }', testStdoutFile, 'nested.js', file => ({file}));43-test('Does not print stdout, stdout fileUrl', testStdoutFile, 'nested-file-url.js', file => file);44-test('Does not print stdout, stdout { file }, sync', testStdoutFile, 'nested-sync.js', file => ({file}));61+test('Does not print stdout, stdout { file }', testStdoutFile, false);62+test('Does not print stdout, stdout fileUrl', testStdoutFile, false, 'file-url.js');63+test('Does not print stdout, stdout { file }, sync', testStdoutFile, true);64+test('Does not print stdout, stdout fileUrl, sync', testStdoutFile, true, 'file-url.js');65 46-const testPrintOutputOptions = async (t, options, execaMethod) => {47- const {stderr} = await execaMethod('noop.js', [foobarString], {verbose: 'full', ...options});66+const testPrintOutputOptions = async (t, options, isSync) => {67+ const {stderr} = await nestedSubprocess('noop.js', [foobarString], {verbose: 'full', isSync, ...options});68 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);69 };70 51-test('Prints stdout, stdout "pipe"', testPrintOutputOptions, {stdout: 'pipe'}, parentExecaAsync);52-test('Prints stdout, stdout "overlapped"', testPrintOutputOptions, {stdout: 'overlapped'}, parentExecaAsync);53-test('Prints stdout, stdout null', testPrintOutputOptions, {stdout: null}, parentExecaAsync);54-test('Prints stdout, stdout ["pipe"]', testPrintOutputOptions, {stdout: ['pipe']}, parentExecaAsync);55-test('Prints stdout, stdout "pipe", sync', testPrintOutputOptions, {stdout: 'pipe'}, parentExecaSync);56-test('Prints stdout, stdout null, sync', testPrintOutputOptions, {stdout: null}, parentExecaSync);57-test('Prints stdout, stdout ["pipe"], sync', testPrintOutputOptions, {stdout: ['pipe']}, parentExecaSync);71+test('Prints stdout, stdout "pipe"', testPrintOutputOptions, {stdout: 'pipe'}, false);72+test('Prints stdout, stdout "overlapped"', testPrintOutputOptions, {stdout: 'overlapped'}, false);73+test('Prints stdout, stdout null', testPrintOutputOptions, {stdout: null}, false);74+test('Prints stdout, stdout ["pipe"]', testPrintOutputOptions, {stdout: ['pipe']}, false);75+test('Prints stdout, stdout "pipe", sync', testPrintOutputOptions, {stdout: 'pipe'}, true);76+test('Prints stdout, stdout null, sync', testPrintOutputOptions, {stdout: null}, true);77+test('Prints stdout, stdout ["pipe"], sync', testPrintOutputOptions, {stdout: ['pipe']}, true);modified:test/verbose/output-pipe.js+24 added-26 removed
1 import test from 'ava';2-import {execa} from '../../index.js';2 import {setFixtureDirectory} from '../helpers/fixtures-directory.js';3 import {foobarString} from '../helpers/input.js';5-import {parentExeca} from '../helpers/nested.js';4+import {nestedSubprocess} from '../helpers/nested.js';5 import {6 getOutputLine,7 getOutputLines,8 testTimestamp,1 unmodified line10 } from '../helpers/verbose.js';11 12 setFixtureDirectory();13 15-const testPipeOutput = async (t, fixtureName, sourceVerbose, destinationVerbose) => {16- const {stderr} = await execa(`nested-pipe-${fixtureName}.js`, [17- JSON.stringify(getVerboseOption(sourceVerbose, 'full')),18- 'noop.js',19- foobarString,20- JSON.stringify(getVerboseOption(destinationVerbose, 'full')),21- 'stdin.js',22- ]);14+const testPipeOutput = async (t, parentFixture, sourceVerbose, destinationVerbose) => {15+ const {stderr} = await nestedSubprocess('noop.js', [foobarString], {16+ parentFixture,17+ sourceOptions: getVerboseOption(sourceVerbose, 'full'),18+ destinationFile: 'stdin.js',19+ destinationOptions: getVerboseOption(destinationVerbose, 'full'),20+ });21 22 const lines = getOutputLines(stderr);23 const id = sourceVerbose && destinationVerbose ? 1 : 0;24 t.deepEqual(lines, destinationVerbose25 ? [`${testTimestamp} [${id}] ${foobarString}`]26 : []);27 };28 31-test('Prints stdout if both verbose with .pipe("file")', testPipeOutput, 'file', true, true);32-test('Prints stdout if both verbose with .pipe`command`', testPipeOutput, 'script', true, true);33-test('Prints stdout if both verbose with .pipe(subprocess)', testPipeOutput, 'subprocesses', true, true);34-test('Prints stdout if only second verbose with .pipe("file")', testPipeOutput, 'file', false, true);35-test('Prints stdout if only second verbose with .pipe`command`', testPipeOutput, 'script', false, true);36-test('Prints stdout if only second verbose with .pipe(subprocess)', testPipeOutput, 'subprocesses', false, true);37-test('Does not print stdout if only first verbose with .pipe("file")', testPipeOutput, 'file', true, false);38-test('Does not print stdout if only first verbose with .pipe`command`', testPipeOutput, 'script', true, false);39-test('Does not print stdout if only first verbose with .pipe(subprocess)', testPipeOutput, 'subprocesses', true, false);40-test('Does not print stdout if neither verbose with .pipe("file")', testPipeOutput, 'file', false, false);41-test('Does not print stdout if neither verbose with .pipe`command`', testPipeOutput, 'script', false, false);42-test('Does not print stdout if neither verbose with .pipe(subprocess)', testPipeOutput, 'subprocesses', false, false);29+test('Prints stdout if both verbose with .pipe("file")', testPipeOutput, 'nested-pipe-file.js', true, true);30+test('Prints stdout if both verbose with .pipe`command`', testPipeOutput, 'nested-pipe-script.js', true, true);31+test('Prints stdout if both verbose with .pipe(subprocess)', testPipeOutput, 'nested-pipe-subprocesses.js', true, true);32+test('Prints stdout if only second verbose with .pipe("file")', testPipeOutput, 'nested-pipe-file.js', false, true);33+test('Prints stdout if only second verbose with .pipe`command`', testPipeOutput, 'nested-pipe-script.js', false, true);34+test('Prints stdout if only second verbose with .pipe(subprocess)', testPipeOutput, 'nested-pipe-subprocesses.js', false, true);35+test('Does not print stdout if only first verbose with .pipe("file")', testPipeOutput, 'nested-pipe-file.js', true, false);36+test('Does not print stdout if only first verbose with .pipe`command`', testPipeOutput, 'nested-pipe-script.js', true, false);37+test('Does not print stdout if only first verbose with .pipe(subprocess)', testPipeOutput, 'nested-pipe-subprocesses.js', true, false);38+test('Does not print stdout if neither verbose with .pipe("file")', testPipeOutput, 'nested-pipe-file.js', false, false);39+test('Does not print stdout if neither verbose with .pipe`command`', testPipeOutput, 'nested-pipe-script.js', false, false);40+test('Does not print stdout if neither verbose with .pipe(subprocess)', testPipeOutput, 'nested-pipe-subprocesses.js', false, false);41 44-const testPrintOutputFixture = async (t, fixtureName, ...commandArguments) => {45- const {stderr} = await parentExeca(fixtureName, 'noop.js', [foobarString, ...commandArguments], {verbose: 'full'});42+const testPrintOutputFixture = async (t, parentFixture) => {43+ const {stderr} = await nestedSubprocess('noop.js', [foobarString], {parentFixture, verbose: 'full', unpipe: true});44 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);45 };46 49-test('Prints stdout, .pipe(stream) + .unpipe()', testPrintOutputFixture, 'nested-pipe-stream.js', 'true');50-test('Prints stdout, .pipe(subprocess) + .unpipe()', testPrintOutputFixture, 'nested-pipe-subprocess.js', 'true');47+test('Prints stdout, .pipe(stream) + .unpipe()', testPrintOutputFixture, 'nested-pipe-stream.js');48+test('Prints stdout, .pipe(subprocess) + .unpipe()', testPrintOutputFixture, 'nested-pipe-subprocess.js');modified:test/verbose/output-progressive.js+7 added-7 removed
1 import {on} from 'node:events';2 import test from 'ava';3 import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4 import {foobarString} from '../helpers/input.js';5-import {parentExeca, parentExecaAsync, parentExecaSync} from '../helpers/nested.js';5+import {nestedSubprocess, nestedInstance} from '../helpers/nested.js';6 import {getOutputLine, getOutputLines, testTimestamp} from '../helpers/verbose.js';7 8 setFixtureDirectory();9 10 test('Prints stdout one line at a time', async t => {11- const subprocess = parentExecaAsync('noop-progressive.js', [foobarString], {verbose: 'full'});11+ const subprocess = nestedInstance('noop-progressive.js', [foobarString], {verbose: 'full'});12 13 for await (const chunk of on(subprocess.stderr, 'data')) {14 const outputLine = getOutputLine(chunk.toString().trim());15 if (outputLine !== undefined) {5 unmodified lines21 await subprocess;22 });23 24 test.serial('Prints stdout progressively, interleaved', async t => {25- const subprocess = parentExeca('nested-double.js', 'noop-repeat.js', ['1', `${foobarString}\n`], {verbose: 'full'});25+ const subprocess = nestedInstance('noop-repeat.js', ['1', `${foobarString}\n`], {parentFixture: 'nested-double.js', verbose: 'full'});26 27 let firstSubprocessPrinted = false;28 let secondSubprocessPrinted = false;29 for await (const chunk of on(subprocess.stderr, 'data')) {18 unmodified lines48 subprocess.kill();49 await t.throwsAsync(subprocess);50 });51 52-const testInterleaved = async (t, expectedLines, execaMethod) => {53- const {stderr} = await execaMethod('noop-132.js', {verbose: 'full'});52+const testInterleaved = async (t, expectedLines, isSync) => {53+ const {stderr} = await nestedSubprocess('noop-132.js', {verbose: 'full', isSync});54 t.deepEqual(getOutputLines(stderr), expectedLines.map(line => `${testTimestamp} [0] ${line}`));55 };56 57-test('Prints stdout + stderr interleaved', testInterleaved, [1, 2, 3], parentExecaAsync);58-test('Prints stdout + stderr not interleaved, sync', testInterleaved, [1, 3, 2], parentExecaSync);57+test('Prints stdout + stderr interleaved', testInterleaved, [1, 2, 3], false);58+test('Prints stdout + stderr not interleaved, sync', testInterleaved, [1, 3, 2], true);modified:test/verbose/start.js+95 added-88 removed
1 import test from 'ava';2 import {red} from 'yoctocolors';3-import {execa} from '../../index.js';3 import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4 import {foobarString} from '../helpers/input.js';6-import {parentExecaAsync, parentExecaSync, parentWorker} from '../helpers/nested.js';5+import {nestedSubprocess} from '../helpers/nested.js';6 import {7 QUOTE,9- runErrorSubprocessAsync,10- runErrorSubprocessSync,11- runEarlyErrorSubprocessAsync,12- runEarlyErrorSubprocessSync,8+ runErrorSubprocess,9+ runEarlyErrorSubprocess,10 getCommandLine,11 getCommandLines,12 testTimestamp,13 getVerboseOption,12 unmodified lines26 } from '../helpers/verbose.js';27 28 setFixtureDirectory();29 33-const testPrintCommand = async (t, verbose, execaMethod) => {34- const {stderr} = await execaMethod('noop.js', [foobarString], {verbose});30+const testPrintCommand = async (t, verbose, worker, isSync) => {31+ const {stderr} = await nestedSubprocess('noop.js', [foobarString], {verbose, worker, isSync});32 t.is(getCommandLine(stderr), `${testTimestamp} [0] $ noop.js ${foobarString}`);33 };34 38-test('Prints command, verbose "short"', testPrintCommand, 'short', parentExecaAsync);39-test('Prints command, verbose "full"', testPrintCommand, 'full', parentExecaAsync);40-test('Prints command, verbose "short", fd-specific stdout', testPrintCommand, stdoutShortOption, parentExecaAsync);41-test('Prints command, verbose "full", fd-specific stdout', testPrintCommand, stdoutFullOption, parentExecaAsync);42-test('Prints command, verbose "short", fd-specific stderr', testPrintCommand, stderrShortOption, parentExecaAsync);43-test('Prints command, verbose "full", fd-specific stderr', testPrintCommand, stderrFullOption, parentExecaAsync);44-test('Prints command, verbose "short", fd-specific fd3', testPrintCommand, fd3ShortOption, parentExecaAsync);45-test('Prints command, verbose "full", fd-specific fd3', testPrintCommand, fd3FullOption, parentExecaAsync);46-test('Prints command, verbose "short", fd-specific ipc', testPrintCommand, ipcShortOption, parentExecaAsync);47-test('Prints command, verbose "full", fd-specific ipc', testPrintCommand, ipcFullOption, parentExecaAsync);48-test('Prints command, verbose "short", sync', testPrintCommand, 'short', parentExecaSync);49-test('Prints command, verbose "full", sync', testPrintCommand, 'full', parentExecaSync);50-test('Prints command, verbose "short", fd-specific stdout, sync', testPrintCommand, stdoutShortOption, parentExecaSync);51-test('Prints command, verbose "full", fd-specific stdout, sync', testPrintCommand, stdoutFullOption, parentExecaSync);52-test('Prints command, verbose "short", fd-specific stderr, sync', testPrintCommand, stderrShortOption, parentExecaSync);53-test('Prints command, verbose "full", fd-specific stderr, sync', testPrintCommand, stderrFullOption, parentExecaSync);54-test('Prints command, verbose "short", fd-specific fd3, sync', testPrintCommand, fd3ShortOption, parentExecaSync);55-test('Prints command, verbose "full", fd-specific fd3, sync', testPrintCommand, fd3FullOption, parentExecaSync);56-test('Prints command, verbose "short", fd-specific ipc, sync', testPrintCommand, ipcShortOption, parentExecaSync);57-test('Prints command, verbose "full", fd-specific ipc, sync', testPrintCommand, ipcFullOption, parentExecaSync);58-test('Prints command, verbose "short", worker', testPrintCommand, 'short', parentWorker);59-test('Prints command, verbose "full", worker', testPrintCommand, 'full', parentWorker);60-test('Prints command, verbose "short", fd-specific stdout, worker', testPrintCommand, stdoutShortOption, parentWorker);61-test('Prints command, verbose "full", fd-specific stdout, worker', testPrintCommand, stdoutFullOption, parentWorker);62-test('Prints command, verbose "short", fd-specific stderr, worker', testPrintCommand, stderrShortOption, parentWorker);63-test('Prints command, verbose "full", fd-specific stderr, worker', testPrintCommand, stderrFullOption, parentWorker);64-test('Prints command, verbose "short", fd-specific fd3, worker', testPrintCommand, fd3ShortOption, parentWorker);65-test('Prints command, verbose "full", fd-specific fd3, worker', testPrintCommand, fd3FullOption, parentWorker);66-test('Prints command, verbose "short", fd-specific ipc, worker', testPrintCommand, ipcShortOption, parentWorker);67-test('Prints command, verbose "full", fd-specific ipc, worker', testPrintCommand, ipcFullOption, parentWorker);35+test('Prints command, verbose "short"', testPrintCommand, 'short', false, false);36+test('Prints command, verbose "full"', testPrintCommand, 'full', false, false);37+test('Prints command, verbose "short", fd-specific stdout', testPrintCommand, stdoutShortOption, false, false);38+test('Prints command, verbose "full", fd-specific stdout', testPrintCommand, stdoutFullOption, false, false);39+test('Prints command, verbose "short", fd-specific stderr', testPrintCommand, stderrShortOption, false, false);40+test('Prints command, verbose "full", fd-specific stderr', testPrintCommand, stderrFullOption, false, false);41+test('Prints command, verbose "short", fd-specific fd3', testPrintCommand, fd3ShortOption, false, false);42+test('Prints command, verbose "full", fd-specific fd3', testPrintCommand, fd3FullOption, false, false);43+test('Prints command, verbose "short", fd-specific ipc', testPrintCommand, ipcShortOption, false, false);44+test('Prints command, verbose "full", fd-specific ipc', testPrintCommand, ipcFullOption, false, false);45+test('Prints command, verbose "short", sync', testPrintCommand, 'short', false, true);46+test('Prints command, verbose "full", sync', testPrintCommand, 'full', false, true);47+test('Prints command, verbose "short", fd-specific stdout, sync', testPrintCommand, stdoutShortOption, false, true);48+test('Prints command, verbose "full", fd-specific stdout, sync', testPrintCommand, stdoutFullOption, false, true);49+test('Prints command, verbose "short", fd-specific stderr, sync', testPrintCommand, stderrShortOption, false, true);50+test('Prints command, verbose "full", fd-specific stderr, sync', testPrintCommand, stderrFullOption, false, true);51+test('Prints command, verbose "short", fd-specific fd3, sync', testPrintCommand, fd3ShortOption, false, true);52+test('Prints command, verbose "full", fd-specific fd3, sync', testPrintCommand, fd3FullOption, false, true);53+test('Prints command, verbose "short", fd-specific ipc, sync', testPrintCommand, ipcShortOption, false, true);54+test('Prints command, verbose "full", fd-specific ipc, sync', testPrintCommand, ipcFullOption, false, true);55+test('Prints command, verbose "short", worker', testPrintCommand, 'short', true, false);56+test('Prints command, verbose "full", worker', testPrintCommand, 'full', true, false);57+test('Prints command, verbose "short", fd-specific stdout, worker', testPrintCommand, stdoutShortOption, true, false);58+test('Prints command, verbose "full", fd-specific stdout, worker', testPrintCommand, stdoutFullOption, true, false);59+test('Prints command, verbose "short", fd-specific stderr, worker', testPrintCommand, stderrShortOption, true, false);60+test('Prints command, verbose "full", fd-specific stderr, worker', testPrintCommand, stderrFullOption, true, false);61+test('Prints command, verbose "short", fd-specific fd3, worker', testPrintCommand, fd3ShortOption, true, false);62+test('Prints command, verbose "full", fd-specific fd3, worker', testPrintCommand, fd3FullOption, true, false);63+test('Prints command, verbose "short", fd-specific ipc, worker', testPrintCommand, ipcShortOption, true, false);64+test('Prints command, verbose "full", fd-specific ipc, worker', testPrintCommand, ipcFullOption, true, false);65+test('Prints command, verbose "short", worker, sync', testPrintCommand, 'short', true, true);66+test('Prints command, verbose "full", worker, sync', testPrintCommand, 'full', true, true);67+test('Prints command, verbose "short", fd-specific stdout, worker, sync', testPrintCommand, stdoutShortOption, true, true);68+test('Prints command, verbose "full", fd-specific stdout, worker, sync', testPrintCommand, stdoutFullOption, true, true);69+test('Prints command, verbose "short", fd-specific stderr, worker, sync', testPrintCommand, stderrShortOption, true, true);70+test('Prints command, verbose "full", fd-specific stderr, worker, sync', testPrintCommand, stderrFullOption, true, true);71+test('Prints command, verbose "short", fd-specific fd3, worker, sync', testPrintCommand, fd3ShortOption, true, true);72+test('Prints command, verbose "full", fd-specific fd3, worker, sync', testPrintCommand, fd3FullOption, true, true);73+test('Prints command, verbose "short", fd-specific ipc, worker, sync', testPrintCommand, ipcShortOption, true, true);74+test('Prints command, verbose "full", fd-specific ipc, worker, sync', testPrintCommand, ipcFullOption, true, true);75 69-const testNoPrintCommand = async (t, verbose, execaMethod) => {70- const {stderr} = await execaMethod('noop.js', [foobarString], {verbose});76+const testNoPrintCommand = async (t, verbose, isSync) => {77+ const {stderr} = await nestedSubprocess('noop.js', [foobarString], {verbose, isSync});78 t.is(stderr, '');79 };80 74-test('Does not print command, verbose "none"', testNoPrintCommand, 'none', parentExecaAsync);75-test('Does not print command, verbose default', testNoPrintCommand, undefined, parentExecaAsync);76-test('Does not print command, verbose "none", fd-specific stdout', testNoPrintCommand, stdoutNoneOption, parentExecaAsync);77-test('Does not print command, verbose "none", fd-specific stderr', testNoPrintCommand, stderrNoneOption, parentExecaAsync);78-test('Does not print command, verbose "none", fd-specific fd3', testNoPrintCommand, fd3NoneOption, parentExecaAsync);79-test('Does not print command, verbose "none", fd-specific ipc', testNoPrintCommand, ipcNoneOption, parentExecaAsync);80-test('Does not print command, verbose default, fd-specific', testNoPrintCommand, {}, parentExecaAsync);81-test('Does not print command, verbose "none", sync', testNoPrintCommand, 'none', parentExecaSync);82-test('Does not print command, verbose default, sync', testNoPrintCommand, undefined, parentExecaSync);83-test('Does not print command, verbose "none", fd-specific stdout, sync', testNoPrintCommand, stdoutNoneOption, parentExecaSync);84-test('Does not print command, verbose "none", fd-specific stderr, sync', testNoPrintCommand, stderrNoneOption, parentExecaSync);85-test('Does not print command, verbose "none", fd-specific fd3, sync', testNoPrintCommand, fd3NoneOption, parentExecaSync);86-test('Does not print command, verbose "none", fd-specific ipc, sync', testNoPrintCommand, ipcNoneOption, parentExecaSync);87-test('Does not print command, verbose default, fd-specific, sync', testNoPrintCommand, {}, parentExecaSync);81+test('Does not print command, verbose "none"', testNoPrintCommand, 'none', false);82+test('Does not print command, verbose default', testNoPrintCommand, undefined, false);83+test('Does not print command, verbose "none", fd-specific stdout', testNoPrintCommand, stdoutNoneOption, false);84+test('Does not print command, verbose "none", fd-specific stderr', testNoPrintCommand, stderrNoneOption, false);85+test('Does not print command, verbose "none", fd-specific fd3', testNoPrintCommand, fd3NoneOption, false);86+test('Does not print command, verbose "none", fd-specific ipc', testNoPrintCommand, ipcNoneOption, false);87+test('Does not print command, verbose default, fd-specific', testNoPrintCommand, {}, false);88+test('Does not print command, verbose "none", sync', testNoPrintCommand, 'none', true);89+test('Does not print command, verbose default, sync', testNoPrintCommand, undefined, true);90+test('Does not print command, verbose "none", fd-specific stdout, sync', testNoPrintCommand, stdoutNoneOption, true);91+test('Does not print command, verbose "none", fd-specific stderr, sync', testNoPrintCommand, stderrNoneOption, true);92+test('Does not print command, verbose "none", fd-specific fd3, sync', testNoPrintCommand, fd3NoneOption, true);93+test('Does not print command, verbose "none", fd-specific ipc, sync', testNoPrintCommand, ipcNoneOption, true);94+test('Does not print command, verbose default, fd-specific, sync', testNoPrintCommand, {}, true);95 89-const testPrintCommandError = async (t, execaMethod) => {90- const stderr = await execaMethod(t, 'short');96+const testPrintCommandError = async (t, isSync) => {97+ const stderr = await runErrorSubprocess(t, 'short', isSync);98 t.is(getCommandLine(stderr), `${testTimestamp} [0] $ noop-fail.js 1 ${foobarString}`);99 };100 94-test('Prints command after errors', testPrintCommandError, runErrorSubprocessAsync);95-test('Prints command after errors, sync', testPrintCommandError, runErrorSubprocessSync);101+test('Prints command after errors', testPrintCommandError, false);102+test('Prints command after errors, sync', testPrintCommandError, true);103 97-const testPrintCommandEarly = async (t, execaMethod) => {98- const stderr = await execaMethod(t);104+const testPrintCommandEarly = async (t, isSync) => {105+ const stderr = await runEarlyErrorSubprocess(t, isSync);106 t.is(getCommandLine(stderr), `${testTimestamp} [0] $ noop.js ${foobarString}`);107 };108 102-test('Prints command before early validation errors', testPrintCommandEarly, runEarlyErrorSubprocessAsync);103-test('Prints command before early validation errors, sync', testPrintCommandEarly, runEarlyErrorSubprocessSync);109+test('Prints command before early validation errors', testPrintCommandEarly, false);110+test('Prints command before early validation errors, sync', testPrintCommandEarly, true);111 105-const testPipeCommand = async (t, fixtureName, sourceVerbose, destinationVerbose) => {106- const {stderr} = await execa(`nested-pipe-${fixtureName}.js`, [107- JSON.stringify(getVerboseOption(sourceVerbose)),108- 'noop.js',109- foobarString,110- JSON.stringify(getVerboseOption(destinationVerbose)),111- 'stdin.js',112- ]);113- const pipeSymbol = fixtureName === 'subprocesses' ? '$' : '|';112+const testPipeCommand = async (t, parentFixture, sourceVerbose, destinationVerbose) => {113+ const {stderr} = await nestedSubprocess('noop.js', [foobarString], {114+ parentFixture,115+ sourceOptions: getVerboseOption(sourceVerbose),116+ destinationFile: 'stdin.js',117+ destinationOptions: getVerboseOption(destinationVerbose),118+ });119+120+ const pipeSymbol = parentFixture === 'nested-pipe-subprocesses.js' ? '$' : '|';121 const lines = getCommandLines(stderr);122 t.is(lines.includes(`${testTimestamp} [0] $ noop.js ${foobarString}`), sourceVerbose);123 t.is(lines.includes(`${testTimestamp} [${sourceVerbose ? 1 : 0}] ${pipeSymbol} stdin.js`), destinationVerbose);124 };125 119-test('Prints both commands piped with .pipe("file")', testPipeCommand, 'file', true, true);120-test('Prints both commands piped with .pipe`command`', testPipeCommand, 'script', true, true);121-test('Prints both commands piped with .pipe(subprocess)', testPipeCommand, 'subprocesses', true, true);122-test('Prints first command piped with .pipe("file")', testPipeCommand, 'file', true, false);123-test('Prints first command piped with .pipe`command`', testPipeCommand, 'script', true, false);124-test('Prints first command piped with .pipe(subprocess)', testPipeCommand, 'subprocesses', true, false);125-test('Prints second command piped with .pipe("file")', testPipeCommand, 'file', false, true);126-test('Prints second command piped with .pipe`command`', testPipeCommand, 'script', false, true);127-test('Prints second command piped with .pipe(subprocess)', testPipeCommand, 'subprocesses', false, true);128-test('Prints neither commands piped with .pipe("file")', testPipeCommand, 'file', false, false);129-test('Prints neither commands piped with .pipe`command`', testPipeCommand, 'script', false, false);130-test('Prints neither commands piped with .pipe(subprocess)', testPipeCommand, 'subprocesses', false, false);126+test('Prints both commands piped with .pipe("file")', testPipeCommand, 'nested-pipe-file.js', true, true);127+test('Prints both commands piped with .pipe`command`', testPipeCommand, 'nested-pipe-script.js', true, true);128+test('Prints both commands piped with .pipe(subprocess)', testPipeCommand, 'nested-pipe-subprocesses.js', true, true);129+test('Prints first command piped with .pipe("file")', testPipeCommand, 'nested-pipe-file.js', true, false);130+test('Prints first command piped with .pipe`command`', testPipeCommand, 'nested-pipe-script.js', true, false);131+test('Prints first command piped with .pipe(subprocess)', testPipeCommand, 'nested-pipe-subprocesses.js', true, false);132+test('Prints second command piped with .pipe("file")', testPipeCommand, 'nested-pipe-file.js', false, true);133+test('Prints second command piped with .pipe`command`', testPipeCommand, 'nested-pipe-script.js', false, true);134+test('Prints second command piped with .pipe(subprocess)', testPipeCommand, 'nested-pipe-subprocesses.js', false, true);135+test('Prints neither commands piped with .pipe("file")', testPipeCommand, 'nested-pipe-file.js', false, false);136+test('Prints neither commands piped with .pipe`command`', testPipeCommand, 'nested-pipe-script.js', false, false);137+test('Prints neither commands piped with .pipe(subprocess)', testPipeCommand, 'nested-pipe-subprocesses.js', false, false);138 139 test('Quotes spaces from command', async t => {133- const {stderr} = await parentExecaAsync('noop.js', ['foo bar'], {verbose: 'short'});140+ const {stderr} = await nestedSubprocess('noop.js', ['foo bar'], {verbose: 'short'});141 t.is(getCommandLine(stderr), `${testTimestamp} [0] $ noop.js ${QUOTE}foo bar${QUOTE}`);142 });143 144 test('Quotes special punctuation from command', async t => {138- const {stderr} = await parentExecaAsync('noop.js', ['%'], {verbose: 'short'});145+ const {stderr} = await nestedSubprocess('noop.js', ['%'], {verbose: 'short'});146 t.is(getCommandLine(stderr), `${testTimestamp} [0] $ noop.js ${QUOTE}%${QUOTE}`);147 });148 149 test('Does not escape internal characters from command', async t => {143- const {stderr} = await parentExecaAsync('noop.js', ['ã'], {verbose: 'short'});150+ const {stderr} = await nestedSubprocess('noop.js', ['ã'], {verbose: 'short'});151 t.is(getCommandLine(stderr), `${testTimestamp} [0] $ noop.js ${QUOTE}ã${QUOTE}`);152 });153 154 test('Escapes color sequences from command', async t => {148- const {stderr} = await parentExecaAsync('noop.js', [red(foobarString)], {verbose: 'short'}, {env: {FORCE_COLOR: '1'}});155+ const {stderr} = await nestedSubprocess('noop.js', [red(foobarString)], {verbose: 'short'}, {env: {FORCE_COLOR: '1'}});156 t.true(getCommandLine(stderr).includes(`${QUOTE}\\u001b[31m${foobarString}\\u001b[39m${QUOTE}`));157 });158 159 test('Escapes control characters from command', async t => {153- const {stderr} = await parentExecaAsync('noop.js', ['\u0001'], {verbose: 'short'});160+ const {stderr} = await nestedSubprocess('noop.js', ['\u0001'], {verbose: 'short'});161 t.is(getCommandLine(stderr), `${testTimestamp} [0] $ noop.js ${QUOTE}\\u0001${QUOTE}`);162 });