Add tests for `node:worker_threads` (#964)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent f3cb72b · Browse files · 15 files·+291 added−210 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
15 files+291 added−210 removed
- tests:+288 added−208 removed
- other:+3 added−2 removed
Provenance
- Commit
a1cd3cf- Tree
dfdf31e- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
f3cb72b
15 files changed+291 added−210 removed
modified:lib/verbose/log.js+3 added-2 removed
122345679891011121314151628 unmodified linesimport {writeFileSync} from 'node:fs';import process from 'node:process';import figures from 'figures';import {gray} from 'yoctocolors';
// Write synchronously to ensure lines are properly ordered and not interleaved with `stdout`export const verboseLog = (string, verboseId, icon, color) => { const prefixedLines = addPrefix(string, verboseId, icon, color); writeFileSync(process.stderr.fd, `${prefixedLines}\n`); writeFileSync(STDERR_FD, `${prefixedLines}\n`);};
const STDERR_FD = 2;
const addPrefix = (string, verboseId, icon, color) => string.includes('\n') ? string .split('\n') .map(line => addPrefixToLine(line, verboseId, icon, color))28 unmodified linesmodified:test/exit/cleanup.js+13 added-6 removed
3 unmodified lines456789101112131415141516171819201819202121222324252627282930313270 unmodified lines3 unmodified linesimport {pEvent} from 'p-event';import isRunning from 'is-running';import {execa, execaSync} from '../../index.js';import {setFixtureDir} from '../helpers/fixtures-dir.js';import {nestedExecaAsync, nestedWorker} from '../helpers/nested.js';import {foobarString} from '../helpers/input.js';
setFixtureDir();
const isWindows = process.platform === 'win32';
// When subprocess exits before current processconst spawnAndExit = async (t, cleanup, detached) => { await t.notThrowsAsync(execa('nested.js', [JSON.stringify({cleanup, detached}), 'noop.js']));const spawnAndExit = async (t, execaMethod, cleanup, detached) => { const {stdout} = await execaMethod('noop-fd.js', ['1', foobarString], {cleanup, detached}); t.is(stdout, foobarString);};
test('spawnAndExit', spawnAndExit, false, false);test('spawnAndExit cleanup', spawnAndExit, true, false);test('spawnAndExit detached', spawnAndExit, false, true);test('spawnAndExit cleanup detached', spawnAndExit, true, true);test('spawnAndExit', spawnAndExit, nestedExecaAsync, false, false);test('spawnAndExit cleanup', spawnAndExit, nestedExecaAsync, true, false);test('spawnAndExit detached', spawnAndExit, nestedExecaAsync, false, true);test('spawnAndExit cleanup detached', spawnAndExit, nestedExecaAsync, true, true);test('spawnAndExit, worker', spawnAndExit, nestedWorker, false, false);test('spawnAndExit cleanup, worker', spawnAndExit, nestedWorker, true, false);test('spawnAndExit detached, worker', spawnAndExit, nestedWorker, false, true);test('spawnAndExit cleanup detached, worker', spawnAndExit, nestedWorker, true, true);
// When current process exits before subprocessconst spawnAndKill = async (t, [signal, cleanup, detached, isKilled]) => { const subprocess = execa('subprocess.js', [cleanup, detached], {stdio: 'ignore', ipc: true});70 unmodified linesdeleted:test/fixtures/nested-send.js-7 removed
1234567#!/usr/bin/env nodeimport process from 'node:process';import {execa} from '../../index.js';
const [options, file, ...args] = process.argv.slice(2);const result = await execa(file, args, JSON.parse(options));process.send(result);modified:test/fixtures/nested-sync.js+6 added-1 removed
12345667891011#!/usr/bin/env nodeimport process from 'node:process';import {execaSync} from '../../index.js';
const [options, file, ...args] = process.argv.slice(2);try {execaSync(file, args, JSON.parse(options)); const result = execaSync(file, args, JSON.parse(options)); process.send({result});} catch (error) { process.send({error});}modified:test/fixtures/nested.js+6 added-1 removed
12345667891011#!/usr/bin/env nodeimport process from 'node:process';import {execa} from '../../index.js';
const [options, file, ...args] = process.argv.slice(2);try {await execa(file, args, JSON.parse(options)); const result = await execa(file, args, JSON.parse(options)); process.send({result});} catch (error) { process.send({error});}added:test/fixtures/worker.js+15 added
123456789101112131415import {once} from 'node:events';import {workerData, parentPort} from 'node:worker_threads';import {execa} from '../../index.js';import {setFixtureDir} from '../helpers/fixtures-dir.js';
setFixtureDir();
const {nodeFile, args, options} = workerData;try { const subprocess = execa(nodeFile, args, options); const [parentResult, [{result, error}]] = await Promise.all([subprocess, once(subprocess, 'message')]); parentPort.postMessage({parentResult, result, error});} catch (parentError) { parentPort.postMessage({parentError});}added:test/helpers/nested.js+49 added
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849import {once} from 'node:events';import {Worker} from 'node:worker_threads';import {execa} from '../../index.js';import {FIXTURES_DIR_URL} from './fixtures-dir.js';
const WORKER_URL = new URL('worker.js', FIXTURES_DIR_URL);
const runWorker = (nodeFile, args, options) => { [args, options] = Array.isArray(args) ? [args, options] : [[], args]; return new Worker(WORKER_URL, {workerData: {nodeFile, args, options}});};
// eslint-disable-next-line max-paramsconst nestedCall = (isWorker, fixtureName, execaMethod, file, args, options, parentOptions) => { [args, options = {}, parentOptions = {}] = Array.isArray(args) ? [args, options, parentOptions] : [[], args, options]; const subprocessOrWorker = execaMethod(fixtureName, [JSON.stringify(options), file, ...args], {...parentOptions, ipc: true}); const onMessage = once(subprocessOrWorker, 'message'); const promise = getNestedResult(onMessage); promise.parent = isWorker ? getParentResult(onMessage) : subprocessOrWorker; return promise;};
const getNestedResult = async onMessage => { const {result} = await getMessage(onMessage); return result;};
const getParentResult = async onMessage => { const {parentResult} = await getMessage(onMessage); return parentResult;};
const getMessage = async onMessage => { const [{error, parentError = error, result, parentResult}] = await onMessage; if (parentError) { throw parentError; }
return {result, parentResult};};
export const nestedWorker = (...args) => nestedCall(true, 'nested.js', runWorker, ...args);const nestedExeca = (fixtureName, ...args) => nestedCall(false, fixtureName, execa, ...args);export const nestedExecaAsync = (...args) => nestedExeca('nested.js', ...args);export const nestedExecaSync = (...args) => nestedExeca('nested-sync.js', ...args);export const parentWorker = (...args) => nestedWorker(...args).parent;export const parentExeca = (...args) => nestedExeca(...args).parent;export const parentExecaAsync = (...args) => nestedExecaAsync(...args).parent;export const parentExecaSync = (...args) => nestedExecaSync(...args).parent;modified:test/helpers/verbose.js+23 added-16 removed
1 import {platform} from 'node:process';2 import {stripVTControlCharacters} from 'node:util';3 import {replaceSymbols} from 'figures';4-import {execa} from '../../index.js';4 import {foobarString} from './input.js';5+import {nestedExecaAsync, nestedExecaSync} from './nested.js';6 7 const isWindows = platform === 'win32';8 export const QUOTE = isWindows ? '"' : '\'';9 10-// eslint-disable-next-line max-params11-export const nestedExeca = (fixtureName, file, args, options, parentOptions) => {12- [args, options = {}, parentOptions = {}] = Array.isArray(args) ? [args, options, parentOptions] : [[], args, options];13- return execa(fixtureName, [JSON.stringify(options), file, ...args], parentOptions);14-};10+const runErrorSubprocess = async (execaMethod, t, verbose) => {11+ const subprocess = execaMethod('noop-fail.js', ['1', foobarString], {verbose});12+ await t.throwsAsync(subprocess);13+ const {stderr} = await subprocess.parent;14+ if (verbose !== 'none') {15+ t.true(stderr.includes('exit code 2'));16+ }17 16-export const nestedExecaAsync = nestedExeca.bind(undefined, 'nested.js');17-export const nestedExecaSync = nestedExeca.bind(undefined, 'nested-sync.js');18-19-export const runErrorSubprocess = async (t, verbose, execaMethod) => {20- const {stderr} = await t.throwsAsync(execaMethod('noop-fail.js', ['1', foobarString], {verbose}));21- t.true(stderr.includes('exit code 2'));18 return stderr;19 };20 25-export const runWarningSubprocess = async (t, execaMethod) => {26- const {stderr} = await execaMethod('noop-fail.js', ['1', foobarString], {verbose: 'short', reject: false});21+export const runErrorSubprocessAsync = runErrorSubprocess.bind(undefined, nestedExecaAsync);22+export const runErrorSubprocessSync = runErrorSubprocess.bind(undefined, nestedExecaSync);23+24+const runWarningSubprocess = async (execaMethod, t) => {25+ const {stderr} = await execaMethod('noop-fail.js', ['1', foobarString], {verbose: 'short', reject: false}).parent;26 t.true(stderr.includes('exit code 2'));27 return stderr;28 };29 31-export const runEarlyErrorSubprocess = async (t, execaMethod) => {32- const {stderr} = await t.throwsAsync(execaMethod('noop.js', [foobarString], {verbose: 'short', cwd: true}));30+export const runWarningSubprocessAsync = runWarningSubprocess.bind(undefined, nestedExecaAsync);31+export const runWarningSubprocessSync = runWarningSubprocess.bind(undefined, nestedExecaSync);32+33+const runEarlyErrorSubprocess = async (execaMethod, t) => {34+ const subprocess = execaMethod('noop.js', [foobarString], {verbose: 'short', cwd: true});35+ await t.throwsAsync(subprocess);36+ const {stderr} = await subprocess.parent;37 t.true(stderr.includes('The "cwd" option must'));38 return stderr;39 };40 41+export const runEarlyErrorSubprocessAsync = runEarlyErrorSubprocess.bind(undefined, nestedExecaAsync);42+export const runEarlyErrorSubprocessSync = runEarlyErrorSubprocess.bind(undefined, nestedExecaSync);43+44 export const getCommandLine = stderr => getCommandLines(stderr)[0];45 export const getCommandLines = stderr => getNormalizedLines(stderr).filter(line => isCommandLine(line));46 const isCommandLine = line => line.includes(' $ ') || line.includes(' | ');47 export const getOutputLine = stderr => getOutputLines(stderr)[0];17 unmodified linesmodified:test/stdio/native.js+31 added-32 removed
4 unmodified lines5 import {execa, execaSync} from '../../index.js';6 import {getStdio, fullStdio} from '../helpers/stdio.js';7 import {setFixtureDir} from '../helpers/fixtures-dir.js';8 import {foobarString} from '../helpers/input.js';9+import {parentExecaAsync, parentExecaSync} from '../helpers/nested.js';10 11 setFixtureDir();12 13 const isLinux = platform === 'linux';14 const isWindows = platform === 'win32';15 15-const getFixtureName = isSync => isSync ? 'nested-sync.js' : 'nested.js';16-16 // eslint-disable-next-line max-params17 const testRedirect = async (t, stdioOption, fdNumber, isInput, isSync) => {18 const {fixtureName, ...options} = isInput19 ? {fixtureName: 'stdin-fd.js', input: foobarString}109 unmodified lines129 test('stderr can be [process.stderr, "pipe"], encoding "buffer", sync', testInheritStdioOutput, 2, 1, ['stderr', 'pipe'], true, 'buffer');130 test('stdio[*] output can be ["inherit", "pipe"], encoding "buffer", sync', testInheritStdioOutput, 3, 1, ['inherit', 'pipe'], true, 'buffer');131 test('stdio[*] output can be [3, "pipe"], encoding "buffer", sync', testInheritStdioOutput, 3, 1, [3, 'pipe'], true, 'buffer');132 134-const testFd3InheritOutput = async (t, stdioOption, isSync) => {135- const {stdio} = await execa(getFixtureName(isSync), [JSON.stringify(getStdio(3, stdioOption)), 'noop-fd.js', '3', foobarString], fullStdio);133+const testFd3InheritOutput = async (t, stdioOption, execaMethod) => {134+ const {stdio} = await execaMethod('noop-fd.js', ['3', foobarString], getStdio(3, stdioOption), fullStdio);135 t.is(stdio[3], foobarString);136 };137 139-test('stdio[*] output can use "inherit"', testFd3InheritOutput, 'inherit', false);140-test('stdio[*] output can use ["inherit"]', testFd3InheritOutput, ['inherit'], false);141-test('stdio[*] output can use "inherit", sync', testFd3InheritOutput, 'inherit', true);142-test('stdio[*] output can use ["inherit"], sync', testFd3InheritOutput, ['inherit'], true);138+test('stdio[*] output can use "inherit"', testFd3InheritOutput, 'inherit', parentExecaAsync);139+test('stdio[*] output can use ["inherit"]', testFd3InheritOutput, ['inherit'], parentExecaAsync);140+test('stdio[*] output can use "inherit", sync', testFd3InheritOutput, 'inherit', parentExecaSync);141+test('stdio[*] output can use ["inherit"], sync', testFd3InheritOutput, ['inherit'], parentExecaSync);142 144-const testInheritNoBuffer = async (t, stdioOption, isSync) => {143+const testInheritNoBuffer = async (t, stdioOption, execaMethod) => {144 const filePath = tempfile();146- await execa(getFixtureName(isSync), [JSON.stringify({stdin: stdioOption, buffer: false}), 'nested-write.js', filePath, foobarString], {input: foobarString});145+ await execaMethod('nested-write.js', [filePath, foobarString], {stdin: stdioOption, buffer: false}, {input: foobarString});146 t.is(await readFile(filePath, 'utf8'), `${foobarString} ${foobarString}`);147 await rm(filePath);148 };149 151-test('stdin can be ["inherit", "pipe"], buffer: false', testInheritNoBuffer, ['inherit', 'pipe'], false);152-test('stdin can be [0, "pipe"], buffer: false', testInheritNoBuffer, [0, 'pipe'], false);153-test.serial('stdin can be ["inherit", "pipe"], buffer: false, sync', testInheritNoBuffer, ['inherit', 'pipe'], true);154-test.serial('stdin can be [0, "pipe"], buffer: false, sync', testInheritNoBuffer, [0, 'pipe'], true);150+test('stdin can be ["inherit", "pipe"], buffer: false', testInheritNoBuffer, ['inherit', 'pipe'], parentExecaAsync);151+test('stdin can be [0, "pipe"], buffer: false', testInheritNoBuffer, [0, 'pipe'], parentExecaAsync);152+test.serial('stdin can be ["inherit", "pipe"], buffer: false, sync', testInheritNoBuffer, ['inherit', 'pipe'], parentExecaSync);153+test.serial('stdin can be [0, "pipe"], buffer: false, sync', testInheritNoBuffer, [0, 'pipe'], parentExecaSync);154 155 if (isLinux) {157- const testOverflowStream = async (t, fdNumber, stdioOption, isSync) => {158- const {stdout} = await execa(getFixtureName(isSync), [JSON.stringify(getStdio(fdNumber, stdioOption)), 'empty.js'], fullStdio);156+ const testOverflowStream = async (t, fdNumber, stdioOption, execaMethod) => {157+ const {stdout} = await execaMethod('empty.js', getStdio(fdNumber, stdioOption), fullStdio);158 t.is(stdout, '');159 };160 162- test('stdin can use 4+', testOverflowStream, 0, 4, false);163- test('stdin can use [4+]', testOverflowStream, 0, [4], false);164- test('stdout can use 4+', testOverflowStream, 1, 4, false);165- test('stdout can use [4+]', testOverflowStream, 1, [4], false);166- test('stderr can use 4+', testOverflowStream, 2, 4, false);167- test('stderr can use [4+]', testOverflowStream, 2, [4], false);168- test('stdio[*] can use 4+', testOverflowStream, 3, 4, false);169- test('stdio[*] can use [4+]', testOverflowStream, 3, [4], false);170- test('stdin can use 4+, sync', testOverflowStream, 0, 4, true);171- test('stdin can use [4+], sync', testOverflowStream, 0, [4], true);172- test('stdout can use 4+, sync', testOverflowStream, 1, 4, true);173- test('stdout can use [4+], sync', testOverflowStream, 1, [4], true);174- test('stderr can use 4+, sync', testOverflowStream, 2, 4, true);175- test('stderr can use [4+], sync', testOverflowStream, 2, [4], true);176- test('stdio[*] can use 4+, sync', testOverflowStream, 3, 4, true);177- test('stdio[*] can use [4+], sync', testOverflowStream, 3, [4], true);161+ test('stdin can use 4+', testOverflowStream, 0, 4, parentExecaAsync);162+ test('stdin can use [4+]', testOverflowStream, 0, [4], parentExecaAsync);163+ test('stdout can use 4+', testOverflowStream, 1, 4, parentExecaAsync);164+ test('stdout can use [4+]', testOverflowStream, 1, [4], parentExecaAsync);165+ test('stderr can use 4+', testOverflowStream, 2, 4, parentExecaAsync);166+ test('stderr can use [4+]', testOverflowStream, 2, [4], parentExecaAsync);167+ test('stdio[*] can use 4+', testOverflowStream, 3, 4, parentExecaAsync);168+ test('stdio[*] can use [4+]', testOverflowStream, 3, [4], parentExecaAsync);169+ test('stdin can use 4+, sync', testOverflowStream, 0, 4, parentExecaSync);170+ test('stdin can use [4+], sync', testOverflowStream, 0, [4], parentExecaSync);171+ test('stdout can use 4+, sync', testOverflowStream, 1, 4, parentExecaSync);172+ test('stdout can use [4+], sync', testOverflowStream, 1, [4], parentExecaSync);173+ test('stderr can use 4+, sync', testOverflowStream, 2, 4, parentExecaSync);174+ test('stderr can use [4+], sync', testOverflowStream, 2, [4], parentExecaSync);175+ test('stdio[*] can use 4+, sync', testOverflowStream, 3, 4, parentExecaSync);176+ test('stdio[*] can use [4+], sync', testOverflowStream, 3, [4], parentExecaSync);177 }178 179 const testOverflowStreamArray = (t, fdNumber, stdioOption) => {180 t.throws(() => {54 unmodified linesmodified:test/verbose/complete.js+23 added-21 removed
1 unmodified line2 import test from 'ava';3 import {execa} from '../../index.js';4 import {setFixtureDir} from '../helpers/fixtures-dir.js';5 import {foobarString} from '../helpers/input.js';6+import {parentExecaAsync, parentExecaSync} from '../helpers/nested.js';7 import {7- nestedExecaAsync,8- nestedExecaSync,9- runErrorSubprocess,10- runWarningSubprocess,11- runEarlyErrorSubprocess,8+ runErrorSubprocessAsync,9+ runErrorSubprocessSync,10+ runWarningSubprocessAsync,11+ runWarningSubprocessSync,12+ runEarlyErrorSubprocessAsync,13+ runEarlyErrorSubprocessSync,14 getCompletionLine,15 getCompletionLines,16 testTimestamp,17 getVerboseOption,5 unmodified lines23 const {stderr} = await execaMethod('noop.js', [foobarString], {verbose});24 t.is(getCompletionLine(stderr), `${testTimestamp} [0] √ (done in 0ms)`);25 };26 25-test('Prints completion, verbose "short"', testPrintCompletion, 'short', nestedExecaAsync);26-test('Prints completion, verbose "full"', testPrintCompletion, 'full', nestedExecaAsync);27-test('Prints completion, verbose "short", sync', testPrintCompletion, 'short', nestedExecaSync);28-test('Prints completion, verbose "full", sync', testPrintCompletion, 'full', nestedExecaSync);27+test('Prints completion, verbose "short"', testPrintCompletion, 'short', parentExecaAsync);28+test('Prints completion, verbose "full"', testPrintCompletion, 'full', parentExecaAsync);29+test('Prints completion, verbose "short", sync', testPrintCompletion, 'short', parentExecaSync);30+test('Prints completion, verbose "full", sync', testPrintCompletion, 'full', parentExecaSync);31 32 const testNoPrintCompletion = async (t, execaMethod) => {33 const {stderr} = await execaMethod('noop.js', [foobarString], {verbose: 'none'});34 t.is(stderr, '');35 };36 35-test('Does not print completion, verbose "none"', testNoPrintCompletion, nestedExecaAsync);36-test('Does not print completion, verbose "none", sync', testNoPrintCompletion, nestedExecaSync);37+test('Does not print completion, verbose "none"', testNoPrintCompletion, parentExecaAsync);38+test('Does not print completion, verbose "none", sync', testNoPrintCompletion, parentExecaSync);39 40 const testPrintCompletionError = async (t, execaMethod) => {39- const stderr = await runErrorSubprocess(t, 'short', execaMethod);41+ const stderr = await execaMethod(t, 'short');42 t.is(getCompletionLine(stderr), `${testTimestamp} [0] × (done in 0ms)`);43 };44 43-test('Prints completion after errors', testPrintCompletionError, nestedExecaAsync);44-test('Prints completion after errors, sync', testPrintCompletionError, nestedExecaSync);45+test('Prints completion after errors', testPrintCompletionError, runErrorSubprocessAsync);46+test('Prints completion after errors, sync', testPrintCompletionError, runErrorSubprocessSync);47 48 const testPrintCompletionWarning = async (t, execaMethod) => {47- const stderr = await runWarningSubprocess(t, execaMethod);49+ const stderr = await execaMethod(t);50 t.is(getCompletionLine(stderr), `${testTimestamp} [0] ‼ (done in 0ms)`);51 };52 51-test('Prints completion after errors, "reject" false', testPrintCompletionWarning, nestedExecaAsync);52-test('Prints completion after errors, "reject" false, sync', testPrintCompletionWarning, nestedExecaSync);53+test('Prints completion after errors, "reject" false', testPrintCompletionWarning, runWarningSubprocessAsync);54+test('Prints completion after errors, "reject" false, sync', testPrintCompletionWarning, runWarningSubprocessSync);55 56 const testPrintCompletionEarly = async (t, execaMethod) => {55- const stderr = await runEarlyErrorSubprocess(t, execaMethod);57+ const stderr = await execaMethod(t);58 t.is(getCompletionLine(stderr), `${testTimestamp} [0] × (done in 0ms)`);59 };60 59-test('Prints completion after early validation errors', testPrintCompletionEarly, nestedExecaAsync);60-test('Prints completion after early validation errors, sync', testPrintCompletionEarly, nestedExecaSync);61+test('Prints completion after early validation errors', testPrintCompletionEarly, runEarlyErrorSubprocessAsync);62+test('Prints completion after early validation errors, sync', testPrintCompletionEarly, runEarlyErrorSubprocessSync);63 64 test.serial('Prints duration', async t => {63- const {stderr} = await nestedExecaAsync('delay.js', ['1000'], {verbose: 'short'});65+ const {stderr} = await parentExecaAsync('delay.js', ['1000'], {verbose: 'short'});66 t.regex(stripVTControlCharacters(stderr).split('\n').at(-1), /\(done in [\d.]+s\)/);67 });68 69 const testPipeDuration = async (t, fixtureName, sourceVerbose, destinationVerbose) => {25 unmodified linesmodified:test/verbose/error.js+26 added-26 removed
1 unmodified line2 import {red} from 'yoctocolors';3 import {execa} from '../../index.js';4 import {setFixtureDir} from '../helpers/fixtures-dir.js';5 import {foobarString} from '../helpers/input.js';6+import {parentExeca, parentExecaAsync, parentExecaSync} from '../helpers/nested.js';7 import {8 QUOTE,8- nestedExeca,9- nestedExecaAsync,10- nestedExecaSync,11- runEarlyErrorSubprocess,9+ runErrorSubprocessAsync,10+ runErrorSubprocessSync,11+ runEarlyErrorSubprocessAsync,12+ runEarlyErrorSubprocessSync,13 getErrorLine,14 getErrorLines,15 testTimestamp,16 getVerboseOption,17 } from '../helpers/verbose.js';18 19 setFixtureDir();20 20-const nestedExecaFail = nestedExeca.bind(undefined, 'nested-fail.js');21+const parentExecaFail = parentExeca.bind(undefined, 'nested-fail.js');22 23 const testPrintError = async (t, verbose, execaMethod) => {23- const {stderr} = await t.throwsAsync(execaMethod('noop-fail.js', ['1', foobarString], {verbose}));24+ const stderr = await execaMethod(t, verbose);25 t.is(getErrorLine(stderr), `${testTimestamp} [0] × Command failed with exit code 2: noop-fail.js 1 ${foobarString}`);26 };27 27-test('Prints error, verbose "short"', testPrintError, 'short', nestedExecaAsync);28-test('Prints error, verbose "full"', testPrintError, 'full', nestedExecaAsync);29-test('Prints error, verbose "short", sync', testPrintError, 'short', nestedExecaSync);30-test('Prints error, verbose "full", sync', testPrintError, 'full', nestedExecaSync);28+test('Prints error, verbose "short"', testPrintError, 'short', runErrorSubprocessAsync);29+test('Prints error, verbose "full"', testPrintError, 'full', runErrorSubprocessAsync);30+test('Prints error, verbose "short", sync', testPrintError, 'short', runErrorSubprocessSync);31+test('Prints error, verbose "full", sync', testPrintError, 'full', runErrorSubprocessSync);32 33 const testNoPrintError = async (t, execaMethod) => {33- const {stderr} = await t.throwsAsync(execaMethod('noop-fail.js', ['1', foobarString], {verbose: 'none'}));34- t.not(stderr, '');34+ const stderr = await execaMethod(t, 'none');35 t.is(getErrorLine(stderr), undefined);36 };37 38-test('Does not print error, verbose "none"', testNoPrintError, nestedExecaAsync);39-test('Does not print error, verbose "none", sync', testNoPrintError, nestedExecaSync);38+test('Does not print error, verbose "none"', testNoPrintError, runErrorSubprocessAsync);39+test('Does not print error, verbose "none", sync', testNoPrintError, runErrorSubprocessSync);40 41 const testPrintNoError = async (t, execaMethod) => {42 const {stderr} = await execaMethod('noop.js', [foobarString], {verbose: 'short'});43 t.is(getErrorLine(stderr), undefined);44 };45 46-test('Does not print error if none', testPrintNoError, nestedExecaAsync);47-test('Does not print error if none, sync', testPrintNoError, nestedExecaSync);46+test('Does not print error if none', testPrintNoError, parentExecaAsync);47+test('Does not print error if none, sync', testPrintNoError, parentExecaSync);48 49 const testPrintErrorEarly = async (t, execaMethod) => {50- const stderr = await runEarlyErrorSubprocess(t, execaMethod);50+ const stderr = await execaMethod(t);51 t.is(getErrorLine(stderr), `${testTimestamp} [0] × TypeError: The "cwd" option must be a string or a file URL: true.`);52 };53 54-test('Prints early validation error', testPrintErrorEarly, nestedExecaAsync);55-test('Prints early validation error, sync', testPrintErrorEarly, nestedExecaSync);54+test('Prints early validation error', testPrintErrorEarly, runEarlyErrorSubprocessAsync);55+test('Prints early validation error, sync', testPrintErrorEarly, runEarlyErrorSubprocessSync);56 57 test('Does not repeat stdout|stderr with error', async t => {58- const {stderr} = await t.throwsAsync(nestedExecaAsync('noop-fail.js', ['1', foobarString], {verbose: 'short'}));58+ const stderr = await runErrorSubprocessAsync(t, 'short');59 t.deepEqual(getErrorLines(stderr), [`${testTimestamp} [0] × Command failed with exit code 2: noop-fail.js 1 ${foobarString}`]);60 });61 62 test('Prints error differently if "reject" is false', async t => {63- const {stderr} = await nestedExecaAsync('noop-fail.js', ['1', foobarString], {verbose: 'short', reject: false});63+ const {stderr} = await parentExecaAsync('noop-fail.js', ['1', foobarString], {verbose: 'short', reject: false});64 t.deepEqual(getErrorLines(stderr), [`${testTimestamp} [0] ‼ Command failed with exit code 2: noop-fail.js 1 ${foobarString}`]);65 });66 67 const testPipeError = async (t, fixtureName, sourceVerbose, destinationVerbose) => {23 unmodified lines91 test('Prints neither errors piped with .pipe`command`', testPipeError, 'script', false, false);92 test('Prints neither errors piped with .pipe(subprocess)', testPipeError, 'subprocesses', false, false);93 94 test('Quotes spaces from error', async t => {95- const {stderr} = await t.throwsAsync(nestedExecaFail('noop-forever.js', ['foo bar'], {verbose: 'short'}));95+ const {stderr} = await t.throwsAsync(parentExecaFail('noop-forever.js', ['foo bar'], {verbose: 'short'}));96 t.deepEqual(getErrorLines(stderr), [97 `${testTimestamp} [0] × Command was killed with SIGTERM (Termination): noop-forever.js ${QUOTE}foo bar${QUOTE}`,98 `${testTimestamp} [0] × foo bar`,99 ]);100 });101 102 test('Quotes special punctuation from error', async t => {103- const {stderr} = await t.throwsAsync(nestedExecaFail('noop-forever.js', ['%'], {verbose: 'short'}));103+ const {stderr} = await t.throwsAsync(parentExecaFail('noop-forever.js', ['%'], {verbose: 'short'}));104 t.deepEqual(getErrorLines(stderr), [105 `${testTimestamp} [0] × Command was killed with SIGTERM (Termination): noop-forever.js ${QUOTE}%${QUOTE}`,106 `${testTimestamp} [0] × %`,107 ]);108 });109 110 test('Does not escape internal characters from error', async t => {111- const {stderr} = await t.throwsAsync(nestedExecaFail('noop-forever.js', ['ã'], {verbose: 'short'}));111+ const {stderr} = await t.throwsAsync(parentExecaFail('noop-forever.js', ['ã'], {verbose: 'short'}));112 t.deepEqual(getErrorLines(stderr), [113 `${testTimestamp} [0] × Command was killed with SIGTERM (Termination): noop-forever.js ${QUOTE}ã${QUOTE}`,114 `${testTimestamp} [0] × ã`,115 ]);116 });117 118 test('Escapes and strips color sequences from error', async t => {119- const {stderr} = await t.throwsAsync(nestedExecaFail('noop-forever.js', [red(foobarString)], {verbose: 'short'}, {env: {FORCE_COLOR: '1'}}));119+ const {stderr} = await t.throwsAsync(parentExecaFail('noop-forever.js', [red(foobarString)], {verbose: 'short'}, {env: {FORCE_COLOR: '1'}}));120 t.deepEqual(getErrorLines(stderr), [121 `${testTimestamp} [0] × Command was killed with SIGTERM (Termination): noop-forever.js ${QUOTE}\\u001b[31m${foobarString}\\u001b[39m${QUOTE}`,122 `${testTimestamp} [0] × ${foobarString}`,123 ]);124 });125 126 test('Escapes control characters from error', async t => {127- const {stderr} = await t.throwsAsync(nestedExecaFail('noop-forever.js', ['\u0001'], {verbose: 'short'}));127+ const {stderr} = await t.throwsAsync(parentExecaFail('noop-forever.js', ['\u0001'], {verbose: 'short'}));128 t.deepEqual(getErrorLines(stderr), [129 `${testTimestamp} [0] × Command was killed with SIGTERM (Termination): noop-forever.js ${QUOTE}\\u0001${QUOTE}`,130 `${testTimestamp} [0] × \\u0001`,131 ]);1 unmodified linemodified:test/verbose/info.js+4 added-5 removed
1 import test from 'ava';2 import {setFixtureDir} from '../helpers/fixtures-dir.js';3 import {execa, execaSync} from '../../index.js';4 import {foobarString} from '../helpers/input.js';5+import {parentExecaAsync, parentExecaSync} from '../helpers/nested.js';6 import {7 QUOTE,7- nestedExecaAsync,8- nestedExecaSync,8 getCommandLine,9 getOutputLine,10 getNormalizedLines,11 testTimestamp,16 unmodified lines28 test('Prints command, NODE_DEBUG=execa + "inherit"', testVerboseGeneral, execa);29 test('Prints command, NODE_DEBUG=execa + "inherit", sync', testVerboseGeneral, execaSync);30 31 test('NODE_DEBUG=execa changes verbose default value to "full"', async t => {33- const {stderr} = await nestedExecaAsync('noop.js', [foobarString], {}, {env: {NODE_DEBUG: 'execa'}});32+ const {stderr} = await parentExecaAsync('noop.js', [foobarString], {}, {env: {NODE_DEBUG: 'execa'}});33 t.is(getCommandLine(stderr), `${testTimestamp} [0] $ noop.js ${foobarString}`);34 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);35 });36 2 unmodified lines39 t.is(getCommandLine(stderr), `${testTimestamp} [0] $ noop.js ${foobarString}`);40 t.is(getOutputLine(stderr), undefined);41 };42 44-test('NODE_DEBUG=execa has lower priority', testDebugEnvPriority, nestedExecaAsync);45-test('NODE_DEBUG=execa has lower priority, sync', testDebugEnvPriority, nestedExecaSync);43+test('NODE_DEBUG=execa has lower priority', testDebugEnvPriority, parentExecaAsync);44+test('NODE_DEBUG=execa has lower priority, sync', testDebugEnvPriority, parentExecaSync);modified:test/verbose/log.js+8 added-8 removed
1 import {stripVTControlCharacters} from 'node:util';2 import test from 'ava';3 import {setFixtureDir} from '../helpers/fixtures-dir.js';4 import {foobarString} from '../helpers/input.js';5-import {nestedExecaAsync, nestedExecaSync} from '../helpers/verbose.js';5+import {parentExecaAsync, parentExecaSync} from '../helpers/nested.js';6 7 setFixtureDir();8 9 const testNoStdout = async (t, verbose, execaMethod) => {10 const {stdout} = await execaMethod('noop.js', [foobarString], {verbose, stdio: 'inherit'});11 t.is(stdout, foobarString);12 };13 14-test('Logs on stderr not stdout, verbose "none"', testNoStdout, 'none', nestedExecaAsync);15-test('Logs on stderr not stdout, verbose "short"', testNoStdout, 'short', nestedExecaAsync);16-test('Logs on stderr not stdout, verbose "full"', testNoStdout, 'full', nestedExecaAsync);17-test('Logs on stderr not stdout, verbose "none", sync', testNoStdout, 'none', nestedExecaSync);18-test('Logs on stderr not stdout, verbose "short", sync', testNoStdout, 'short', nestedExecaSync);19-test('Logs on stderr not stdout, verbose "full", sync', testNoStdout, 'full', nestedExecaSync);14+test('Logs on stderr not stdout, verbose "none"', testNoStdout, 'none', parentExecaAsync);15+test('Logs on stderr not stdout, verbose "short"', testNoStdout, 'short', parentExecaAsync);16+test('Logs on stderr not stdout, verbose "full"', testNoStdout, 'full', parentExecaAsync);17+test('Logs on stderr not stdout, verbose "none", sync', testNoStdout, 'none', parentExecaSync);18+test('Logs on stderr not stdout, verbose "short", sync', testNoStdout, 'short', parentExecaSync);19+test('Logs on stderr not stdout, verbose "full", sync', testNoStdout, 'full', parentExecaSync);20 21 const testColor = async (t, expectedResult, forceColor) => {22- const {stderr} = await nestedExecaAsync('noop.js', [foobarString], {verbose: 'short'}, {env: {FORCE_COLOR: forceColor}});22+ const {stderr} = await parentExecaAsync('noop.js', [foobarString], {verbose: 'short'}, {env: {FORCE_COLOR: forceColor}});23 t.is(stderr !== stripVTControlCharacters(stderr), expectedResult);24 };25 26 test('Prints with colors if supported', testColor, true, '1');1 unmodified linemodified:test/verbose/output.js+60 added-64 removed
1-import {once, on} from 'node:events';1+import {on} from 'node:events';2 import {rm, readFile} from 'node:fs/promises';3 import {inspect} from 'node:util';4 import test from 'ava';5 import tempfile from 'tempfile';2 unmodified lines8 import {setFixtureDir} from '../helpers/fixtures-dir.js';9 import {foobarString, foobarObject, foobarUppercase} from '../helpers/input.js';10 import {simpleFull, noNewlinesChunks} from '../helpers/lines.js';11 import {fullStdio} from '../helpers/stdio.js';12+import {nestedExecaAsync, parentExeca, parentExecaAsync, parentExecaSync} from '../helpers/nested.js';13 import {13- nestedExeca,14- nestedExecaAsync,15- nestedExecaSync,16- runErrorSubprocess,14+ runErrorSubprocessAsync,15+ runErrorSubprocessSync,16 getOutputLine,17 getOutputLines,18 testTimestamp,19 getVerboseOption,20 } from '../helpers/verbose.js';21 22 setFixtureDir();23 25-const nestedExecaDouble = nestedExeca.bind(undefined, 'nested-double.js');26-24 const testPrintOutput = async (t, fdNumber, execaMethod) => {25 const {stderr} = await execaMethod('noop-fd.js', [`${fdNumber}`, foobarString], {verbose: 'full'});26 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);27 };28 32-test('Prints stdout, verbose "full"', testPrintOutput, 1, nestedExecaAsync);33-test('Prints stdout, verbose "full", sync', testPrintOutput, 1, nestedExecaSync);34-test('Prints stderr, verbose "full"', testPrintOutput, 2, nestedExecaAsync);35-test('Prints stderr, verbose "full", sync', testPrintOutput, 2, nestedExecaSync);29+test('Prints stdout, verbose "full"', testPrintOutput, 1, parentExecaAsync);30+test('Prints stdout, verbose "full", sync', testPrintOutput, 1, parentExecaSync);31+test('Prints stderr, verbose "full"', testPrintOutput, 2, parentExecaAsync);32+test('Prints stderr, verbose "full", sync', testPrintOutput, 2, parentExecaSync);33 34 const testNoPrintOutput = async (t, verbose, fdNumber, execaMethod) => {35 const {stderr} = await execaMethod('noop-fd.js', [`${fdNumber}`, foobarString], {verbose, ...fullStdio});36 t.is(getOutputLine(stderr), undefined);37 };38 42-test('Does not print stdout, verbose "none"', testNoPrintOutput, 'none', 1, nestedExecaAsync);43-test('Does not print stdout, verbose "short"', testNoPrintOutput, 'short', 1, nestedExecaAsync);44-test('Does not print stdout, verbose "none", sync', testNoPrintOutput, 'none', 1, nestedExecaSync);45-test('Does not print stdout, verbose "short", sync', testNoPrintOutput, 'short', 1, nestedExecaSync);46-test('Does not print stderr, verbose "none"', testNoPrintOutput, 'none', 2, nestedExecaAsync);47-test('Does not print stderr, verbose "short"', testNoPrintOutput, 'short', 2, nestedExecaAsync);48-test('Does not print stderr, verbose "none", sync', testNoPrintOutput, 'none', 2, nestedExecaSync);49-test('Does not print stderr, verbose "short", sync', testNoPrintOutput, 'short', 2, nestedExecaSync);50-test('Does not print stdio[*], verbose "none"', testNoPrintOutput, 'none', 3, nestedExecaAsync);51-test('Does not print stdio[*], verbose "short"', testNoPrintOutput, 'short', 3, nestedExecaAsync);52-test('Does not print stdio[*], verbose "full"', testNoPrintOutput, 'full', 3, nestedExecaAsync);53-test('Does not print stdio[*], verbose "none", sync', testNoPrintOutput, 'none', 3, nestedExecaSync);54-test('Does not print stdio[*], verbose "short", sync', testNoPrintOutput, 'short', 3, nestedExecaSync);55-test('Does not print stdio[*], verbose "full", sync', testNoPrintOutput, 'full', 3, nestedExecaSync);39+test('Does not print stdout, verbose "none"', testNoPrintOutput, 'none', 1, parentExecaAsync);40+test('Does not print stdout, verbose "short"', testNoPrintOutput, 'short', 1, parentExecaAsync);41+test('Does not print stdout, verbose "none", sync', testNoPrintOutput, 'none', 1, parentExecaSync);42+test('Does not print stdout, verbose "short", sync', testNoPrintOutput, 'short', 1, parentExecaSync);43+test('Does not print stderr, verbose "none"', testNoPrintOutput, 'none', 2, parentExecaAsync);44+test('Does not print stderr, verbose "short"', testNoPrintOutput, 'short', 2, parentExecaAsync);45+test('Does not print stderr, verbose "none", sync', testNoPrintOutput, 'none', 2, parentExecaSync);46+test('Does not print stderr, verbose "short", sync', testNoPrintOutput, 'short', 2, parentExecaSync);47+test('Does not print stdio[*], verbose "none"', testNoPrintOutput, 'none', 3, parentExecaAsync);48+test('Does not print stdio[*], verbose "short"', testNoPrintOutput, 'short', 3, parentExecaAsync);49+test('Does not print stdio[*], verbose "full"', testNoPrintOutput, 'full', 3, parentExecaAsync);50+test('Does not print stdio[*], verbose "none", sync', testNoPrintOutput, 'none', 3, parentExecaSync);51+test('Does not print stdio[*], verbose "short", sync', testNoPrintOutput, 'short', 3, parentExecaSync);52+test('Does not print stdio[*], verbose "full", sync', testNoPrintOutput, 'full', 3, parentExecaSync);53 54 const testPrintError = async (t, execaMethod) => {58- const stderr = await runErrorSubprocess(t, 'full', execaMethod);55+ const stderr = await execaMethod(t, 'full');56 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);57 };58 62-test('Prints stdout after errors', testPrintError, nestedExecaAsync);63-test('Prints stdout after errors, sync', testPrintError, nestedExecaSync);59+test('Prints stdout after errors', testPrintError, runErrorSubprocessAsync);60+test('Prints stdout after errors, sync', testPrintError, runErrorSubprocessSync);61 62 const testPipeOutput = async (t, fixtureName, sourceVerbose, destinationVerbose) => {63 const {stderr} = await execa(`nested-pipe-${fixtureName}.js`, [64 JSON.stringify(getVerboseOption(sourceVerbose, 'full')),23 unmodified lines88 test('Does not print stdout if neither verbose with .pipe`command`', testPipeOutput, 'script', false, false);89 test('Does not print stdout if neither verbose with .pipe(subprocess)', testPipeOutput, 'subprocesses', false, false);90 91 test('Does not quote spaces from stdout', async t => {95- const {stderr} = await nestedExecaAsync('noop.js', ['foo bar'], {verbose: 'full'});92+ const {stderr} = await parentExecaAsync('noop.js', ['foo bar'], {verbose: 'full'});93 t.is(getOutputLine(stderr), `${testTimestamp} [0] foo bar`);94 });95 96 test('Does not quote special punctuation from stdout', async t => {100- const {stderr} = await nestedExecaAsync('noop.js', ['%'], {verbose: 'full'});97+ const {stderr} = await parentExecaAsync('noop.js', ['%'], {verbose: 'full'});98 t.is(getOutputLine(stderr), `${testTimestamp} [0] %`);99 });100 101 test('Does not escape internal characters from stdout', async t => {105- const {stderr} = await nestedExecaAsync('noop.js', ['ã'], {verbose: 'full'});102+ const {stderr} = await parentExecaAsync('noop.js', ['ã'], {verbose: 'full'});103 t.is(getOutputLine(stderr), `${testTimestamp} [0] ã`);104 });105 106 test('Strips color sequences from stdout', async t => {110- const {stderr} = await nestedExecaAsync('noop.js', [red(foobarString)], {verbose: 'full'}, {env: {FORCE_COLOR: '1'}});107+ const {stderr} = await parentExecaAsync('noop.js', [red(foobarString)], {verbose: 'full'}, {env: {FORCE_COLOR: '1'}});108 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);109 });110 111 test('Escapes control characters from stdout', async t => {115- const {stderr} = await nestedExecaAsync('noop.js', ['\u0001'], {verbose: 'full'});112+ const {stderr} = await parentExecaAsync('noop.js', ['\u0001'], {verbose: 'full'});113 t.is(getOutputLine(stderr), `${testTimestamp} [0] \\u0001`);114 });115 116 const testStdioSame = async (t, fdNumber) => {120- const subprocess = execa('nested-send.js', [JSON.stringify({verbose: true}), 'noop-fd.js', `${fdNumber}`, foobarString], {ipc: true});121- const [[{stdio}]] = await Promise.all([once(subprocess, 'message'), subprocess]);117+ const {stdio} = await nestedExecaAsync('noop-fd.js', [`${fdNumber}`, foobarString], {verbose: true});118 t.is(stdio[fdNumber], foobarString);119 };120 121 test('Does not change subprocess.stdout', testStdioSame, 1);3 unmodified lines125 const {stderr} = await execaMethod('noop-fd.js', ['1', simpleFull], {verbose: 'full', lines: true});126 t.deepEqual(getOutputLines(stderr), noNewlinesChunks.map(line => `${testTimestamp} [0] ${line}`));127 };128 133-test('Prints stdout, "lines: true"', testLines, false, nestedExecaAsync);134-test('Prints stdout, "lines: true", stripFinalNewline', testLines, true, nestedExecaAsync);135-test('Prints stdout, "lines: true", sync', testLines, false, nestedExecaSync);136-test('Prints stdout, "lines: true", stripFinalNewline, sync', testLines, true, nestedExecaSync);129+test('Prints stdout, "lines: true"', testLines, false, parentExecaAsync);130+test('Prints stdout, "lines: true", stripFinalNewline', testLines, true, parentExecaAsync);131+test('Prints stdout, "lines: true", sync', testLines, false, parentExecaSync);132+test('Prints stdout, "lines: true", stripFinalNewline, sync', testLines, true, parentExecaSync);133 134 const testOnlyTransforms = async (t, type, isSync) => {139- const {stderr} = await nestedExeca('nested-transform.js', 'noop.js', [foobarString], {verbose: 'full', type, isSync});135+ const {stderr} = await parentExeca('nested-transform.js', 'noop.js', [foobarString], {verbose: 'full', type, isSync});136 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString.toUpperCase()}`);137 };138 139 test('Prints stdout with only transforms', testOnlyTransforms, 'generator', false);140 test('Prints stdout with only transforms, sync', testOnlyTransforms, 'generator', true);141 test('Prints stdout with only duplexes', testOnlyTransforms, 'duplex', false);142 143 const testObjectMode = async (t, isSync) => {148- const {stderr} = await nestedExeca('nested-transform.js', 'noop.js', {verbose: 'full', transformName: 'object', isSync});144+ const {stderr} = await parentExeca('nested-transform.js', 'noop.js', {verbose: 'full', transformName: 'object', isSync});145 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${inspect(foobarObject)}`);146 };147 148 test('Prints stdout with object transforms', testObjectMode, false);149 test('Prints stdout with object transforms, sync', testObjectMode, true);150 151 const testBigArray = async (t, isSync) => {156- const {stderr} = await nestedExeca('nested-transform.js', 'noop.js', {verbose: 'full', transformName: 'bigArray', isSync});152+ const {stderr} = await parentExeca('nested-transform.js', 'noop.js', {verbose: 'full', transformName: 'bigArray', isSync});153 const lines = getOutputLines(stderr);154 t.is(lines[0], `${testTimestamp} [0] [`);155 t.true(lines[1].startsWith(`${testTimestamp} [0] 0, 1,`));156 t.is(lines.at(-1), `${testTimestamp} [0] ]`);2 unmodified lines159 test('Prints stdout with big object transforms', testBigArray, false);160 test('Prints stdout with big object transforms, sync', testBigArray, true);161 162 const testObjectModeString = async (t, isSync) => {167- const {stderr} = await nestedExeca('nested-transform.js', 'noop.js', {verbose: 'full', transformName: 'stringObject', isSync});163+ const {stderr} = await parentExeca('nested-transform.js', 'noop.js', {verbose: 'full', transformName: 'stringObject', isSync});164 t.deepEqual(getOutputLines(stderr), noNewlinesChunks.map(line => `${testTimestamp} [0] ${line}`));165 };166 167 test('Prints stdout with string transforms in objectMode', testObjectModeString, false);168 test('Prints stdout with string transforms in objectMode, sync', testObjectModeString, true);169 170 test('Prints stdout one line at a time', async t => {175- const subprocess = nestedExecaAsync('noop-progressive.js', [foobarString], {verbose: 'full'});171+ const subprocess = parentExecaAsync('noop-progressive.js', [foobarString], {verbose: 'full'});172 173 for await (const chunk of on(subprocess.stderr, 'data')) {174 const outputLine = getOutputLine(chunk.toString().trim());175 if (outputLine !== undefined) {4 unmodified lines180 181 await subprocess;182 });183 188-test('Prints stdout progressively, interleaved', async t => {189- const subprocess = nestedExecaDouble('noop-repeat.js', ['1', `${foobarString}\n`], {verbose: 'full'});184+test.serial('Prints stdout progressively, interleaved', async t => {185+ const subprocess = parentExeca('nested-double.js', 'noop-repeat.js', ['1', `${foobarString}\n`], {verbose: 'full'});186 187 let firstSubprocessPrinted = false;188 let secondSubprocessPrinted = false;189 for await (const chunk of on(subprocess.stderr, 'data')) {23 unmodified lines213 const {stderr} = await execaMethod('noop-fd.js', ['1', '\n'], {verbose: 'full'});214 t.deepEqual(getOutputLines(stderr), [`${testTimestamp} [0] `]);215 };216 221-test('Prints stdout, single newline', testSingleNewline, nestedExecaAsync);222-test('Prints stdout, single newline, sync', testSingleNewline, nestedExecaSync);217+test('Prints stdout, single newline', testSingleNewline, parentExecaAsync);218+test('Prints stdout, single newline, sync', testSingleNewline, parentExecaSync);219 220 const testUtf16 = async (t, isSync) => {225- const {stderr} = await nestedExeca('nested-input.js', 'stdin.js', [`${isSync}`], {verbose: 'full', encoding: 'utf16le'});221+ const {stderr} = await parentExeca('nested-input.js', 'stdin.js', [`${isSync}`], {verbose: 'full', encoding: 'utf16le'});222 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);223 };224 225 test('Can use encoding UTF16, verbose "full"', testUtf16, false);226 test('Can use encoding UTF16, verbose "full", sync', testUtf16, true);227 228 const testNoOutputOptions = async (t, fixtureName, options = {}) => {233- const {stderr} = await nestedExeca(fixtureName, 'noop.js', [foobarString], {verbose: 'full', ...options});229+ const {stderr} = await parentExeca(fixtureName, 'noop.js', [foobarString], {verbose: 'full', ...options});230 t.is(getOutputLine(stderr), undefined);231 };232 233 test('Does not print stdout, encoding "buffer"', testNoOutputOptions, 'nested.js', {encoding: 'buffer'});14 unmodified lines248 test('Does not print stdout, stdout 1, sync', testNoOutputOptions, 'nested-sync.js', {stdout: 1});249 250 const testStdoutFile = async (t, fixtureName, getStdout) => {251 const file = tempfile();256- const {stderr} = await nestedExeca(fixtureName, 'noop.js', [foobarString], {verbose: 'full', stdout: getStdout(file)});252+ const {stderr} = await parentExeca(fixtureName, 'noop.js', [foobarString], {verbose: 'full', stdout: getStdout(file)});253 t.is(getOutputLine(stderr), undefined);254 const contents = await readFile(file, 'utf8');255 t.is(contents.trim(), foobarString);256 await rm(file);7 unmodified lines264 const {stderr} = await execaMethod('noop.js', [foobarString], {verbose: 'full', ...options});265 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);266 };267 272-test('Prints stdout, stdout "pipe"', testPrintOutputOptions, {stdout: 'pipe'}, nestedExecaAsync);273-test('Prints stdout, stdout "overlapped"', testPrintOutputOptions, {stdout: 'overlapped'}, nestedExecaAsync);274-test('Prints stdout, stdout null', testPrintOutputOptions, {stdout: null}, nestedExecaAsync);275-test('Prints stdout, stdout ["pipe"]', testPrintOutputOptions, {stdout: ['pipe']}, nestedExecaAsync);276-test('Prints stdout, stdout "pipe", sync', testPrintOutputOptions, {stdout: 'pipe'}, nestedExecaSync);277-test('Prints stdout, stdout null, sync', testPrintOutputOptions, {stdout: null}, nestedExecaSync);278-test('Prints stdout, stdout ["pipe"], sync', testPrintOutputOptions, {stdout: ['pipe']}, nestedExecaSync);268+test('Prints stdout, stdout "pipe"', testPrintOutputOptions, {stdout: 'pipe'}, parentExecaAsync);269+test('Prints stdout, stdout "overlapped"', testPrintOutputOptions, {stdout: 'overlapped'}, parentExecaAsync);270+test('Prints stdout, stdout null', testPrintOutputOptions, {stdout: null}, parentExecaAsync);271+test('Prints stdout, stdout ["pipe"]', testPrintOutputOptions, {stdout: ['pipe']}, parentExecaAsync);272+test('Prints stdout, stdout "pipe", sync', testPrintOutputOptions, {stdout: 'pipe'}, parentExecaSync);273+test('Prints stdout, stdout null, sync', testPrintOutputOptions, {stdout: null}, parentExecaSync);274+test('Prints stdout, stdout ["pipe"], sync', testPrintOutputOptions, {stdout: ['pipe']}, parentExecaSync);275 276 const testPrintOutputNoBuffer = async (t, execaMethod) => {277 const {stderr} = await execaMethod('noop.js', [foobarString], {verbose: 'full', buffer: false});278 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);279 };280 285-test('Prints stdout, buffer: false', testPrintOutputNoBuffer, nestedExecaAsync);286-test('Prints stdout, buffer: false, sync', testPrintOutputNoBuffer, nestedExecaSync);281+test('Prints stdout, buffer: false', testPrintOutputNoBuffer, parentExecaAsync);282+test('Prints stdout, buffer: false, sync', testPrintOutputNoBuffer, parentExecaSync);283 284 const testPrintOutputNoBufferTransform = async (t, isSync) => {289- const {stderr} = await nestedExeca('nested-transform.js', 'noop.js', [foobarString], {verbose: 'full', buffer: false, type: 'generator', isSync});285+ const {stderr} = await parentExeca('nested-transform.js', 'noop.js', [foobarString], {verbose: 'full', buffer: false, type: 'generator', isSync});286 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarUppercase}`);287 };288 289 test('Prints stdout, buffer: false, transform', testPrintOutputNoBufferTransform, false);290 test('Prints stdout, buffer: false, transform, sync', testPrintOutputNoBufferTransform, true);291 292 const testPrintOutputFixture = async (t, fixtureName, ...args) => {297- const {stderr} = await nestedExeca(fixtureName, 'noop.js', [foobarString, ...args], {verbose: 'full'});293+ const {stderr} = await parentExeca(fixtureName, 'noop.js', [foobarString, ...args], {verbose: 'full'});294 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);295 };296 297 test('Prints stdout, .pipe(stream) + .unpipe()', testPrintOutputFixture, 'nested-pipe-stream.js', 'true');3 unmodified lines301 const {stderr} = await execaMethod('noop-132.js', {verbose: 'full'});302 t.deepEqual(getOutputLines(stderr), expectedLines.map(line => `${testTimestamp} [0] ${line}`));303 };304 309-test('Prints stdout + stderr interleaved', testInterleaved, [1, 2, 3], nestedExecaAsync);310-test('Prints stdout + stderr not interleaved, sync', testInterleaved, [1, 3, 2], nestedExecaSync);305+test('Prints stdout + stderr interleaved', testInterleaved, [1, 2, 3], parentExecaAsync);306+test('Prints stdout + stderr not interleaved, sync', testInterleaved, [1, 3, 2], parentExecaSync);modified:test/verbose/start.js+24 added-21 removed
1 unmodified line2 import {red} from 'yoctocolors';3 import {execa} from '../../index.js';4 import {setFixtureDir} from '../helpers/fixtures-dir.js';5 import {foobarString} from '../helpers/input.js';6+import {parentExecaAsync, parentExecaSync, parentWorker} from '../helpers/nested.js';7 import {8 QUOTE,8- nestedExecaAsync,9- nestedExecaSync,10- runErrorSubprocess,11- runEarlyErrorSubprocess,9+ runErrorSubprocessAsync,10+ runErrorSubprocessSync,11+ runEarlyErrorSubprocessAsync,12+ runEarlyErrorSubprocessSync,13 getCommandLine,14 getCommandLines,15 testTimestamp,16 getVerboseOption,5 unmodified lines22 const {stderr} = await execaMethod('noop.js', [foobarString], {verbose});23 t.is(getCommandLine(stderr), `${testTimestamp} [0] $ noop.js ${foobarString}`);24 };25 25-test('Prints command, verbose "short"', testPrintCommand, 'short', nestedExecaAsync);26-test('Prints command, verbose "full"', testPrintCommand, 'full', nestedExecaAsync);27-test('Prints command, verbose "short", sync', testPrintCommand, 'short', nestedExecaSync);28-test('Prints command, verbose "full", sync', testPrintCommand, 'full', nestedExecaSync);26+test('Prints command, verbose "short"', testPrintCommand, 'short', parentExecaAsync);27+test('Prints command, verbose "full"', testPrintCommand, 'full', parentExecaAsync);28+test('Prints command, verbose "short", sync', testPrintCommand, 'short', parentExecaSync);29+test('Prints command, verbose "full", sync', testPrintCommand, 'full', parentExecaSync);30+test('Prints command, verbose "short", worker', testPrintCommand, 'short', parentWorker);31+test('Prints command, verbose "full", work', testPrintCommand, 'full', parentWorker);32 33 const testNoPrintCommand = async (t, execaMethod) => {34 const {stderr} = await execaMethod('noop.js', [foobarString], {verbose: 'none'});35 t.is(stderr, '');36 };37 35-test('Does not print command, verbose "none"', testNoPrintCommand, nestedExecaAsync);36-test('Does not print command, verbose "none", sync', testNoPrintCommand, nestedExecaSync);38+test('Does not print command, verbose "none"', testNoPrintCommand, parentExecaAsync);39+test('Does not print command, verbose "none", sync', testNoPrintCommand, parentExecaSync);40 41 const testPrintCommandError = async (t, execaMethod) => {39- const stderr = await runErrorSubprocess(t, 'short', execaMethod);42+ const stderr = await execaMethod(t, 'short');43 t.is(getCommandLine(stderr), `${testTimestamp} [0] $ noop-fail.js 1 ${foobarString}`);44 };45 43-test('Prints command after errors', testPrintCommandError, nestedExecaAsync);44-test('Prints command after errors, sync', testPrintCommandError, nestedExecaSync);46+test('Prints command after errors', testPrintCommandError, runErrorSubprocessAsync);47+test('Prints command after errors, sync', testPrintCommandError, runErrorSubprocessSync);48 49 const testPrintCommandEarly = async (t, execaMethod) => {47- const stderr = await runEarlyErrorSubprocess(t, execaMethod);50+ const stderr = await execaMethod(t);51 t.is(getCommandLine(stderr), `${testTimestamp} [0] $ noop.js ${foobarString}`);52 };53 51-test('Prints command before early validation errors', testPrintCommandEarly, nestedExecaAsync);52-test('Prints command before early validation errors, sync', testPrintCommandEarly, nestedExecaSync);54+test('Prints command before early validation errors', testPrintCommandEarly, runEarlyErrorSubprocessAsync);55+test('Prints command before early validation errors, sync', testPrintCommandEarly, runEarlyErrorSubprocessSync);56 57 const testPipeCommand = async (t, fixtureName, sourceVerbose, destinationVerbose) => {58 const {stderr} = await execa(`nested-pipe-${fixtureName}.js`, [59 JSON.stringify(getVerboseOption(sourceVerbose)),21 unmodified lines81 test('Prints neither commands piped with .pipe`command`', testPipeCommand, 'script', false, false);82 test('Prints neither commands piped with .pipe(subprocess)', testPipeCommand, 'subprocesses', false, false);83 84 test('Quotes spaces from command', async t => {82- const {stderr} = await nestedExecaAsync('noop.js', ['foo bar'], {verbose: 'short'});85+ const {stderr} = await parentExecaAsync('noop.js', ['foo bar'], {verbose: 'short'});86 t.is(getCommandLine(stderr), `${testTimestamp} [0] $ noop.js ${QUOTE}foo bar${QUOTE}`);87 });88 89 test('Quotes special punctuation from command', async t => {87- const {stderr} = await nestedExecaAsync('noop.js', ['%'], {verbose: 'short'});90+ const {stderr} = await parentExecaAsync('noop.js', ['%'], {verbose: 'short'});91 t.is(getCommandLine(stderr), `${testTimestamp} [0] $ noop.js ${QUOTE}%${QUOTE}`);92 });93 94 test('Does not escape internal characters from command', async t => {92- const {stderr} = await nestedExecaAsync('noop.js', ['ã'], {verbose: 'short'});95+ const {stderr} = await parentExecaAsync('noop.js', ['ã'], {verbose: 'short'});96 t.is(getCommandLine(stderr), `${testTimestamp} [0] $ noop.js ${QUOTE}ã${QUOTE}`);97 });98 99 test('Escapes color sequences from command', async t => {97- const {stderr} = await nestedExecaAsync('noop.js', [red(foobarString)], {verbose: 'short'}, {env: {FORCE_COLOR: '1'}});100+ const {stderr} = await parentExecaAsync('noop.js', [red(foobarString)], {verbose: 'short'}, {env: {FORCE_COLOR: '1'}});101 t.true(getCommandLine(stderr).includes(`${QUOTE}\\u001b[31m${foobarString}\\u001b[39m${QUOTE}`));102 });103 104 test('Escapes control characters from command', async t => {102- const {stderr} = await nestedExecaAsync('noop.js', ['\u0001'], {verbose: 'short'});105+ const {stderr} = await parentExecaAsync('noop.js', ['\u0001'], {verbose: 'short'});106 t.is(getCommandLine(stderr), `${testTimestamp} [0] $ noop.js ${QUOTE}\\u0001${QUOTE}`);107 });