Skip to content
Myr

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

41 files+712 added−709 removed

added:test/fixtures/nested/file-url.js+3 added
added:test/fixtures/nested/generator-big-array.js+4 added
added:test/fixtures/nested/generator-duplex.js+3 added
added:test/fixtures/nested/generator-object.js+3 added
added:test/fixtures/nested/generator-string-object.js+4 added
added:test/fixtures/nested/generator-uppercase.js+3 added
added:test/fixtures/nested/writable-web.js+1 added
added:test/fixtures/nested/writable.js+3 added
modified:test/fixtures/nested-double.js+4 added-5 removed
1#!/usr/bin/env node2import process from 'node:process';3import {execa} from '../../index.js';2import {execa, getOneMessage} from '../../index.js';35const [options, file, ...commandArguments] = process.argv.slice(2);4const {file, commandArguments, options} = await getOneMessage();5const firstArguments = commandArguments.slice(0, -1);6const lastArgument = commandArguments.at(-1);7await 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 node2import process from 'node:process';3import {execa} from '../../index.js';2import {execa, getOneMessage} from '../../index.js';35const [options, file, ...commandArguments] = process.argv.slice(2);6const subprocess = execa(file, commandArguments, JSON.parse(options));4const {file, commandArguments, options} = await getOneMessage();5const subprocess = execa(file, commandArguments, options);6subprocess.kill(new Error(commandArguments[0]));7await subprocess;
deleted:test/fixtures/nested-file-url.js-8 removed
1#!/usr/bin/env node2import process from 'node:process';3import {pathToFileURL} from 'node:url';4import {execa} from '../../index.js';56const [options, file, commandArgument] = process.argv.slice(2);7const parsedOptions = JSON.parse(options);8await execa(file, [commandArgument], {...parsedOptions, stdout: pathToFileURL(parsedOptions.stdout)});
deleted:test/fixtures/nested-input.js-12 removed
1#!/usr/bin/env node2import process from 'node:process';3import {execa, execaSync} from '../../index.js';4import {foobarUtf16Uint8Array} from '../helpers/input.js';56const [optionsString, file, isSync, ...commandArguments] = process.argv.slice(2);7const options = {...JSON.parse(optionsString), input: foobarUtf16Uint8Array};8if (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 node2import process from 'node:process';3import {execa} from '../../index.js';2import {execa, getOneMessage} from '../../index.js';35const [6 sourceOptions,7 sourceFile,8 sourceArgument,9 destinationOptions,10 destinationFile,11 destinationArgument,12] = process.argv.slice(2);13await execa(sourceFile, [sourceArgument], JSON.parse(sourceOptions))14 .pipe(destinationFile, destinationArgument === undefined ? [] : [destinationArgument], JSON.parse(destinationOptions));4const {5 file,6 commandArguments = [],7 options: {8 sourceOptions = {},9 destinationFile,10 destinationArguments = [],11 destinationOptions = {},12 },13} = await getOneMessage();14await execa(file, commandArguments, sourceOptions)15 .pipe(destinationFile, destinationArguments, destinationOptions);
modified:test/fixtures/nested-pipe-script.js+13 added-12 removed
1#!/usr/bin/env node2import process from 'node:process';3import {$} from '../../index.js';2import {$, getOneMessage} from '../../index.js';35const [6 sourceOptions,7 sourceFile,8 sourceArgument,9 destinationOptions,10 destinationFile,11 destinationArgument,12] = process.argv.slice(2);13await $(JSON.parse(sourceOptions))`${sourceFile} ${sourceArgument}`14 .pipe(JSON.parse(destinationOptions))`${destinationFile} ${destinationArgument === undefined ? [] : [destinationArgument]}`;4const {5 file,6 commandArguments = [],7 options: {8 sourceOptions = {},9 destinationFile,10 destinationArguments = [],11 destinationOptions = {},12 },13} = await getOneMessage();14await $(sourceOptions)`${file} ${commandArguments}`15 .pipe(destinationOptions)`${destinationFile} ${destinationArguments}`;
modified:test/fixtures/nested-pipe-stream.js+4 added-4 removed
1#!/usr/bin/env node2import process from 'node:process';3import {execa} from '../../index.js';3import {execa, getOneMessage} from '../../index.js';45const [options, file, commandArgument, unpipe] = process.argv.slice(2);6const subprocess = execa(file, [commandArgument], JSON.parse(options));5const {file, commandArguments, options: {unpipe, ...options}} = await getOneMessage();6const subprocess = execa(file, commandArguments, options);7subprocess.stdout.pipe(process.stdout);8if (unpipe === 'true') {8if (unpipe) {9 subprocess.stdout.unpipe(process.stdout);10}1112await subprocess;
modified:test/fixtures/nested-pipe-subprocess.js+8 added-7 removed
1#!/usr/bin/env node2import process from 'node:process';3import {execa} from '../../index.js';2import {execa, getOneMessage} from '../../index.js';35const [options, file, commandArgument, unpipe] = process.argv.slice(2);6const source = execa(file, [commandArgument], JSON.parse(options));4const {file, commandArguments, options: {unpipe, ...options}} = await getOneMessage();5const source = execa(file, commandArguments, options);6const destination = execa('stdin.js');7const controller = new AbortController();9const pipePromise = source.pipe(destination, {unpipeSignal: controller.signal});10if (unpipe === 'true') {8const subprocess = source.pipe(destination, {unpipeSignal: controller.signal});9if (unpipe) {10 controller.abort();11 destination.stdin.end();12}1315await Promise.allSettled([source, destination, pipePromise]);14try {15 await subprocess;16} catch {}
modified:test/fixtures/nested-pipe-subprocesses.js+13 added-12 removed
1#!/usr/bin/env node2import process from 'node:process';3import {execa} from '../../index.js';2import {execa, getOneMessage} from '../../index.js';35const [6 sourceOptions,7 sourceFile,8 sourceArgument,9 destinationOptions,10 destinationFile,11 destinationArgument,12] = process.argv.slice(2);13await execa(sourceFile, [sourceArgument], JSON.parse(sourceOptions))14 .pipe(execa(destinationFile, destinationArgument === undefined ? [] : [destinationArgument], JSON.parse(destinationOptions)));4const {5 file,6 commandArguments = [],7 options: {8 sourceOptions = {},9 destinationFile,10 destinationArguments = [],11 destinationOptions = {},12 },13} = await getOneMessage();14await execa(file, commandArguments, sourceOptions)15 .pipe(execa(destinationFile, destinationArguments, destinationOptions));
deleted:test/fixtures/nested-sync.js-11 removed
1#!/usr/bin/env node2import process from 'node:process';3import {execaSync, sendMessage} from '../../index.js';45const [options, file, ...commandArguments] = process.argv.slice(2);6try {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 node2import process from 'node:process';3import {execa, execaSync} from '../../index.js';4import {generatorsMap} from '../helpers/map.js';5import {outputObjectGenerator, getOutputGenerator} from '../helpers/generator.js';6import {simpleFull} from '../helpers/lines.js';78const getTransform = (type, transformName) => {9 if (type !== undefined) {10 return generatorsMap[type].uppercase();11 }1213 if (transformName === 'object') {14 return outputObjectGenerator();15 }1617 if (transformName === 'stringObject') {18 return getOutputGenerator(simpleFull)(true);19 }2021 if (transformName === 'bigArray') {22 const bigArray = Array.from({length: 100}, (_, index) => index);23 return getOutputGenerator(bigArray)(true);24 }25};2627const [optionsString, file, ...commandArguments] = process.argv.slice(2);28const {type, transformName, isSync, ...options} = JSON.parse(optionsString);29const newOptions = {stdout: getTransform(type, transformName), ...options};30if (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 node2import process from 'node:process';3import {execa} from '../../index.js';45const [options, file, commandArgument] = process.argv.slice(2);6await execa(file, [commandArgument], {...JSON.parse(options), stdout: new WritableStream()});
deleted:test/fixtures/nested-writable.js-6 removed
1#!/usr/bin/env node2import process from 'node:process';3import {execa} from '../../index.js';45const [options, file, commandArgument] = process.argv.slice(2);6await execa(file, [commandArgument], {...JSON.parse(options), stdout: process.stdout});
modified:test/fixtures/nested.js+29 added-6 removed
1#!/usr/bin/env node2import process from 'node:process';3import {execa, sendMessage} from '../../index.js';2import {3 execa,4 execaSync,5 getOneMessage,6 sendMessage,7} from '../../index.js';85const [options, file, ...commandArguments] = process.argv.slice(2);9const {10 isSync,11 file,12 commandArguments,13 options,14 optionsFixture,15 optionsInput,16} = await getOneMessage();1718let commandOptions = options;1920// Some subprocess options cannot be serialized between processes.21// For those, we pass a fixture filename instead, which dynamically creates the options.22if (optionsFixture !== undefined) {23 const {getOptions} = await import(`./nested/${optionsFixture}`);24 commandOptions = {...commandOptions, ...getOptions({...commandOptions, ...optionsInput})};25}2627try {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 node2import {workerData, parentPort} from 'node:worker_threads';2import {execa} from '../../index.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';3import {spawnParentProcess} from '../helpers/nested.js';45setFixtureDirectory();67const {nodeFile, commandArguments, options} = workerData;5try {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 lines
4import {FIXTURES_DIRECTORY_URL} from './fixtures-directory.js';56const WORKER_URL = new URL('worker.js', FIXTURES_DIRECTORY_URL);78const 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.14export 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};1915// eslint-disable-next-line max-params16const nestedCall = (isWorker, fixtureName, execaMethod, file, commandArguments, options, parentOptions) => {20export 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};4627const getNestedResult = async onMessage => {28 const {result} = await getMessage(onMessage);29 return result;30};3132const getParentResult = async onMessage => {33 const {parentResult} = await getMessage(onMessage);34 return parentResult;35};3637const getMessage = async onMessage => {38 const [{error, parentError = error, result, parentResult}] = await onMessage;39 if (parentError) {40 throw parentError;47const 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 }5343 return {result, parentResult};54 return result;55};5646export const nestedWorker = (...commandArguments) => nestedCall(true, 'nested.js', runWorker, ...commandArguments);47const nestedExeca = (fixtureName, ...commandArguments) => nestedCall(false, fixtureName, execa, ...commandArguments);48export const nestedExecaAsync = (...commandArguments) => nestedExeca('nested.js', ...commandArguments);49export const nestedExecaSync = (...commandArguments) => nestedExeca('nested-sync.js', ...commandArguments);50export const parentWorker = (...commandArguments) => nestedWorker(...commandArguments).parent;51export const parentExeca = (...commandArguments) => nestedExeca(...commandArguments).parent;52export const parentExecaAsync = (...commandArguments) => nestedExecaAsync(...commandArguments).parent;53export const parentExecaSync = (...commandArguments) => nestedExecaSync(...commandArguments).parent;57export const spawnParentProcess = ({parentFixture, parentOptions, ...ipcInput}) => execa(parentFixture, {...parentOptions, ipcInput});
modified:test/helpers/verbose.js+10 added-20 removed
1import {platform} from 'node:process';2import {stripVTControlCharacters} from 'node:util';3import {replaceSymbols} from 'figures';4import {foobarString} from './input.js';5import {nestedExecaAsync, nestedExecaSync} from './nested.js';5import {nestedSubprocess} from './nested.js';67const isWindows = platform === 'win32';8export const QUOTE = isWindows ? '"' : '\'';910const 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;10export 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 }1617 return stderr;18};1921export const runErrorSubprocessAsync = runErrorSubprocess.bind(undefined, nestedExecaAsync);22export const runErrorSubprocessSync = runErrorSubprocess.bind(undefined, nestedExecaSync);2324const runWarningSubprocess = async (execaMethod, t) => {25 const {stderr} = await execaMethod('noop-fail.js', ['1', foobarString], {verbose: 'short', reject: false}).parent;20export 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};2630export const runWarningSubprocessAsync = runWarningSubprocess.bind(undefined, nestedExecaAsync);31export const runWarningSubprocessSync = runWarningSubprocess.bind(undefined, nestedExecaSync);3233const 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;27export 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};3341export const runEarlyErrorSubprocessAsync = runEarlyErrorSubprocess.bind(undefined, nestedExecaAsync);42export const runEarlyErrorSubprocessSync = runEarlyErrorSubprocess.bind(undefined, nestedExecaSync);4334export const getCommandLine = stderr => getCommandLines(stderr)[0];35export const getCommandLines = stderr => getNormalizedLines(stderr).filter(line => isCommandLine(line));36const isCommandLine = line => line.includes(' $ ') || line.includes(' | ');37export const getOutputLine = stderr => getOutputLines(stderr)[0];
33 unmodified lines
modified:test/stdio/duplicate.js+5 added-5 removed
15 unmodified lines
16import {appendDuplex} from '../helpers/duplex.js';17import {appendWebTransform} from '../helpers/web-transform.js';18import {foobarString, foobarUint8Array, foobarUppercase} from '../helpers/input.js';19import {fullStdio} from '../helpers/stdio.js';20import {nestedExecaAsync, nestedExecaSync} from '../helpers/nested.js';20import {nestedSubprocess} from '../helpers/nested.js';21import {getAbsolutePath} from '../helpers/file-path.js';22import {noopDuplex} from '../helpers/stream.js';2324setFixtureDirectory();
119 unmodified lines
144test('Can re-use same native Writable stream on different output file descriptors', testMultipleStreamOutput, getNativeStream);145test('Can re-use same non-native Writable stream on different output file descriptors', testMultipleStreamOutput, getNonNativeStream);146test('Can re-use same web Writable stream on different output file descriptors', testMultipleStreamOutput, getWebWritableStream);147148const testMultipleInheritOutput = async (t, execaMethod) => {149 const {stdout} = await execaMethod('noop-both.js', [foobarString], getDifferentOutputs(1)).parent;148const testMultipleInheritOutput = async (t, isSync) => {149 const {stdout} = await nestedSubprocess('noop-both.js', [foobarString], {...getDifferentOutputs(1), isSync});150 t.is(stdout, `${foobarString}\n${foobarString}`);151};152153test('Can re-use same parent file descriptor on different output file descriptors', testMultipleInheritOutput, nestedExecaAsync);154test('Can re-use same parent file descriptor on different output file descriptors, sync', testMultipleInheritOutput, nestedExecaSync);153test('Can re-use same parent file descriptor on different output file descriptors', testMultipleInheritOutput, false);154test('Can re-use same parent file descriptor on different output file descriptors, sync', testMultipleInheritOutput, true);155156const testMultipleFileInput = async (t, mapFile) => {157 const filePath = tempfile();158 await writeFile(filePath, foobarString);
55 unmodified lines
modified:test/stdio/native-fd.js+25 added-25 removed
2 unmodified lines
3import {execa, execaSync} from '../../index.js';4import {getStdio, fullStdio} from '../helpers/stdio.js';5import {setFixtureDirectory} from '../helpers/fixtures-directory.js';6import {foobarString} from '../helpers/input.js';7import {parentExecaAsync, parentExecaSync} from '../helpers/nested.js';7import {nestedSubprocess} from '../helpers/nested.js';89setFixtureDirectory();1011const isLinux = platform === 'linux';12const isWindows = platform === 'win32';1314const testFd3InheritOutput = async (t, stdioOption, execaMethod) => {15 const {stdio} = await execaMethod('noop-fd.js', ['3', foobarString], getStdio(3, stdioOption), fullStdio);14const 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};1819test('stdio[*] output can use "inherit"', testFd3InheritOutput, 'inherit', parentExecaAsync);20test('stdio[*] output can use ["inherit"]', testFd3InheritOutput, ['inherit'], parentExecaAsync);21test('stdio[*] output can use "inherit", sync', testFd3InheritOutput, 'inherit', parentExecaSync);22test('stdio[*] output can use ["inherit"], sync', testFd3InheritOutput, ['inherit'], parentExecaSync);19test('stdio[*] output can use "inherit"', testFd3InheritOutput, 'inherit', false);20test('stdio[*] output can use ["inherit"]', testFd3InheritOutput, ['inherit'], false);21test('stdio[*] output can use "inherit", sync', testFd3InheritOutput, 'inherit', true);22test('stdio[*] output can use ["inherit"], sync', testFd3InheritOutput, ['inherit'], true);2324if (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 };2930 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}4748const testOverflowStreamArray = (t, fdNumber, stdioOption) => {49 t.throws(() => {
27 unmodified lines
modified:test/stdio/native-inherit-pipe.js+7 added-7 removed
3 unmodified lines
4import {execa} from '../../index.js';5import {getStdio, fullStdio} from '../helpers/stdio.js';6import {setFixtureDirectory} from '../helpers/fixtures-directory.js';7import {foobarString} from '../helpers/input.js';8import {parentExecaAsync, parentExecaSync} from '../helpers/nested.js';8import {nestedSubprocess} from '../helpers/nested.js';910setFixtureDirectory();1112const testInheritStdin = async (t, stdioOption, isSync) => {
43 unmodified lines
56test('stderr can be [process.stderr, "pipe"], encoding "buffer", sync', testInheritStdioOutput, 2, 1, ['stderr', 'pipe'], true, 'buffer');57test('stdio[*] output can be ["inherit", "pipe"], encoding "buffer", sync', testInheritStdioOutput, 3, 1, ['inherit', 'pipe'], true, 'buffer');58test('stdio[*] output can be [3, "pipe"], encoding "buffer", sync', testInheritStdioOutput, 3, 1, [3, 'pipe'], true, 'buffer');5960const testInheritNoBuffer = async (t, stdioOption, execaMethod) => {60const 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};6667test('stdin can be ["inherit", "pipe"], buffer: false', testInheritNoBuffer, ['inherit', 'pipe'], parentExecaAsync);68test('stdin can be [0, "pipe"], buffer: false', testInheritNoBuffer, [0, 'pipe'], parentExecaAsync);69test.serial('stdin can be ["inherit", "pipe"], buffer: false, sync', testInheritNoBuffer, ['inherit', 'pipe'], parentExecaSync);70test.serial('stdin can be [0, "pipe"], buffer: false, sync', testInheritNoBuffer, [0, 'pipe'], parentExecaSync);67test('stdin can be ["inherit", "pipe"], buffer: false', testInheritNoBuffer, ['inherit', 'pipe'], false);68test('stdin can be [0, "pipe"], buffer: false', testInheritNoBuffer, [0, 'pipe'], false);69test.serial('stdin can be ["inherit", "pipe"], buffer: false, sync', testInheritNoBuffer, ['inherit', 'pipe'], true);70test.serial('stdin can be [0, "pipe"], buffer: false, sync', testInheritNoBuffer, [0, 'pipe'], true);7172test('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 lines
modified:test/terminate/cleanup.js+11 added-11 removed
2 unmodified lines
3import test from 'ava';4import isRunning from 'is-running';5import {execa, execaSync} from '../../index.js';6import {setFixtureDirectory} from '../helpers/fixtures-directory.js';7import {nestedExecaAsync, nestedWorker} from '../helpers/nested.js';7import {nestedSubprocess} from '../helpers/nested.js';8import {foobarString} from '../helpers/input.js';910setFixtureDirectory();1112const isWindows = process.platform === 'win32';1314// When subprocess exits before current process15const spawnAndExit = async (t, execaMethod, cleanup, detached) => {16 const {stdout} = await execaMethod('noop-fd.js', ['1', foobarString], {cleanup, detached});15const 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};1920test('spawnAndExit', spawnAndExit, nestedExecaAsync, false, false);21test('spawnAndExit cleanup', spawnAndExit, nestedExecaAsync, true, false);22test('spawnAndExit detached', spawnAndExit, nestedExecaAsync, false, true);23test('spawnAndExit cleanup detached', spawnAndExit, nestedExecaAsync, true, true);24test('spawnAndExit, worker', spawnAndExit, nestedWorker, false, false);25test('spawnAndExit cleanup, worker', spawnAndExit, nestedWorker, true, false);26test('spawnAndExit detached, worker', spawnAndExit, nestedWorker, false, true);27test('spawnAndExit cleanup detached, worker', spawnAndExit, nestedWorker, true, true);20test('spawnAndExit', spawnAndExit, false, false, false);21test('spawnAndExit cleanup', spawnAndExit, false, true, false);22test('spawnAndExit detached', spawnAndExit, false, false, true);23test('spawnAndExit cleanup detached', spawnAndExit, false, true, true);24test('spawnAndExit, worker', spawnAndExit, true, false, false);25test('spawnAndExit cleanup, worker', spawnAndExit, true, true, false);26test('spawnAndExit detached, worker', spawnAndExit, true, false, true);27test('spawnAndExit cleanup detached, worker', spawnAndExit, true, true, true);2829// When current process exits before subprocess30const spawnAndKill = async (t, [signal, cleanup, detached, isKilled]) => {31 const subprocess = execa('ipc-send-pid.js', [cleanup, detached], {stdio: 'ignore', ipc: true});
70 unmodified lines
modified:test/verbose/complete.js+74 added-79 removed
1import {stripVTControlCharacters} from 'node:util';2import test from 'ava';3import {execa} from '../../index.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {foobarString} from '../helpers/input.js';6import {parentExecaAsync, parentExecaSync} from '../helpers/nested.js';5import {nestedSubprocess} from '../helpers/nested.js';6import {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 lines
26} from '../helpers/verbose.js';2728setFixtureDirectory();2934const testPrintCompletion = async (t, verbose, execaMethod) => {35 const {stderr} = await execaMethod('noop.js', [foobarString], {verbose});30const 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};3439test('Prints completion, verbose "short"', testPrintCompletion, 'short', parentExecaAsync);40test('Prints completion, verbose "full"', testPrintCompletion, 'full', parentExecaAsync);41test('Prints completion, verbose "short", fd-specific stdout', testPrintCompletion, stdoutShortOption, parentExecaAsync);42test('Prints completion, verbose "full", fd-specific stdout', testPrintCompletion, stdoutFullOption, parentExecaAsync);43test('Prints completion, verbose "short", fd-specific stderr', testPrintCompletion, stderrShortOption, parentExecaAsync);44test('Prints completion, verbose "full", fd-specific stderr', testPrintCompletion, stderrFullOption, parentExecaAsync);45test('Prints completion, verbose "short", fd-specific fd3', testPrintCompletion, fd3ShortOption, parentExecaAsync);46test('Prints completion, verbose "full", fd-specific fd3', testPrintCompletion, fd3FullOption, parentExecaAsync);47test('Prints completion, verbose "short", fd-specific ipc', testPrintCompletion, ipcShortOption, parentExecaAsync);48test('Prints completion, verbose "full", fd-specific ipc', testPrintCompletion, ipcFullOption, parentExecaAsync);49test('Prints completion, verbose "short", sync', testPrintCompletion, 'short', parentExecaSync);50test('Prints completion, verbose "full", sync', testPrintCompletion, 'full', parentExecaSync);51test('Prints completion, verbose "short", fd-specific stdout, sync', testPrintCompletion, stdoutShortOption, parentExecaSync);52test('Prints completion, verbose "full", fd-specific stdout, sync', testPrintCompletion, stdoutFullOption, parentExecaSync);53test('Prints completion, verbose "short", fd-specific stderr, sync', testPrintCompletion, stderrShortOption, parentExecaSync);54test('Prints completion, verbose "full", fd-specific stderr, sync', testPrintCompletion, stderrFullOption, parentExecaSync);55test('Prints completion, verbose "short", fd-specific fd3, sync', testPrintCompletion, fd3ShortOption, parentExecaSync);56test('Prints completion, verbose "full", fd-specific fd3, sync', testPrintCompletion, fd3FullOption, parentExecaSync);57test('Prints completion, verbose "short", fd-specific ipc, sync', testPrintCompletion, ipcShortOption, parentExecaSync);58test('Prints completion, verbose "full", fd-specific ipc, sync', testPrintCompletion, ipcFullOption, parentExecaSync);35test('Prints completion, verbose "short"', testPrintCompletion, 'short', false);36test('Prints completion, verbose "full"', testPrintCompletion, 'full', false);37test('Prints completion, verbose "short", fd-specific stdout', testPrintCompletion, stdoutShortOption, false);38test('Prints completion, verbose "full", fd-specific stdout', testPrintCompletion, stdoutFullOption, false);39test('Prints completion, verbose "short", fd-specific stderr', testPrintCompletion, stderrShortOption, false);40test('Prints completion, verbose "full", fd-specific stderr', testPrintCompletion, stderrFullOption, false);41test('Prints completion, verbose "short", fd-specific fd3', testPrintCompletion, fd3ShortOption, false);42test('Prints completion, verbose "full", fd-specific fd3', testPrintCompletion, fd3FullOption, false);43test('Prints completion, verbose "short", fd-specific ipc', testPrintCompletion, ipcShortOption, false);44test('Prints completion, verbose "full", fd-specific ipc', testPrintCompletion, ipcFullOption, false);45test('Prints completion, verbose "short", sync', testPrintCompletion, 'short', true);46test('Prints completion, verbose "full", sync', testPrintCompletion, 'full', true);47test('Prints completion, verbose "short", fd-specific stdout, sync', testPrintCompletion, stdoutShortOption, true);48test('Prints completion, verbose "full", fd-specific stdout, sync', testPrintCompletion, stdoutFullOption, true);49test('Prints completion, verbose "short", fd-specific stderr, sync', testPrintCompletion, stderrShortOption, true);50test('Prints completion, verbose "full", fd-specific stderr, sync', testPrintCompletion, stderrFullOption, true);51test('Prints completion, verbose "short", fd-specific fd3, sync', testPrintCompletion, fd3ShortOption, true);52test('Prints completion, verbose "full", fd-specific fd3, sync', testPrintCompletion, fd3FullOption, true);53test('Prints completion, verbose "short", fd-specific ipc, sync', testPrintCompletion, ipcShortOption, true);54test('Prints completion, verbose "full", fd-specific ipc, sync', testPrintCompletion, ipcFullOption, true);5560const testNoPrintCompletion = async (t, verbose, execaMethod) => {61 const {stderr} = await execaMethod('noop.js', [foobarString], {verbose});56const testNoPrintCompletion = async (t, verbose, isSync) => {57 const {stderr} = await nestedSubprocess('noop.js', [foobarString], {verbose, isSync});58 t.is(stderr, '');59};6065test('Does not print completion, verbose "none"', testNoPrintCompletion, 'none', parentExecaAsync);66test('Does not print completion, verbose default"', testNoPrintCompletion, undefined, parentExecaAsync);67test('Does not print completion, verbose "none", fd-specific stdout', testNoPrintCompletion, stdoutNoneOption, parentExecaAsync);68test('Does not print completion, verbose "none", fd-specific stderr', testNoPrintCompletion, stderrNoneOption, parentExecaAsync);69test('Does not print completion, verbose "none", fd-specific fd3', testNoPrintCompletion, fd3NoneOption, parentExecaAsync);70test('Does not print completion, verbose "none", fd-specific ipc', testNoPrintCompletion, ipcNoneOption, parentExecaAsync);71test('Does not print completion, verbose default", fd-specific', testNoPrintCompletion, {}, parentExecaAsync);72test('Does not print completion, verbose "none", sync', testNoPrintCompletion, 'none', parentExecaSync);73test('Does not print completion, verbose default", sync', testNoPrintCompletion, undefined, parentExecaSync);74test('Does not print completion, verbose "none", fd-specific stdout, sync', testNoPrintCompletion, stdoutNoneOption, parentExecaSync);75test('Does not print completion, verbose "none", fd-specific stderr, sync', testNoPrintCompletion, stderrNoneOption, parentExecaSync);76test('Does not print completion, verbose "none", fd-specific fd3, sync', testNoPrintCompletion, fd3NoneOption, parentExecaSync);77test('Does not print completion, verbose "none", fd-specific ipc, sync', testNoPrintCompletion, ipcNoneOption, parentExecaSync);78test('Does not print completion, verbose default", fd-specific, sync', testNoPrintCompletion, {}, parentExecaSync);61test('Does not print completion, verbose "none"', testNoPrintCompletion, 'none', false);62test('Does not print completion, verbose default"', testNoPrintCompletion, undefined, false);63test('Does not print completion, verbose "none", fd-specific stdout', testNoPrintCompletion, stdoutNoneOption, false);64test('Does not print completion, verbose "none", fd-specific stderr', testNoPrintCompletion, stderrNoneOption, false);65test('Does not print completion, verbose "none", fd-specific fd3', testNoPrintCompletion, fd3NoneOption, false);66test('Does not print completion, verbose "none", fd-specific ipc', testNoPrintCompletion, ipcNoneOption, false);67test('Does not print completion, verbose default", fd-specific', testNoPrintCompletion, {}, false);68test('Does not print completion, verbose "none", sync', testNoPrintCompletion, 'none', true);69test('Does not print completion, verbose default", sync', testNoPrintCompletion, undefined, true);70test('Does not print completion, verbose "none", fd-specific stdout, sync', testNoPrintCompletion, stdoutNoneOption, true);71test('Does not print completion, verbose "none", fd-specific stderr, sync', testNoPrintCompletion, stderrNoneOption, true);72test('Does not print completion, verbose "none", fd-specific fd3, sync', testNoPrintCompletion, fd3NoneOption, true);73test('Does not print completion, verbose "none", fd-specific ipc, sync', testNoPrintCompletion, ipcNoneOption, true);74test('Does not print completion, verbose default", fd-specific, sync', testNoPrintCompletion, {}, true);7580const testPrintCompletionError = async (t, execaMethod) => {81 const stderr = await execaMethod(t, 'short');76const testPrintCompletionError = async (t, isSync) => {77 const stderr = await runErrorSubprocess(t, 'short', isSync);78 t.is(getCompletionLine(stderr), `${testTimestamp} [0] × (done in 0ms)`);79};8085test('Prints completion after errors', testPrintCompletionError, runErrorSubprocessAsync);86test('Prints completion after errors, sync', testPrintCompletionError, runErrorSubprocessSync);81test('Prints completion after errors', testPrintCompletionError, false);82test('Prints completion after errors, sync', testPrintCompletionError, true);8388const testPrintCompletionWarning = async (t, execaMethod) => {89 const stderr = await execaMethod(t);84const testPrintCompletionWarning = async (t, isSync) => {85 const stderr = await runWarningSubprocess(t, isSync);86 t.is(getCompletionLine(stderr), `${testTimestamp} [0] ‼ (done in 0ms)`);87};8893test('Prints completion after errors, "reject" false', testPrintCompletionWarning, runWarningSubprocessAsync);94test('Prints completion after errors, "reject" false, sync', testPrintCompletionWarning, runWarningSubprocessSync);89test('Prints completion after errors, "reject" false', testPrintCompletionWarning, false);90test('Prints completion after errors, "reject" false, sync', testPrintCompletionWarning, true);9196const testPrintCompletionEarly = async (t, execaMethod) => {97 const stderr = await execaMethod(t);92const testPrintCompletionEarly = async (t, isSync) => {93 const stderr = await runEarlyErrorSubprocess(t, isSync);94 t.is(getCompletionLine(stderr), `${testTimestamp} [0] × (done in 0ms)`);95};96101test('Prints completion after early validation errors', testPrintCompletionEarly, runEarlyErrorSubprocessAsync);102test('Prints completion after early validation errors, sync', testPrintCompletionEarly, runEarlyErrorSubprocessSync);97test('Prints completion after early validation errors', testPrintCompletionEarly, false);98test('Prints completion after early validation errors, sync', testPrintCompletionEarly, true);99100test.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});104109const 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 ]);105const 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 });112113 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};117123test('Prints both durations piped with .pipe("file")', testPipeDuration, 'file', true, true);124test('Prints both durations piped with .pipe`command`', testPipeDuration, 'script', true, true);125test('Prints both durations piped with .pipe(subprocess)', testPipeDuration, 'subprocesses', true, true);126test('Prints first duration piped with .pipe("file")', testPipeDuration, 'file', true, false);127test('Prints first duration piped with .pipe`command`', testPipeDuration, 'script', true, false);128test('Prints first duration piped with .pipe(subprocess)', testPipeDuration, 'subprocesses', true, false);129test('Prints second duration piped with .pipe("file")', testPipeDuration, 'file', false, true);130test('Prints second duration piped with .pipe`command`', testPipeDuration, 'script', false, true);131test('Prints second duration piped with .pipe(subprocess)', testPipeDuration, 'subprocesses', false, true);132test('Prints neither durations piped with .pipe("file")', testPipeDuration, 'file', false, false);133test('Prints neither durations piped with .pipe`command`', testPipeDuration, 'script', false, false);134test('Prints neither durations piped with .pipe(subprocess)', testPipeDuration, 'subprocesses', false, false);118test('Prints both durations piped with .pipe("file")', testPipeDuration, 'nested-pipe-file.js', true, true);119test('Prints both durations piped with .pipe`command`', testPipeDuration, 'nested-pipe-script.js', true, true);120test('Prints both durations piped with .pipe(subprocess)', testPipeDuration, 'nested-pipe-subprocesses.js', true, true);121test('Prints first duration piped with .pipe("file")', testPipeDuration, 'nested-pipe-file.js', true, false);122test('Prints first duration piped with .pipe`command`', testPipeDuration, 'nested-pipe-script.js', true, false);123test('Prints first duration piped with .pipe(subprocess)', testPipeDuration, 'nested-pipe-subprocesses.js', true, false);124test('Prints second duration piped with .pipe("file")', testPipeDuration, 'nested-pipe-file.js', false, true);125test('Prints second duration piped with .pipe`command`', testPipeDuration, 'nested-pipe-script.js', false, true);126test('Prints second duration piped with .pipe(subprocess)', testPipeDuration, 'nested-pipe-subprocesses.js', false, true);127test('Prints neither durations piped with .pipe("file")', testPipeDuration, 'nested-pipe-file.js', false, false);128test('Prints neither durations piped with .pipe`command`', testPipeDuration, 'nested-pipe-script.js', false, false);129test('Prints neither durations piped with .pipe(subprocess)', testPipeDuration, 'nested-pipe-subprocesses.js', false, false);
modified:test/verbose/error.js+75 added-81 removed
1import test from 'ava';2import {red} from 'yoctocolors';3import {execa} from '../../index.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {foobarString} from '../helpers/input.js';6import {parentExeca, parentExecaAsync, parentExecaSync} from '../helpers/nested.js';5import {nestedSubprocess} from '../helpers/nested.js';6import {7 QUOTE,9 runErrorSubprocessAsync,10 runErrorSubprocessSync,11 runEarlyErrorSubprocessAsync,12 runEarlyErrorSubprocessSync,8 runErrorSubprocess,9 runEarlyErrorSubprocess,10 getErrorLine,11 getErrorLines,12 testTimestamp,13 getVerboseOption,
12 unmodified lines
26} from '../helpers/verbose.js';2728setFixtureDirectory();2933const parentExecaFail = parentExeca.bind(undefined, 'nested-fail.js');3435const testPrintError = async (t, verbose, execaMethod) => {36 const stderr = await execaMethod(t, verbose);30const 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};3440test('Prints error, verbose "short"', testPrintError, 'short', runErrorSubprocessAsync);41test('Prints error, verbose "full"', testPrintError, 'full', runErrorSubprocessAsync);42test('Prints error, verbose "short", fd-specific stdout', testPrintError, stdoutShortOption, runErrorSubprocessAsync);43test('Prints error, verbose "full", fd-specific stdout', testPrintError, stdoutFullOption, runErrorSubprocessAsync);44test('Prints error, verbose "short", fd-specific stderr', testPrintError, stderrShortOption, runErrorSubprocessAsync);45test('Prints error, verbose "full", fd-specific stderr', testPrintError, stderrFullOption, runErrorSubprocessAsync);46test('Prints error, verbose "short", fd-specific fd3', testPrintError, fd3ShortOption, runErrorSubprocessAsync);47test('Prints error, verbose "full", fd-specific fd3', testPrintError, fd3FullOption, runErrorSubprocessAsync);48test('Prints error, verbose "short", fd-specific ipc', testPrintError, ipcShortOption, runErrorSubprocessAsync);49test('Prints error, verbose "full", fd-specific ipc', testPrintError, ipcFullOption, runErrorSubprocessAsync);50test('Prints error, verbose "short", sync', testPrintError, 'short', runErrorSubprocessSync);51test('Prints error, verbose "full", sync', testPrintError, 'full', runErrorSubprocessSync);52test('Prints error, verbose "short", fd-specific stdout, sync', testPrintError, stdoutShortOption, runErrorSubprocessSync);53test('Prints error, verbose "full", fd-specific stdout, sync', testPrintError, stdoutFullOption, runErrorSubprocessSync);54test('Prints error, verbose "short", fd-specific stderr, sync', testPrintError, stderrShortOption, runErrorSubprocessSync);55test('Prints error, verbose "full", fd-specific stderr, sync', testPrintError, stderrFullOption, runErrorSubprocessSync);56test('Prints error, verbose "short", fd-specific fd3, sync', testPrintError, fd3ShortOption, runErrorSubprocessSync);57test('Prints error, verbose "full", fd-specific fd3, sync', testPrintError, fd3FullOption, runErrorSubprocessSync);58test('Prints error, verbose "short", fd-specific ipc, sync', testPrintError, ipcShortOption, runErrorSubprocessSync);59test('Prints error, verbose "full", fd-specific ipc, sync', testPrintError, ipcFullOption, runErrorSubprocessSync);35test('Prints error, verbose "short"', testPrintError, 'short', false);36test('Prints error, verbose "full"', testPrintError, 'full', false);37test('Prints error, verbose "short", fd-specific stdout', testPrintError, stdoutShortOption, false);38test('Prints error, verbose "full", fd-specific stdout', testPrintError, stdoutFullOption, false);39test('Prints error, verbose "short", fd-specific stderr', testPrintError, stderrShortOption, false);40test('Prints error, verbose "full", fd-specific stderr', testPrintError, stderrFullOption, false);41test('Prints error, verbose "short", fd-specific fd3', testPrintError, fd3ShortOption, false);42test('Prints error, verbose "full", fd-specific fd3', testPrintError, fd3FullOption, false);43test('Prints error, verbose "short", fd-specific ipc', testPrintError, ipcShortOption, false);44test('Prints error, verbose "full", fd-specific ipc', testPrintError, ipcFullOption, false);45test('Prints error, verbose "short", sync', testPrintError, 'short', true);46test('Prints error, verbose "full", sync', testPrintError, 'full', true);47test('Prints error, verbose "short", fd-specific stdout, sync', testPrintError, stdoutShortOption, true);48test('Prints error, verbose "full", fd-specific stdout, sync', testPrintError, stdoutFullOption, true);49test('Prints error, verbose "short", fd-specific stderr, sync', testPrintError, stderrShortOption, true);50test('Prints error, verbose "full", fd-specific stderr, sync', testPrintError, stderrFullOption, true);51test('Prints error, verbose "short", fd-specific fd3, sync', testPrintError, fd3ShortOption, true);52test('Prints error, verbose "full", fd-specific fd3, sync', testPrintError, fd3FullOption, true);53test('Prints error, verbose "short", fd-specific ipc, sync', testPrintError, ipcShortOption, true);54test('Prints error, verbose "full", fd-specific ipc, sync', testPrintError, ipcFullOption, true);5561const testNoPrintError = async (t, verbose, execaMethod) => {62 const stderr = await execaMethod(t, verbose, false);56const testNoPrintError = async (t, verbose, isSync) => {57 const stderr = await runErrorSubprocess(t, verbose, isSync, false);58 t.is(getErrorLine(stderr), undefined);59};6066test('Does not print error, verbose "none"', testNoPrintError, 'none', runErrorSubprocessAsync);67test('Does not print error, verbose default', testNoPrintError, undefined, runErrorSubprocessAsync);68test('Does not print error, verbose "none", fd-specific stdout', testNoPrintError, stdoutNoneOption, runErrorSubprocessAsync);69test('Does not print error, verbose "none", fd-specific stderr', testNoPrintError, stderrNoneOption, runErrorSubprocessAsync);70test('Does not print error, verbose "none", fd-specific fd3', testNoPrintError, fd3NoneOption, runErrorSubprocessAsync);71test('Does not print error, verbose "none", fd-specific ipc', testNoPrintError, ipcNoneOption, runErrorSubprocessAsync);72test('Does not print error, verbose default, fd-specific', testNoPrintError, {}, runErrorSubprocessAsync);73test('Does not print error, verbose "none", sync', testNoPrintError, 'none', runErrorSubprocessSync);74test('Does not print error, verbose default, sync', testNoPrintError, undefined, runErrorSubprocessSync);75test('Does not print error, verbose "none", fd-specific stdout, sync', testNoPrintError, stdoutNoneOption, runErrorSubprocessSync);76test('Does not print error, verbose "none", fd-specific stderr, sync', testNoPrintError, stderrNoneOption, runErrorSubprocessSync);77test('Does not print error, verbose "none", fd-specific fd3, sync', testNoPrintError, fd3NoneOption, runErrorSubprocessSync);78test('Does not print error, verbose "none", fd-specific ipc, sync', testNoPrintError, ipcNoneOption, runErrorSubprocessSync);79test('Does not print error, verbose default, fd-specific, sync', testNoPrintError, {}, runErrorSubprocessSync);61test('Does not print error, verbose "none"', testNoPrintError, 'none', false);62test('Does not print error, verbose default', testNoPrintError, undefined, false);63test('Does not print error, verbose "none", fd-specific stdout', testNoPrintError, stdoutNoneOption, false);64test('Does not print error, verbose "none", fd-specific stderr', testNoPrintError, stderrNoneOption, false);65test('Does not print error, verbose "none", fd-specific fd3', testNoPrintError, fd3NoneOption, false);66test('Does not print error, verbose "none", fd-specific ipc', testNoPrintError, ipcNoneOption, false);67test('Does not print error, verbose default, fd-specific', testNoPrintError, {}, false);68test('Does not print error, verbose "none", sync', testNoPrintError, 'none', true);69test('Does not print error, verbose default, sync', testNoPrintError, undefined, true);70test('Does not print error, verbose "none", fd-specific stdout, sync', testNoPrintError, stdoutNoneOption, true);71test('Does not print error, verbose "none", fd-specific stderr, sync', testNoPrintError, stderrNoneOption, true);72test('Does not print error, verbose "none", fd-specific fd3, sync', testNoPrintError, fd3NoneOption, true);73test('Does not print error, verbose "none", fd-specific ipc, sync', testNoPrintError, ipcNoneOption, true);74test('Does not print error, verbose default, fd-specific, sync', testNoPrintError, {}, true);7581const testPrintNoError = async (t, execaMethod) => {82 const {stderr} = await execaMethod('noop.js', [foobarString], {verbose: 'short'});76const testPrintNoError = async (t, isSync) => {77 const {stderr} = await nestedSubprocess('noop.js', [foobarString], {verbose: 'short', isSync});78 t.is(getErrorLine(stderr), undefined);79};8086test('Does not print error if none', testPrintNoError, parentExecaAsync);87test('Does not print error if none, sync', testPrintNoError, parentExecaSync);81test('Does not print error if none', testPrintNoError, false);82test('Does not print error if none, sync', testPrintNoError, true);8389const testPrintErrorEarly = async (t, execaMethod) => {90 const stderr = await execaMethod(t);84const 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};8894test('Prints early validation error', testPrintErrorEarly, runEarlyErrorSubprocessAsync);95test('Prints early validation error, sync', testPrintErrorEarly, runEarlyErrorSubprocessSync);89test('Prints early validation error', testPrintErrorEarly, false);90test('Prints early validation error, sync', testPrintErrorEarly, true);9192test('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});9697test('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});101107const 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 ]));102const 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 }));109110 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};114121test('Prints both errors piped with .pipe("file")', testPipeError, 'file', true, true);122test('Prints both errors piped with .pipe`command`', testPipeError, 'script', true, true);123test('Prints both errors piped with .pipe(subprocess)', testPipeError, 'subprocesses', true, true);124test('Prints first error piped with .pipe("file")', testPipeError, 'file', true, false);125test('Prints first error piped with .pipe`command`', testPipeError, 'script', true, false);126test('Prints first error piped with .pipe(subprocess)', testPipeError, 'subprocesses', true, false);127test('Prints second error piped with .pipe("file")', testPipeError, 'file', false, true);128test('Prints second error piped with .pipe`command`', testPipeError, 'script', false, true);129test('Prints second error piped with .pipe(subprocess)', testPipeError, 'subprocesses', false, true);130test('Prints neither errors piped with .pipe("file")', testPipeError, 'file', false, false);131test('Prints neither errors piped with .pipe`command`', testPipeError, 'script', false, false);132test('Prints neither errors piped with .pipe(subprocess)', testPipeError, 'subprocesses', false, false);115test('Prints both errors piped with .pipe("file")', testPipeError, 'nested-pipe-file.js', true, true);116test('Prints both errors piped with .pipe`command`', testPipeError, 'nested-pipe-script.js', true, true);117test('Prints both errors piped with .pipe(subprocess)', testPipeError, 'nested-pipe-subprocesses.js', true, true);118test('Prints first error piped with .pipe("file")', testPipeError, 'nested-pipe-file.js', true, false);119test('Prints first error piped with .pipe`command`', testPipeError, 'nested-pipe-script.js', true, false);120test('Prints first error piped with .pipe(subprocess)', testPipeError, 'nested-pipe-subprocesses.js', true, false);121test('Prints second error piped with .pipe("file")', testPipeError, 'nested-pipe-file.js', false, true);122test('Prints second error piped with .pipe`command`', testPipeError, 'nested-pipe-script.js', false, true);123test('Prints second error piped with .pipe(subprocess)', testPipeError, 'nested-pipe-subprocesses.js', false, true);124test('Prints neither errors piped with .pipe("file")', testPipeError, 'nested-pipe-file.js', false, false);125test('Prints neither errors piped with .pipe`command`', testPipeError, 'nested-pipe-script.js', false, false);126test('Prints neither errors piped with .pipe(subprocess)', testPipeError, 'nested-pipe-subprocesses.js', false, false);127128test('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});135136test('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});143144test('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});151152test('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});159160test('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 line
modified:test/verbose/info.js+6 added-6 removed
1import test from 'ava';2import {setFixtureDirectory} from '../helpers/fixtures-directory.js';3import {execa, execaSync} from '../../index.js';4import {foobarString} from '../helpers/input.js';5import {parentExecaAsync, parentExecaSync} from '../helpers/nested.js';5import {nestedSubprocess} from '../helpers/nested.js';6import {7 QUOTE,8 getCommandLine,9 getOutputLine,
18 unmodified lines
28test('Prints command, NODE_DEBUG=execa + "inherit"', testVerboseGeneral, execa);29test('Prints command, NODE_DEBUG=execa + "inherit", sync', testVerboseGeneral, execaSync);3031test('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});3637const testDebugEnvPriority = async (t, execaMethod) => {38 const {stderr} = await execaMethod('noop.js', [foobarString], {verbose: 'short'}, {env: {NODE_DEBUG: 'execa'}});37const 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};4243test('NODE_DEBUG=execa has lower priority', testDebugEnvPriority, parentExecaAsync);44test('NODE_DEBUG=execa has lower priority, sync', testDebugEnvPriority, parentExecaSync);43test('NODE_DEBUG=execa has lower priority', testDebugEnvPriority, false);44test('NODE_DEBUG=execa has lower priority, sync', testDebugEnvPriority, true);4546const invalidFalseMessage = 'renamed to "verbose: \'none\'"';47const invalidTrueMessage = 'renamed to "verbose: \'short\'"';48const invalidUnknownMessage = 'Allowed values are: \'none\', \'short\', \'full\'';
14 unmodified lines
modified:test/verbose/ipc.js+15 added-15 removed
2 unmodified lines
3import test from 'ava';4import {red} from 'yoctocolors';5import {setFixtureDirectory} from '../helpers/fixtures-directory.js';6import {foobarString, foobarObject} from '../helpers/input.js';7import {nestedExecaAsync, parentExecaAsync} from '../helpers/nested.js';7import {nestedSubprocess, nestedInstance} from '../helpers/nested.js';8import {9 getIpcLine,10 getIpcLines,11 testTimestamp,
4 unmodified lines
1617setFixtureDirectory();1819const 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};2324test('Prints IPC, verbose "full"', testPrintIpc, 'full');25test('Prints IPC, verbose "full", fd-specific', testPrintIpc, ipcFullOption);2627const 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};3132test('Does not print IPC, verbose default', testNoPrintIpc, undefined);
3 unmodified lines
36test('Does not print IPC, verbose "none", fd-specific', testNoPrintIpc, ipcNoneOption);37test('Does not print IPC, verbose "short", fd-specific', testNoPrintIpc, ipcShortOption);3839const 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};4546test('Does not print IPC, ipc: false', testNoIpc, false);47test('Does not print IPC, ipc: default', testNoIpc, undefined);4849test('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});5354test('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});6263test('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});6768test('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});7576test('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});8081test('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});8586test('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});9091test('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});9596test('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 lines
modified:test/verbose/log.js+10 added-10 removed
1import {stripVTControlCharacters} from 'node:util';2import test from 'ava';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {foobarString} from '../helpers/input.js';5import {parentExecaAsync, parentExecaSync} from '../helpers/nested.js';5import {nestedSubprocess} from '../helpers/nested.js';67setFixtureDirectory();89const testNoStdout = async (t, verbose, execaMethod) => {10 const {stdout} = await execaMethod('noop.js', [foobarString], {verbose, stdio: 'inherit'});9const testNoStdout = async (t, verbose, isSync) => {10 const {stdout} = await nestedSubprocess('noop.js', [foobarString], {verbose, stdio: 'inherit', isSync});11 t.is(stdout, foobarString);12};1314test('Logs on stderr not stdout, verbose "none"', testNoStdout, 'none', parentExecaAsync);15test('Logs on stderr not stdout, verbose "short"', testNoStdout, 'short', parentExecaAsync);16test('Logs on stderr not stdout, verbose "full"', testNoStdout, 'full', parentExecaAsync);17test('Logs on stderr not stdout, verbose "none", sync', testNoStdout, 'none', parentExecaSync);18test('Logs on stderr not stdout, verbose "short", sync', testNoStdout, 'short', parentExecaSync);19test('Logs on stderr not stdout, verbose "full", sync', testNoStdout, 'full', parentExecaSync);14test('Logs on stderr not stdout, verbose "none"', testNoStdout, 'none', false);15test('Logs on stderr not stdout, verbose "short"', testNoStdout, 'short', false);16test('Logs on stderr not stdout, verbose "full"', testNoStdout, 'full', false);17test('Logs on stderr not stdout, verbose "none", sync', testNoStdout, 'none', true);18test('Logs on stderr not stdout, verbose "short", sync', testNoStdout, 'short', true);19test('Logs on stderr not stdout, verbose "full", sync', testNoStdout, 'full', true);2021const 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};2526test('Prints with colors if supported', testColor, true, '1');
1 unmodified line
modified:test/verbose/output-buffer.js+19 added-19 removed
1import test from 'ava';2import {setFixtureDirectory} from '../helpers/fixtures-directory.js';3import {foobarString, foobarUppercase} from '../helpers/input.js';4import {parentExeca, parentExecaAsync, parentExecaSync} from '../helpers/nested.js';4import {nestedSubprocess} from '../helpers/nested.js';5import {6 getOutputLine,7 testTimestamp,8 stdoutNoneOption,
2 unmodified lines
11} from '../helpers/verbose.js';1213setFixtureDirectory();1415const testPrintOutputNoBuffer = async (t, verbose, buffer, execaMethod) => {16 const {stderr} = await execaMethod('noop.js', [foobarString], {verbose, buffer});15const 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};1920test('Prints stdout, buffer: false', testPrintOutputNoBuffer, 'full', false, parentExecaAsync);21test('Prints stdout, buffer: false, fd-specific buffer', testPrintOutputNoBuffer, 'full', {stdout: false}, parentExecaAsync);22test('Prints stdout, buffer: false, fd-specific verbose', testPrintOutputNoBuffer, stdoutFullOption, false, parentExecaAsync);23test('Prints stdout, buffer: false, sync', testPrintOutputNoBuffer, 'full', false, parentExecaSync);24test('Prints stdout, buffer: false, fd-specific buffer, sync', testPrintOutputNoBuffer, 'full', {stdout: false}, parentExecaSync);25test('Prints stdout, buffer: false, fd-specific verbose, sync', testPrintOutputNoBuffer, stdoutFullOption, false, parentExecaSync);20test('Prints stdout, buffer: false', testPrintOutputNoBuffer, 'full', false, false);21test('Prints stdout, buffer: false, fd-specific buffer', testPrintOutputNoBuffer, 'full', {stdout: false}, false);22test('Prints stdout, buffer: false, fd-specific verbose', testPrintOutputNoBuffer, stdoutFullOption, false, false);23test('Prints stdout, buffer: false, sync', testPrintOutputNoBuffer, 'full', false, true);24test('Prints stdout, buffer: false, fd-specific buffer, sync', testPrintOutputNoBuffer, 'full', {stdout: false}, true);25test('Prints stdout, buffer: false, fd-specific verbose, sync', testPrintOutputNoBuffer, stdoutFullOption, false, true);2627const testPrintOutputNoBufferFalse = async (t, verbose, buffer, execaMethod) => {28 const {stderr} = await execaMethod('noop.js', [foobarString], {verbose, buffer});27const testPrintOutputNoBufferFalse = async (t, verbose, buffer, isSync) => {28 const {stderr} = await nestedSubprocess('noop.js', [foobarString], {verbose, buffer, isSync});29 t.is(getOutputLine(stderr), undefined);30};3132test('Does not print stdout, buffer: false, fd-specific none', testPrintOutputNoBufferFalse, stdoutNoneOption, false, parentExecaAsync);33test('Does not print stdout, buffer: false, different fd', testPrintOutputNoBufferFalse, stderrFullOption, false, parentExecaAsync);34test('Does not print stdout, buffer: false, different fd, fd-specific buffer', testPrintOutputNoBufferFalse, stderrFullOption, {stdout: false}, parentExecaAsync);35test('Does not print stdout, buffer: false, fd-specific none, sync', testPrintOutputNoBufferFalse, stdoutNoneOption, false, parentExecaSync);36test('Does not print stdout, buffer: false, different fd, sync', testPrintOutputNoBufferFalse, stderrFullOption, false, parentExecaSync);37test('Does not print stdout, buffer: false, different fd, fd-specific buffer, sync', testPrintOutputNoBufferFalse, stderrFullOption, {stdout: false}, parentExecaSync);32test('Does not print stdout, buffer: false, fd-specific none', testPrintOutputNoBufferFalse, stdoutNoneOption, false, false);33test('Does not print stdout, buffer: false, different fd', testPrintOutputNoBufferFalse, stderrFullOption, false, false);34test('Does not print stdout, buffer: false, different fd, fd-specific buffer', testPrintOutputNoBufferFalse, stderrFullOption, {stdout: false}, false);35test('Does not print stdout, buffer: false, fd-specific none, sync', testPrintOutputNoBufferFalse, stdoutNoneOption, false, true);36test('Does not print stdout, buffer: false, different fd, sync', testPrintOutputNoBufferFalse, stderrFullOption, false, true);37test('Does not print stdout, buffer: false, different fd, fd-specific buffer, sync', testPrintOutputNoBufferFalse, stderrFullOption, {stdout: false}, true);3839const 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 lines
modified:test/verbose/output-enable.js+75 added-76 removed
1import test from 'ava';2import {red} from 'yoctocolors';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {foobarString} from '../helpers/input.js';4import {foobarString, foobarUtf16Uint8Array} from '../helpers/input.js';5import {fullStdio} from '../helpers/stdio.js';6import {nestedSubprocess} from '../helpers/nested.js';7import {7 nestedExecaAsync,8 parentExeca,9 parentExecaAsync,10 parentExecaSync,11} from '../helpers/nested.js';12import {13 runErrorSubprocessAsync,14 runErrorSubprocessSync,8 runErrorSubprocess,9 getOutputLine,10 getOutputLines,11 testTimestamp,12 stdoutNoneOption,
8 unmodified lines
21} from '../helpers/verbose.js';2223setFixtureDirectory();2431const testPrintOutput = async (t, verbose, fdNumber, execaMethod) => {32 const {stderr} = await execaMethod('noop-fd.js', [`${fdNumber}`, foobarString], {verbose});25const 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};2936test('Prints stdout, verbose "full"', testPrintOutput, 'full', 1, parentExecaAsync);37test('Prints stderr, verbose "full"', testPrintOutput, 'full', 2, parentExecaAsync);38test('Prints stdout, verbose "full", fd-specific', testPrintOutput, stdoutFullOption, 1, parentExecaAsync);39test('Prints stderr, verbose "full", fd-specific', testPrintOutput, stderrFullOption, 2, parentExecaAsync);40test('Prints stdout, verbose "full", sync', testPrintOutput, 'full', 1, parentExecaSync);41test('Prints stderr, verbose "full", sync', testPrintOutput, 'full', 2, parentExecaSync);42test('Prints stdout, verbose "full", fd-specific, sync', testPrintOutput, stdoutFullOption, 1, parentExecaSync);43test('Prints stderr, verbose "full", fd-specific, sync', testPrintOutput, stderrFullOption, 2, parentExecaSync);30test('Prints stdout, verbose "full"', testPrintOutput, 'full', 1, false);31test('Prints stderr, verbose "full"', testPrintOutput, 'full', 2, false);32test('Prints stdout, verbose "full", fd-specific', testPrintOutput, stdoutFullOption, 1, false);33test('Prints stderr, verbose "full", fd-specific', testPrintOutput, stderrFullOption, 2, false);34test('Prints stdout, verbose "full", sync', testPrintOutput, 'full', 1, true);35test('Prints stderr, verbose "full", sync', testPrintOutput, 'full', 2, true);36test('Prints stdout, verbose "full", fd-specific, sync', testPrintOutput, stdoutFullOption, 1, true);37test('Prints stderr, verbose "full", fd-specific, sync', testPrintOutput, stderrFullOption, 2, true);3845const testNoPrintOutput = async (t, verbose, fdNumber, execaMethod) => {46 const {stderr} = await execaMethod('noop-fd.js', [`${fdNumber}`, foobarString], {verbose, ...fullStdio});39const 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};4350test('Does not print stdout, verbose default', testNoPrintOutput, undefined, 1, parentExecaAsync);51test('Does not print stdout, verbose "none"', testNoPrintOutput, 'none', 1, parentExecaAsync);52test('Does not print stdout, verbose "short"', testNoPrintOutput, 'short', 1, parentExecaAsync);53test('Does not print stderr, verbose default', testNoPrintOutput, undefined, 2, parentExecaAsync);54test('Does not print stderr, verbose "none"', testNoPrintOutput, 'none', 2, parentExecaAsync);55test('Does not print stderr, verbose "short"', testNoPrintOutput, 'short', 2, parentExecaAsync);56test('Does not print stdio[*], verbose default', testNoPrintOutput, undefined, 3, parentExecaAsync);57test('Does not print stdio[*], verbose "none"', testNoPrintOutput, 'none', 3, parentExecaAsync);58test('Does not print stdio[*], verbose "short"', testNoPrintOutput, 'short', 3, parentExecaAsync);59test('Does not print stdio[*], verbose "full"', testNoPrintOutput, 'full', 3, parentExecaAsync);60test('Does not print stdout, verbose default, fd-specific', testNoPrintOutput, {}, 1, parentExecaAsync);61test('Does not print stdout, verbose "none", fd-specific', testNoPrintOutput, stdoutNoneOption, 1, parentExecaAsync);62test('Does not print stdout, verbose "short", fd-specific', testNoPrintOutput, stdoutShortOption, 1, parentExecaAsync);63test('Does not print stderr, verbose default, fd-specific', testNoPrintOutput, {}, 2, parentExecaAsync);64test('Does not print stderr, verbose "none", fd-specific', testNoPrintOutput, stderrNoneOption, 2, parentExecaAsync);65test('Does not print stderr, verbose "short", fd-specific', testNoPrintOutput, stderrShortOption, 2, parentExecaAsync);66test('Does not print stdio[*], verbose default, fd-specific', testNoPrintOutput, {}, 3, parentExecaAsync);67test('Does not print stdio[*], verbose "none", fd-specific', testNoPrintOutput, fd3NoneOption, 3, parentExecaAsync);68test('Does not print stdio[*], verbose "short", fd-specific', testNoPrintOutput, fd3ShortOption, 3, parentExecaAsync);69test('Does not print stdio[*], verbose "full", fd-specific', testNoPrintOutput, fd3FullOption, 3, parentExecaAsync);70test('Does not print stdout, verbose default, sync', testNoPrintOutput, undefined, 1, parentExecaSync);71test('Does not print stdout, verbose "none", sync', testNoPrintOutput, 'none', 1, parentExecaSync);72test('Does not print stdout, verbose "short", sync', testNoPrintOutput, 'short', 1, parentExecaSync);73test('Does not print stderr, verbose default, sync', testNoPrintOutput, undefined, 2, parentExecaSync);74test('Does not print stderr, verbose "none", sync', testNoPrintOutput, 'none', 2, parentExecaSync);75test('Does not print stderr, verbose "short", sync', testNoPrintOutput, 'short', 2, parentExecaSync);76test('Does not print stdio[*], verbose default, sync', testNoPrintOutput, undefined, 3, parentExecaSync);77test('Does not print stdio[*], verbose "none", sync', testNoPrintOutput, 'none', 3, parentExecaSync);78test('Does not print stdio[*], verbose "short", sync', testNoPrintOutput, 'short', 3, parentExecaSync);79test('Does not print stdio[*], verbose "full", sync', testNoPrintOutput, 'full', 3, parentExecaSync);80test('Does not print stdout, verbose default, fd-specific, sync', testNoPrintOutput, {}, 1, parentExecaSync);81test('Does not print stdout, verbose "none", fd-specific, sync', testNoPrintOutput, stdoutNoneOption, 1, parentExecaSync);82test('Does not print stdout, verbose "short", fd-specific, sync', testNoPrintOutput, stdoutShortOption, 1, parentExecaSync);83test('Does not print stderr, verbose default, fd-specific, sync', testNoPrintOutput, {}, 2, parentExecaSync);84test('Does not print stderr, verbose "none", fd-specific, sync', testNoPrintOutput, stderrNoneOption, 2, parentExecaSync);85test('Does not print stderr, verbose "short", fd-specific, sync', testNoPrintOutput, stderrShortOption, 2, parentExecaSync);86test('Does not print stdio[*], verbose default, fd-specific, sync', testNoPrintOutput, {}, 3, parentExecaSync);87test('Does not print stdio[*], verbose "none", fd-specific, sync', testNoPrintOutput, fd3NoneOption, 3, parentExecaSync);88test('Does not print stdio[*], verbose "short", fd-specific, sync', testNoPrintOutput, fd3ShortOption, 3, parentExecaSync);89test('Does not print stdio[*], verbose "full", fd-specific, sync', testNoPrintOutput, fd3FullOption, 3, parentExecaSync);44test('Does not print stdout, verbose default', testNoPrintOutput, undefined, 1, false);45test('Does not print stdout, verbose "none"', testNoPrintOutput, 'none', 1, false);46test('Does not print stdout, verbose "short"', testNoPrintOutput, 'short', 1, false);47test('Does not print stderr, verbose default', testNoPrintOutput, undefined, 2, false);48test('Does not print stderr, verbose "none"', testNoPrintOutput, 'none', 2, false);49test('Does not print stderr, verbose "short"', testNoPrintOutput, 'short', 2, false);50test('Does not print stdio[*], verbose default', testNoPrintOutput, undefined, 3, false);51test('Does not print stdio[*], verbose "none"', testNoPrintOutput, 'none', 3, false);52test('Does not print stdio[*], verbose "short"', testNoPrintOutput, 'short', 3, false);53test('Does not print stdio[*], verbose "full"', testNoPrintOutput, 'full', 3, false);54test('Does not print stdout, verbose default, fd-specific', testNoPrintOutput, {}, 1, false);55test('Does not print stdout, verbose "none", fd-specific', testNoPrintOutput, stdoutNoneOption, 1, false);56test('Does not print stdout, verbose "short", fd-specific', testNoPrintOutput, stdoutShortOption, 1, false);57test('Does not print stderr, verbose default, fd-specific', testNoPrintOutput, {}, 2, false);58test('Does not print stderr, verbose "none", fd-specific', testNoPrintOutput, stderrNoneOption, 2, false);59test('Does not print stderr, verbose "short", fd-specific', testNoPrintOutput, stderrShortOption, 2, false);60test('Does not print stdio[*], verbose default, fd-specific', testNoPrintOutput, {}, 3, false);61test('Does not print stdio[*], verbose "none", fd-specific', testNoPrintOutput, fd3NoneOption, 3, false);62test('Does not print stdio[*], verbose "short", fd-specific', testNoPrintOutput, fd3ShortOption, 3, false);63test('Does not print stdio[*], verbose "full", fd-specific', testNoPrintOutput, fd3FullOption, 3, false);64test('Does not print stdout, verbose default, sync', testNoPrintOutput, undefined, 1, true);65test('Does not print stdout, verbose "none", sync', testNoPrintOutput, 'none', 1, true);66test('Does not print stdout, verbose "short", sync', testNoPrintOutput, 'short', 1, true);67test('Does not print stderr, verbose default, sync', testNoPrintOutput, undefined, 2, true);68test('Does not print stderr, verbose "none", sync', testNoPrintOutput, 'none', 2, true);69test('Does not print stderr, verbose "short", sync', testNoPrintOutput, 'short', 2, true);70test('Does not print stdio[*], verbose default, sync', testNoPrintOutput, undefined, 3, true);71test('Does not print stdio[*], verbose "none", sync', testNoPrintOutput, 'none', 3, true);72test('Does not print stdio[*], verbose "short", sync', testNoPrintOutput, 'short', 3, true);73test('Does not print stdio[*], verbose "full", sync', testNoPrintOutput, 'full', 3, true);74test('Does not print stdout, verbose default, fd-specific, sync', testNoPrintOutput, {}, 1, true);75test('Does not print stdout, verbose "none", fd-specific, sync', testNoPrintOutput, stdoutNoneOption, 1, true);76test('Does not print stdout, verbose "short", fd-specific, sync', testNoPrintOutput, stdoutShortOption, 1, true);77test('Does not print stderr, verbose default, fd-specific, sync', testNoPrintOutput, {}, 2, true);78test('Does not print stderr, verbose "none", fd-specific, sync', testNoPrintOutput, stderrNoneOption, 2, true);79test('Does not print stderr, verbose "short", fd-specific, sync', testNoPrintOutput, stderrShortOption, 2, true);80test('Does not print stdio[*], verbose default, fd-specific, sync', testNoPrintOutput, {}, 3, true);81test('Does not print stdio[*], verbose "none", fd-specific, sync', testNoPrintOutput, fd3NoneOption, 3, true);82test('Does not print stdio[*], verbose "short", fd-specific, sync', testNoPrintOutput, fd3ShortOption, 3, true);83test('Does not print stdio[*], verbose "full", fd-specific, sync', testNoPrintOutput, fd3FullOption, 3, true);8491const testPrintError = async (t, execaMethod) => {92 const stderr = await execaMethod(t, 'full');85const testPrintError = async (t, isSync) => {86 const stderr = await runErrorSubprocess(t, 'full', isSync);87 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);88};8996test('Prints stdout after errors', testPrintError, runErrorSubprocessAsync);97test('Prints stdout after errors, sync', testPrintError, runErrorSubprocessSync);90test('Prints stdout after errors', testPrintError, false);91test('Prints stdout after errors, sync', testPrintError, true);9293test('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});9798test('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});102103test('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});107108test('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});112113test('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});117118const 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};122123test('Does not change subprocess.stdout', testStdioSame, 1);124test('Does not change subprocess.stderr', testStdioSame, 2);125132const testSingleNewline = async (t, execaMethod) => {133 const {stderr} = await execaMethod('noop-fd.js', ['1', '\n'], {verbose: 'full'});126const 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};130137test('Prints stdout, single newline', testSingleNewline, parentExecaAsync);138test('Prints stdout, single newline, sync', testSingleNewline, parentExecaSync);131test('Prints stdout, single newline', testSingleNewline, false);132test('Prints stdout, single newline, sync', testSingleNewline, true);133134const 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};143144test('Can use encoding UTF16, verbose "full"', testUtf16, false);
1 unmodified line
modified:test/verbose/output-mixed.js+45 added-17 removed
1 unmodified line
2import test from 'ava';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {foobarString, foobarObject} from '../helpers/input.js';5import {simpleFull, noNewlinesChunks} from '../helpers/lines.js';6import {parentExeca, parentExecaAsync, parentExecaSync} from '../helpers/nested.js';6import {nestedSubprocess} from '../helpers/nested.js';7import {getOutputLine, getOutputLines, testTimestamp} from '../helpers/verbose.js';89setFixtureDirectory();1011const testLines = async (t, lines, stripFinalNewline, execaMethod) => {12 const {stderr} = await execaMethod('noop-fd.js', ['1', simpleFull], {verbose: 'full', lines, stripFinalNewline});11const 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};2016test('Prints stdout, "lines: true"', testLines, true, false, parentExecaAsync);17test('Prints stdout, "lines: true", fd-specific', testLines, {stdout: true}, false, parentExecaAsync);18test('Prints stdout, "lines: true", stripFinalNewline', testLines, true, true, parentExecaAsync);19test('Prints stdout, "lines: true", sync', testLines, true, false, parentExecaSync);20test('Prints stdout, "lines: true", fd-specific, sync', testLines, {stdout: true}, false, parentExecaSync);21test('Prints stdout, "lines: true", stripFinalNewline, sync', testLines, true, true, parentExecaSync);21test('Prints stdout, "lines: true"', testLines, true, false, false);22test('Prints stdout, "lines: true", fd-specific', testLines, {stdout: true}, false, false);23test('Prints stdout, "lines: true", stripFinalNewline', testLines, true, true, false);24test('Prints stdout, "lines: true", sync', testLines, true, false, true);25test('Prints stdout, "lines: true", fd-specific, sync', testLines, {stdout: true}, false, true);26test('Prints stdout, "lines: true", stripFinalNewline, sync', testLines, true, true, true);2723const testOnlyTransforms = async (t, type, isSync) => {24 const {stderr} = await parentExeca('nested-transform.js', 'noop.js', [foobarString], {verbose: 'full', type, isSync});28const 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};3628test('Prints stdout with only transforms', testOnlyTransforms, 'generator', false);29test('Prints stdout with only transforms, sync', testOnlyTransforms, 'generator', true);30test('Prints stdout with only duplexes', testOnlyTransforms, 'duplex', false);37test('Prints stdout with only transforms', testOnlyTransforms, false);38test('Prints stdout with only transforms, sync', testOnlyTransforms, true);3940test('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});4748const 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};5657test('Prints stdout with object transforms', testObjectMode, false);58test('Prints stdout with object transforms, sync', testObjectMode, true);5960const 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 lines
72test('Prints stdout with big object transforms', testBigArray, false);73test('Prints stdout with big object transforms, sync', testBigArray, true);7475const 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};8384test('Prints stdout with string transforms in objectMode', testObjectModeString, false);
1 unmodified line
modified:test/verbose/output-noop.js+53 added-33 removed
1 unmodified line
2import test from 'ava';3import tempfile from 'tempfile';4import {setFixtureDirectory} from '../helpers/fixtures-directory.js';5import {foobarString} from '../helpers/input.js';6import {parentExeca, parentExecaAsync, parentExecaSync} from '../helpers/nested.js';6import {nestedSubprocess} from '../helpers/nested.js';7import {getOutputLine, testTimestamp} from '../helpers/verbose.js';89setFixtureDirectory();1011const testNoOutputOptions = async (t, fixtureName, options = {}) => {12 const {stderr} = await parentExeca(fixtureName, 'noop.js', [foobarString], {verbose: 'full', ...options});11const testNoOutputOptions = async (t, isSync, options) => {12 const {stderr} = await nestedSubprocess('noop.js', [foobarString], {verbose: 'full', isSync, ...options});13 t.is(getOutputLine(stderr), undefined);14};1516test('Does not print stdout, encoding "buffer"', testNoOutputOptions, 'nested.js', {encoding: 'buffer'});17test('Does not print stdout, encoding "hex"', testNoOutputOptions, 'nested.js', {encoding: 'hex'});18test('Does not print stdout, encoding "base64"', testNoOutputOptions, 'nested.js', {encoding: 'base64'});19test('Does not print stdout, stdout "ignore"', testNoOutputOptions, 'nested.js', {stdout: 'ignore'});20test('Does not print stdout, stdout "inherit"', testNoOutputOptions, 'nested.js', {stdout: 'inherit'});21test('Does not print stdout, stdout 1', testNoOutputOptions, 'nested.js', {stdout: 1});22test('Does not print stdout, stdout Writable', testNoOutputOptions, 'nested-writable.js');23test('Does not print stdout, stdout WritableStream', testNoOutputOptions, 'nested-writable-web.js');24test('Does not print stdout, .pipe(stream)', testNoOutputOptions, 'nested-pipe-stream.js');25test('Does not print stdout, .pipe(subprocess)', testNoOutputOptions, 'nested-pipe-subprocess.js');26test('Does not print stdout, encoding "buffer", sync', testNoOutputOptions, 'nested-sync.js', {encoding: 'buffer'});27test('Does not print stdout, encoding "hex", sync', testNoOutputOptions, 'nested-sync.js', {encoding: 'hex'});28test('Does not print stdout, encoding "base64", sync', testNoOutputOptions, 'nested-sync.js', {encoding: 'base64'});29test('Does not print stdout, stdout "ignore", sync', testNoOutputOptions, 'nested-sync.js', {stdout: 'ignore'});30test('Does not print stdout, stdout "inherit", sync', testNoOutputOptions, 'nested-sync.js', {stdout: 'inherit'});31test('Does not print stdout, stdout 1, sync', testNoOutputOptions, 'nested-sync.js', {stdout: 1});16test('Does not print stdout, encoding "buffer"', testNoOutputOptions, false, {encoding: 'buffer'});17test('Does not print stdout, encoding "hex"', testNoOutputOptions, false, {encoding: 'hex'});18test('Does not print stdout, encoding "base64"', testNoOutputOptions, false, {encoding: 'base64'});19test('Does not print stdout, stdout "ignore"', testNoOutputOptions, false, {stdout: 'ignore'});20test('Does not print stdout, stdout "inherit"', testNoOutputOptions, false, {stdout: 'inherit'});21test('Does not print stdout, stdout 1', testNoOutputOptions, false, {stdout: 1});22test('Does not print stdout, encoding "buffer", sync', testNoOutputOptions, true, {encoding: 'buffer'});23test('Does not print stdout, encoding "hex", sync', testNoOutputOptions, true, {encoding: 'hex'});24test('Does not print stdout, encoding "base64", sync', testNoOutputOptions, true, {encoding: 'base64'});25test('Does not print stdout, stdout "ignore", sync', testNoOutputOptions, true, {stdout: 'ignore'});26test('Does not print stdout, stdout "inherit", sync', testNoOutputOptions, true, {stdout: 'inherit'});27test('Does not print stdout, stdout 1, sync', testNoOutputOptions, true, {stdout: 1});2833const testStdoutFile = async (t, fixtureName, getStdout) => {29const testNoOutputDynamic = async (t, isSync, optionsFixture) => {30 const {stderr} = await nestedSubprocess('noop.js', [foobarString], {verbose: 'full', isSync, optionsFixture});31 t.is(getOutputLine(stderr), undefined);32};3334test('Does not print stdout, stdout Writable', testNoOutputDynamic, false, 'writable.js');35test('Does not print stdout, stdout WritableStream', testNoOutputDynamic, false, 'writable-web.js');36test('Does not print stdout, stdout Writable, sync', testNoOutputDynamic, true, 'writable.js');37test('Does not print stdout, stdout WritableStream, sync', testNoOutputDynamic, true, 'writable-web.js');3839const testNoOutputStream = async (t, parentFixture) => {40 const {stderr} = await nestedSubprocess('noop.js', [foobarString], {verbose: 'full', parentFixture});41 t.is(getOutputLine(stderr), undefined);42};4344test('Does not print stdout, .pipe(stream)', testNoOutputStream, 'nested-pipe-stream.js');45test('Does not print stdout, .pipe(subprocess)', testNoOutputStream, 'nested-pipe-subprocess.js');4647const 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};6042test('Does not print stdout, stdout { file }', testStdoutFile, 'nested.js', file => ({file}));43test('Does not print stdout, stdout fileUrl', testStdoutFile, 'nested-file-url.js', file => file);44test('Does not print stdout, stdout { file }, sync', testStdoutFile, 'nested-sync.js', file => ({file}));61test('Does not print stdout, stdout { file }', testStdoutFile, false);62test('Does not print stdout, stdout fileUrl', testStdoutFile, false, 'file-url.js');63test('Does not print stdout, stdout { file }, sync', testStdoutFile, true);64test('Does not print stdout, stdout fileUrl, sync', testStdoutFile, true, 'file-url.js');6546const testPrintOutputOptions = async (t, options, execaMethod) => {47 const {stderr} = await execaMethod('noop.js', [foobarString], {verbose: 'full', ...options});66const 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};7051test('Prints stdout, stdout "pipe"', testPrintOutputOptions, {stdout: 'pipe'}, parentExecaAsync);52test('Prints stdout, stdout "overlapped"', testPrintOutputOptions, {stdout: 'overlapped'}, parentExecaAsync);53test('Prints stdout, stdout null', testPrintOutputOptions, {stdout: null}, parentExecaAsync);54test('Prints stdout, stdout ["pipe"]', testPrintOutputOptions, {stdout: ['pipe']}, parentExecaAsync);55test('Prints stdout, stdout "pipe", sync', testPrintOutputOptions, {stdout: 'pipe'}, parentExecaSync);56test('Prints stdout, stdout null, sync', testPrintOutputOptions, {stdout: null}, parentExecaSync);57test('Prints stdout, stdout ["pipe"], sync', testPrintOutputOptions, {stdout: ['pipe']}, parentExecaSync);71test('Prints stdout, stdout "pipe"', testPrintOutputOptions, {stdout: 'pipe'}, false);72test('Prints stdout, stdout "overlapped"', testPrintOutputOptions, {stdout: 'overlapped'}, false);73test('Prints stdout, stdout null', testPrintOutputOptions, {stdout: null}, false);74test('Prints stdout, stdout ["pipe"]', testPrintOutputOptions, {stdout: ['pipe']}, false);75test('Prints stdout, stdout "pipe", sync', testPrintOutputOptions, {stdout: 'pipe'}, true);76test('Prints stdout, stdout null, sync', testPrintOutputOptions, {stdout: null}, true);77test('Prints stdout, stdout ["pipe"], sync', testPrintOutputOptions, {stdout: ['pipe']}, true);
modified:test/verbose/output-pipe.js+24 added-26 removed
1import test from 'ava';2import {execa} from '../../index.js';2import {setFixtureDirectory} from '../helpers/fixtures-directory.js';3import {foobarString} from '../helpers/input.js';5import {parentExeca} from '../helpers/nested.js';4import {nestedSubprocess} from '../helpers/nested.js';5import {6 getOutputLine,7 getOutputLines,8 testTimestamp,
1 unmodified line
10} from '../helpers/verbose.js';1112setFixtureDirectory();1315const 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 ]);14const 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 });2122 const lines = getOutputLines(stderr);23 const id = sourceVerbose && destinationVerbose ? 1 : 0;24 t.deepEqual(lines, destinationVerbose25 ? [`${testTimestamp} [${id}] ${foobarString}`]26 : []);27};2831test('Prints stdout if both verbose with .pipe("file")', testPipeOutput, 'file', true, true);32test('Prints stdout if both verbose with .pipe`command`', testPipeOutput, 'script', true, true);33test('Prints stdout if both verbose with .pipe(subprocess)', testPipeOutput, 'subprocesses', true, true);34test('Prints stdout if only second verbose with .pipe("file")', testPipeOutput, 'file', false, true);35test('Prints stdout if only second verbose with .pipe`command`', testPipeOutput, 'script', false, true);36test('Prints stdout if only second verbose with .pipe(subprocess)', testPipeOutput, 'subprocesses', false, true);37test('Does not print stdout if only first verbose with .pipe("file")', testPipeOutput, 'file', true, false);38test('Does not print stdout if only first verbose with .pipe`command`', testPipeOutput, 'script', true, false);39test('Does not print stdout if only first verbose with .pipe(subprocess)', testPipeOutput, 'subprocesses', true, false);40test('Does not print stdout if neither verbose with .pipe("file")', testPipeOutput, 'file', false, false);41test('Does not print stdout if neither verbose with .pipe`command`', testPipeOutput, 'script', false, false);42test('Does not print stdout if neither verbose with .pipe(subprocess)', testPipeOutput, 'subprocesses', false, false);29test('Prints stdout if both verbose with .pipe("file")', testPipeOutput, 'nested-pipe-file.js', true, true);30test('Prints stdout if both verbose with .pipe`command`', testPipeOutput, 'nested-pipe-script.js', true, true);31test('Prints stdout if both verbose with .pipe(subprocess)', testPipeOutput, 'nested-pipe-subprocesses.js', true, true);32test('Prints stdout if only second verbose with .pipe("file")', testPipeOutput, 'nested-pipe-file.js', false, true);33test('Prints stdout if only second verbose with .pipe`command`', testPipeOutput, 'nested-pipe-script.js', false, true);34test('Prints stdout if only second verbose with .pipe(subprocess)', testPipeOutput, 'nested-pipe-subprocesses.js', false, true);35test('Does not print stdout if only first verbose with .pipe("file")', testPipeOutput, 'nested-pipe-file.js', true, false);36test('Does not print stdout if only first verbose with .pipe`command`', testPipeOutput, 'nested-pipe-script.js', true, false);37test('Does not print stdout if only first verbose with .pipe(subprocess)', testPipeOutput, 'nested-pipe-subprocesses.js', true, false);38test('Does not print stdout if neither verbose with .pipe("file")', testPipeOutput, 'nested-pipe-file.js', false, false);39test('Does not print stdout if neither verbose with .pipe`command`', testPipeOutput, 'nested-pipe-script.js', false, false);40test('Does not print stdout if neither verbose with .pipe(subprocess)', testPipeOutput, 'nested-pipe-subprocesses.js', false, false);4144const testPrintOutputFixture = async (t, fixtureName, ...commandArguments) => {45 const {stderr} = await parentExeca(fixtureName, 'noop.js', [foobarString, ...commandArguments], {verbose: 'full'});42const 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};4649test('Prints stdout, .pipe(stream) + .unpipe()', testPrintOutputFixture, 'nested-pipe-stream.js', 'true');50test('Prints stdout, .pipe(subprocess) + .unpipe()', testPrintOutputFixture, 'nested-pipe-subprocess.js', 'true');47test('Prints stdout, .pipe(stream) + .unpipe()', testPrintOutputFixture, 'nested-pipe-stream.js');48test('Prints stdout, .pipe(subprocess) + .unpipe()', testPrintOutputFixture, 'nested-pipe-subprocess.js');
modified:test/verbose/output-progressive.js+7 added-7 removed
1import {on} from 'node:events';2import test from 'ava';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {foobarString} from '../helpers/input.js';5import {parentExeca, parentExecaAsync, parentExecaSync} from '../helpers/nested.js';5import {nestedSubprocess, nestedInstance} from '../helpers/nested.js';6import {getOutputLine, getOutputLines, testTimestamp} from '../helpers/verbose.js';78setFixtureDirectory();910test('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'});1213 for await (const chunk of on(subprocess.stderr, 'data')) {14 const outputLine = getOutputLine(chunk.toString().trim());15 if (outputLine !== undefined) {
5 unmodified lines
21 await subprocess;22});2324test.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'});2627 let firstSubprocessPrinted = false;28 let secondSubprocessPrinted = false;29 for await (const chunk of on(subprocess.stderr, 'data')) {
18 unmodified lines
48 subprocess.kill();49 await t.throwsAsync(subprocess);50});5152const testInterleaved = async (t, expectedLines, execaMethod) => {53 const {stderr} = await execaMethod('noop-132.js', {verbose: 'full'});52const 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};5657test('Prints stdout + stderr interleaved', testInterleaved, [1, 2, 3], parentExecaAsync);58test('Prints stdout + stderr not interleaved, sync', testInterleaved, [1, 3, 2], parentExecaSync);57test('Prints stdout + stderr interleaved', testInterleaved, [1, 2, 3], false);58test('Prints stdout + stderr not interleaved, sync', testInterleaved, [1, 3, 2], true);
modified:test/verbose/start.js+95 added-88 removed
1import test from 'ava';2import {red} from 'yoctocolors';3import {execa} from '../../index.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {foobarString} from '../helpers/input.js';6import {parentExecaAsync, parentExecaSync, parentWorker} from '../helpers/nested.js';5import {nestedSubprocess} from '../helpers/nested.js';6import {7 QUOTE,9 runErrorSubprocessAsync,10 runErrorSubprocessSync,11 runEarlyErrorSubprocessAsync,12 runEarlyErrorSubprocessSync,8 runErrorSubprocess,9 runEarlyErrorSubprocess,10 getCommandLine,11 getCommandLines,12 testTimestamp,13 getVerboseOption,
12 unmodified lines
26} from '../helpers/verbose.js';2728setFixtureDirectory();2933const testPrintCommand = async (t, verbose, execaMethod) => {34 const {stderr} = await execaMethod('noop.js', [foobarString], {verbose});30const 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};3438test('Prints command, verbose "short"', testPrintCommand, 'short', parentExecaAsync);39test('Prints command, verbose "full"', testPrintCommand, 'full', parentExecaAsync);40test('Prints command, verbose "short", fd-specific stdout', testPrintCommand, stdoutShortOption, parentExecaAsync);41test('Prints command, verbose "full", fd-specific stdout', testPrintCommand, stdoutFullOption, parentExecaAsync);42test('Prints command, verbose "short", fd-specific stderr', testPrintCommand, stderrShortOption, parentExecaAsync);43test('Prints command, verbose "full", fd-specific stderr', testPrintCommand, stderrFullOption, parentExecaAsync);44test('Prints command, verbose "short", fd-specific fd3', testPrintCommand, fd3ShortOption, parentExecaAsync);45test('Prints command, verbose "full", fd-specific fd3', testPrintCommand, fd3FullOption, parentExecaAsync);46test('Prints command, verbose "short", fd-specific ipc', testPrintCommand, ipcShortOption, parentExecaAsync);47test('Prints command, verbose "full", fd-specific ipc', testPrintCommand, ipcFullOption, parentExecaAsync);48test('Prints command, verbose "short", sync', testPrintCommand, 'short', parentExecaSync);49test('Prints command, verbose "full", sync', testPrintCommand, 'full', parentExecaSync);50test('Prints command, verbose "short", fd-specific stdout, sync', testPrintCommand, stdoutShortOption, parentExecaSync);51test('Prints command, verbose "full", fd-specific stdout, sync', testPrintCommand, stdoutFullOption, parentExecaSync);52test('Prints command, verbose "short", fd-specific stderr, sync', testPrintCommand, stderrShortOption, parentExecaSync);53test('Prints command, verbose "full", fd-specific stderr, sync', testPrintCommand, stderrFullOption, parentExecaSync);54test('Prints command, verbose "short", fd-specific fd3, sync', testPrintCommand, fd3ShortOption, parentExecaSync);55test('Prints command, verbose "full", fd-specific fd3, sync', testPrintCommand, fd3FullOption, parentExecaSync);56test('Prints command, verbose "short", fd-specific ipc, sync', testPrintCommand, ipcShortOption, parentExecaSync);57test('Prints command, verbose "full", fd-specific ipc, sync', testPrintCommand, ipcFullOption, parentExecaSync);58test('Prints command, verbose "short", worker', testPrintCommand, 'short', parentWorker);59test('Prints command, verbose "full", worker', testPrintCommand, 'full', parentWorker);60test('Prints command, verbose "short", fd-specific stdout, worker', testPrintCommand, stdoutShortOption, parentWorker);61test('Prints command, verbose "full", fd-specific stdout, worker', testPrintCommand, stdoutFullOption, parentWorker);62test('Prints command, verbose "short", fd-specific stderr, worker', testPrintCommand, stderrShortOption, parentWorker);63test('Prints command, verbose "full", fd-specific stderr, worker', testPrintCommand, stderrFullOption, parentWorker);64test('Prints command, verbose "short", fd-specific fd3, worker', testPrintCommand, fd3ShortOption, parentWorker);65test('Prints command, verbose "full", fd-specific fd3, worker', testPrintCommand, fd3FullOption, parentWorker);66test('Prints command, verbose "short", fd-specific ipc, worker', testPrintCommand, ipcShortOption, parentWorker);67test('Prints command, verbose "full", fd-specific ipc, worker', testPrintCommand, ipcFullOption, parentWorker);35test('Prints command, verbose "short"', testPrintCommand, 'short', false, false);36test('Prints command, verbose "full"', testPrintCommand, 'full', false, false);37test('Prints command, verbose "short", fd-specific stdout', testPrintCommand, stdoutShortOption, false, false);38test('Prints command, verbose "full", fd-specific stdout', testPrintCommand, stdoutFullOption, false, false);39test('Prints command, verbose "short", fd-specific stderr', testPrintCommand, stderrShortOption, false, false);40test('Prints command, verbose "full", fd-specific stderr', testPrintCommand, stderrFullOption, false, false);41test('Prints command, verbose "short", fd-specific fd3', testPrintCommand, fd3ShortOption, false, false);42test('Prints command, verbose "full", fd-specific fd3', testPrintCommand, fd3FullOption, false, false);43test('Prints command, verbose "short", fd-specific ipc', testPrintCommand, ipcShortOption, false, false);44test('Prints command, verbose "full", fd-specific ipc', testPrintCommand, ipcFullOption, false, false);45test('Prints command, verbose "short", sync', testPrintCommand, 'short', false, true);46test('Prints command, verbose "full", sync', testPrintCommand, 'full', false, true);47test('Prints command, verbose "short", fd-specific stdout, sync', testPrintCommand, stdoutShortOption, false, true);48test('Prints command, verbose "full", fd-specific stdout, sync', testPrintCommand, stdoutFullOption, false, true);49test('Prints command, verbose "short", fd-specific stderr, sync', testPrintCommand, stderrShortOption, false, true);50test('Prints command, verbose "full", fd-specific stderr, sync', testPrintCommand, stderrFullOption, false, true);51test('Prints command, verbose "short", fd-specific fd3, sync', testPrintCommand, fd3ShortOption, false, true);52test('Prints command, verbose "full", fd-specific fd3, sync', testPrintCommand, fd3FullOption, false, true);53test('Prints command, verbose "short", fd-specific ipc, sync', testPrintCommand, ipcShortOption, false, true);54test('Prints command, verbose "full", fd-specific ipc, sync', testPrintCommand, ipcFullOption, false, true);55test('Prints command, verbose "short", worker', testPrintCommand, 'short', true, false);56test('Prints command, verbose "full", worker', testPrintCommand, 'full', true, false);57test('Prints command, verbose "short", fd-specific stdout, worker', testPrintCommand, stdoutShortOption, true, false);58test('Prints command, verbose "full", fd-specific stdout, worker', testPrintCommand, stdoutFullOption, true, false);59test('Prints command, verbose "short", fd-specific stderr, worker', testPrintCommand, stderrShortOption, true, false);60test('Prints command, verbose "full", fd-specific stderr, worker', testPrintCommand, stderrFullOption, true, false);61test('Prints command, verbose "short", fd-specific fd3, worker', testPrintCommand, fd3ShortOption, true, false);62test('Prints command, verbose "full", fd-specific fd3, worker', testPrintCommand, fd3FullOption, true, false);63test('Prints command, verbose "short", fd-specific ipc, worker', testPrintCommand, ipcShortOption, true, false);64test('Prints command, verbose "full", fd-specific ipc, worker', testPrintCommand, ipcFullOption, true, false);65test('Prints command, verbose "short", worker, sync', testPrintCommand, 'short', true, true);66test('Prints command, verbose "full", worker, sync', testPrintCommand, 'full', true, true);67test('Prints command, verbose "short", fd-specific stdout, worker, sync', testPrintCommand, stdoutShortOption, true, true);68test('Prints command, verbose "full", fd-specific stdout, worker, sync', testPrintCommand, stdoutFullOption, true, true);69test('Prints command, verbose "short", fd-specific stderr, worker, sync', testPrintCommand, stderrShortOption, true, true);70test('Prints command, verbose "full", fd-specific stderr, worker, sync', testPrintCommand, stderrFullOption, true, true);71test('Prints command, verbose "short", fd-specific fd3, worker, sync', testPrintCommand, fd3ShortOption, true, true);72test('Prints command, verbose "full", fd-specific fd3, worker, sync', testPrintCommand, fd3FullOption, true, true);73test('Prints command, verbose "short", fd-specific ipc, worker, sync', testPrintCommand, ipcShortOption, true, true);74test('Prints command, verbose "full", fd-specific ipc, worker, sync', testPrintCommand, ipcFullOption, true, true);7569const testNoPrintCommand = async (t, verbose, execaMethod) => {70 const {stderr} = await execaMethod('noop.js', [foobarString], {verbose});76const testNoPrintCommand = async (t, verbose, isSync) => {77 const {stderr} = await nestedSubprocess('noop.js', [foobarString], {verbose, isSync});78 t.is(stderr, '');79};8074test('Does not print command, verbose "none"', testNoPrintCommand, 'none', parentExecaAsync);75test('Does not print command, verbose default', testNoPrintCommand, undefined, parentExecaAsync);76test('Does not print command, verbose "none", fd-specific stdout', testNoPrintCommand, stdoutNoneOption, parentExecaAsync);77test('Does not print command, verbose "none", fd-specific stderr', testNoPrintCommand, stderrNoneOption, parentExecaAsync);78test('Does not print command, verbose "none", fd-specific fd3', testNoPrintCommand, fd3NoneOption, parentExecaAsync);79test('Does not print command, verbose "none", fd-specific ipc', testNoPrintCommand, ipcNoneOption, parentExecaAsync);80test('Does not print command, verbose default, fd-specific', testNoPrintCommand, {}, parentExecaAsync);81test('Does not print command, verbose "none", sync', testNoPrintCommand, 'none', parentExecaSync);82test('Does not print command, verbose default, sync', testNoPrintCommand, undefined, parentExecaSync);83test('Does not print command, verbose "none", fd-specific stdout, sync', testNoPrintCommand, stdoutNoneOption, parentExecaSync);84test('Does not print command, verbose "none", fd-specific stderr, sync', testNoPrintCommand, stderrNoneOption, parentExecaSync);85test('Does not print command, verbose "none", fd-specific fd3, sync', testNoPrintCommand, fd3NoneOption, parentExecaSync);86test('Does not print command, verbose "none", fd-specific ipc, sync', testNoPrintCommand, ipcNoneOption, parentExecaSync);87test('Does not print command, verbose default, fd-specific, sync', testNoPrintCommand, {}, parentExecaSync);81test('Does not print command, verbose "none"', testNoPrintCommand, 'none', false);82test('Does not print command, verbose default', testNoPrintCommand, undefined, false);83test('Does not print command, verbose "none", fd-specific stdout', testNoPrintCommand, stdoutNoneOption, false);84test('Does not print command, verbose "none", fd-specific stderr', testNoPrintCommand, stderrNoneOption, false);85test('Does not print command, verbose "none", fd-specific fd3', testNoPrintCommand, fd3NoneOption, false);86test('Does not print command, verbose "none", fd-specific ipc', testNoPrintCommand, ipcNoneOption, false);87test('Does not print command, verbose default, fd-specific', testNoPrintCommand, {}, false);88test('Does not print command, verbose "none", sync', testNoPrintCommand, 'none', true);89test('Does not print command, verbose default, sync', testNoPrintCommand, undefined, true);90test('Does not print command, verbose "none", fd-specific stdout, sync', testNoPrintCommand, stdoutNoneOption, true);91test('Does not print command, verbose "none", fd-specific stderr, sync', testNoPrintCommand, stderrNoneOption, true);92test('Does not print command, verbose "none", fd-specific fd3, sync', testNoPrintCommand, fd3NoneOption, true);93test('Does not print command, verbose "none", fd-specific ipc, sync', testNoPrintCommand, ipcNoneOption, true);94test('Does not print command, verbose default, fd-specific, sync', testNoPrintCommand, {}, true);9589const testPrintCommandError = async (t, execaMethod) => {90 const stderr = await execaMethod(t, 'short');96const 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};10094test('Prints command after errors', testPrintCommandError, runErrorSubprocessAsync);95test('Prints command after errors, sync', testPrintCommandError, runErrorSubprocessSync);101test('Prints command after errors', testPrintCommandError, false);102test('Prints command after errors, sync', testPrintCommandError, true);10397const testPrintCommandEarly = async (t, execaMethod) => {98 const stderr = await execaMethod(t);104const testPrintCommandEarly = async (t, isSync) => {105 const stderr = await runEarlyErrorSubprocess(t, isSync);106 t.is(getCommandLine(stderr), `${testTimestamp} [0] $ noop.js ${foobarString}`);107};108102test('Prints command before early validation errors', testPrintCommandEarly, runEarlyErrorSubprocessAsync);103test('Prints command before early validation errors, sync', testPrintCommandEarly, runEarlyErrorSubprocessSync);109test('Prints command before early validation errors', testPrintCommandEarly, false);110test('Prints command before early validation errors, sync', testPrintCommandEarly, true);111105const 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' ? '$' : '|';112const 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 });119120 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};125119test('Prints both commands piped with .pipe("file")', testPipeCommand, 'file', true, true);120test('Prints both commands piped with .pipe`command`', testPipeCommand, 'script', true, true);121test('Prints both commands piped with .pipe(subprocess)', testPipeCommand, 'subprocesses', true, true);122test('Prints first command piped with .pipe("file")', testPipeCommand, 'file', true, false);123test('Prints first command piped with .pipe`command`', testPipeCommand, 'script', true, false);124test('Prints first command piped with .pipe(subprocess)', testPipeCommand, 'subprocesses', true, false);125test('Prints second command piped with .pipe("file")', testPipeCommand, 'file', false, true);126test('Prints second command piped with .pipe`command`', testPipeCommand, 'script', false, true);127test('Prints second command piped with .pipe(subprocess)', testPipeCommand, 'subprocesses', false, true);128test('Prints neither commands piped with .pipe("file")', testPipeCommand, 'file', false, false);129test('Prints neither commands piped with .pipe`command`', testPipeCommand, 'script', false, false);130test('Prints neither commands piped with .pipe(subprocess)', testPipeCommand, 'subprocesses', false, false);126test('Prints both commands piped with .pipe("file")', testPipeCommand, 'nested-pipe-file.js', true, true);127test('Prints both commands piped with .pipe`command`', testPipeCommand, 'nested-pipe-script.js', true, true);128test('Prints both commands piped with .pipe(subprocess)', testPipeCommand, 'nested-pipe-subprocesses.js', true, true);129test('Prints first command piped with .pipe("file")', testPipeCommand, 'nested-pipe-file.js', true, false);130test('Prints first command piped with .pipe`command`', testPipeCommand, 'nested-pipe-script.js', true, false);131test('Prints first command piped with .pipe(subprocess)', testPipeCommand, 'nested-pipe-subprocesses.js', true, false);132test('Prints second command piped with .pipe("file")', testPipeCommand, 'nested-pipe-file.js', false, true);133test('Prints second command piped with .pipe`command`', testPipeCommand, 'nested-pipe-script.js', false, true);134test('Prints second command piped with .pipe(subprocess)', testPipeCommand, 'nested-pipe-subprocesses.js', false, true);135test('Prints neither commands piped with .pipe("file")', testPipeCommand, 'nested-pipe-file.js', false, false);136test('Prints neither commands piped with .pipe`command`', testPipeCommand, 'nested-pipe-script.js', false, false);137test('Prints neither commands piped with .pipe(subprocess)', testPipeCommand, 'nested-pipe-subprocesses.js', false, false);138139test('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});143144test('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});148149test('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});153154test('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});158159test('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});