Skip to content
Myr

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

15 files+291 added−210 removed

modified:lib/verbose/log.js+3 added-2 removed
modified:test/exit/cleanup.js+13 added-6 removed
deleted:test/fixtures/nested-send.js-7 removed
modified:test/fixtures/nested-sync.js+6 added-1 removed
modified:test/fixtures/nested.js+6 added-1 removed
added:test/fixtures/worker.js+15 added
added:test/helpers/nested.js+49 added
modified:test/helpers/verbose.js+23 added-16 removed
1import {platform} from 'node:process';2import {stripVTControlCharacters} from 'node:util';3import {replaceSymbols} from 'figures';4import {execa} from '../../index.js';4import {foobarString} from './input.js';5import {nestedExecaAsync, nestedExecaSync} from './nested.js';67const isWindows = platform === 'win32';8export const QUOTE = isWindows ? '"' : '\'';910// eslint-disable-next-line max-params11export 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};10const 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 }1716export const nestedExecaAsync = nestedExeca.bind(undefined, 'nested.js');17export const nestedExecaSync = nestedExeca.bind(undefined, 'nested-sync.js');1819export 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};2025export const runWarningSubprocess = async (t, execaMethod) => {26 const {stderr} = await execaMethod('noop-fail.js', ['1', foobarString], {verbose: 'short', reject: false});21export 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;26 t.true(stderr.includes('exit code 2'));27 return stderr;28};2931export const runEarlyErrorSubprocess = async (t, execaMethod) => {32 const {stderr} = await t.throwsAsync(execaMethod('noop.js', [foobarString], {verbose: 'short', cwd: true}));30export 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;37 t.true(stderr.includes('The "cwd" option must'));38 return stderr;39};4041export const runEarlyErrorSubprocessAsync = runEarlyErrorSubprocess.bind(undefined, nestedExecaAsync);42export const runEarlyErrorSubprocessSync = runEarlyErrorSubprocess.bind(undefined, nestedExecaSync);4344export const getCommandLine = stderr => getCommandLines(stderr)[0];45export const getCommandLines = stderr => getNormalizedLines(stderr).filter(line => isCommandLine(line));46const isCommandLine = line => line.includes(' $ ') || line.includes(' | ');47export const getOutputLine = stderr => getOutputLines(stderr)[0];
17 unmodified lines
modified:test/stdio/native.js+31 added-32 removed
4 unmodified lines
5import {execa, execaSync} from '../../index.js';6import {getStdio, fullStdio} from '../helpers/stdio.js';7import {setFixtureDir} from '../helpers/fixtures-dir.js';8import {foobarString} from '../helpers/input.js';9import {parentExecaAsync, parentExecaSync} from '../helpers/nested.js';1011setFixtureDir();1213const isLinux = platform === 'linux';14const isWindows = platform === 'win32';1515const getFixtureName = isSync => isSync ? 'nested-sync.js' : 'nested.js';1616// eslint-disable-next-line max-params17const testRedirect = async (t, stdioOption, fdNumber, isInput, isSync) => {18 const {fixtureName, ...options} = isInput19 ? {fixtureName: 'stdin-fd.js', input: foobarString}
109 unmodified lines
129test('stderr can be [process.stderr, "pipe"], encoding "buffer", sync', testInheritStdioOutput, 2, 1, ['stderr', 'pipe'], true, 'buffer');130test('stdio[*] output can be ["inherit", "pipe"], encoding "buffer", sync', testInheritStdioOutput, 3, 1, ['inherit', 'pipe'], true, 'buffer');131test('stdio[*] output can be [3, "pipe"], encoding "buffer", sync', testInheritStdioOutput, 3, 1, [3, 'pipe'], true, 'buffer');132134const testFd3InheritOutput = async (t, stdioOption, isSync) => {135 const {stdio} = await execa(getFixtureName(isSync), [JSON.stringify(getStdio(3, stdioOption)), 'noop-fd.js', '3', foobarString], fullStdio);133const 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};137139test('stdio[*] output can use "inherit"', testFd3InheritOutput, 'inherit', false);140test('stdio[*] output can use ["inherit"]', testFd3InheritOutput, ['inherit'], false);141test('stdio[*] output can use "inherit", sync', testFd3InheritOutput, 'inherit', true);142test('stdio[*] output can use ["inherit"], sync', testFd3InheritOutput, ['inherit'], true);138test('stdio[*] output can use "inherit"', testFd3InheritOutput, 'inherit', parentExecaAsync);139test('stdio[*] output can use ["inherit"]', testFd3InheritOutput, ['inherit'], parentExecaAsync);140test('stdio[*] output can use "inherit", sync', testFd3InheritOutput, 'inherit', parentExecaSync);141test('stdio[*] output can use ["inherit"], sync', testFd3InheritOutput, ['inherit'], parentExecaSync);142144const testInheritNoBuffer = async (t, stdioOption, isSync) => {143const 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};149151test('stdin can be ["inherit", "pipe"], buffer: false', testInheritNoBuffer, ['inherit', 'pipe'], false);152test('stdin can be [0, "pipe"], buffer: false', testInheritNoBuffer, [0, 'pipe'], false);153test.serial('stdin can be ["inherit", "pipe"], buffer: false, sync', testInheritNoBuffer, ['inherit', 'pipe'], true);154test.serial('stdin can be [0, "pipe"], buffer: false, sync', testInheritNoBuffer, [0, 'pipe'], true);150test('stdin can be ["inherit", "pipe"], buffer: false', testInheritNoBuffer, ['inherit', 'pipe'], parentExecaAsync);151test('stdin can be [0, "pipe"], buffer: false', testInheritNoBuffer, [0, 'pipe'], parentExecaAsync);152test.serial('stdin can be ["inherit", "pipe"], buffer: false, sync', testInheritNoBuffer, ['inherit', 'pipe'], parentExecaSync);153test.serial('stdin can be [0, "pipe"], buffer: false, sync', testInheritNoBuffer, [0, 'pipe'], parentExecaSync);154155if (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 };160162 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}178179const testOverflowStreamArray = (t, fdNumber, stdioOption) => {180 t.throws(() => {
54 unmodified lines
modified:test/verbose/complete.js+23 added-21 removed
1 unmodified line
2import test from 'ava';3import {execa} from '../../index.js';4import {setFixtureDir} from '../helpers/fixtures-dir.js';5import {foobarString} from '../helpers/input.js';6import {parentExecaAsync, parentExecaSync} from '../helpers/nested.js';7import {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 lines
23 const {stderr} = await execaMethod('noop.js', [foobarString], {verbose});24 t.is(getCompletionLine(stderr), `${testTimestamp} [0] √ (done in 0ms)`);25};2625test('Prints completion, verbose "short"', testPrintCompletion, 'short', nestedExecaAsync);26test('Prints completion, verbose "full"', testPrintCompletion, 'full', nestedExecaAsync);27test('Prints completion, verbose "short", sync', testPrintCompletion, 'short', nestedExecaSync);28test('Prints completion, verbose "full", sync', testPrintCompletion, 'full', nestedExecaSync);27test('Prints completion, verbose "short"', testPrintCompletion, 'short', parentExecaAsync);28test('Prints completion, verbose "full"', testPrintCompletion, 'full', parentExecaAsync);29test('Prints completion, verbose "short", sync', testPrintCompletion, 'short', parentExecaSync);30test('Prints completion, verbose "full", sync', testPrintCompletion, 'full', parentExecaSync);3132const testNoPrintCompletion = async (t, execaMethod) => {33 const {stderr} = await execaMethod('noop.js', [foobarString], {verbose: 'none'});34 t.is(stderr, '');35};3635test('Does not print completion, verbose "none"', testNoPrintCompletion, nestedExecaAsync);36test('Does not print completion, verbose "none", sync', testNoPrintCompletion, nestedExecaSync);37test('Does not print completion, verbose "none"', testNoPrintCompletion, parentExecaAsync);38test('Does not print completion, verbose "none", sync', testNoPrintCompletion, parentExecaSync);3940const 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};4443test('Prints completion after errors', testPrintCompletionError, nestedExecaAsync);44test('Prints completion after errors, sync', testPrintCompletionError, nestedExecaSync);45test('Prints completion after errors', testPrintCompletionError, runErrorSubprocessAsync);46test('Prints completion after errors, sync', testPrintCompletionError, runErrorSubprocessSync);4748const 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};5251test('Prints completion after errors, "reject" false', testPrintCompletionWarning, nestedExecaAsync);52test('Prints completion after errors, "reject" false, sync', testPrintCompletionWarning, nestedExecaSync);53test('Prints completion after errors, "reject" false', testPrintCompletionWarning, runWarningSubprocessAsync);54test('Prints completion after errors, "reject" false, sync', testPrintCompletionWarning, runWarningSubprocessSync);5556const 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};6059test('Prints completion after early validation errors', testPrintCompletionEarly, nestedExecaAsync);60test('Prints completion after early validation errors, sync', testPrintCompletionEarly, nestedExecaSync);61test('Prints completion after early validation errors', testPrintCompletionEarly, runEarlyErrorSubprocessAsync);62test('Prints completion after early validation errors, sync', testPrintCompletionEarly, runEarlyErrorSubprocessSync);6364test.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});6869const testPipeDuration = async (t, fixtureName, sourceVerbose, destinationVerbose) => {
25 unmodified lines
modified:test/verbose/error.js+26 added-26 removed
1 unmodified line
2import {red} from 'yoctocolors';3import {execa} from '../../index.js';4import {setFixtureDir} from '../helpers/fixtures-dir.js';5import {foobarString} from '../helpers/input.js';6import {parentExeca, parentExecaAsync, parentExecaSync} from '../helpers/nested.js';7import {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';1819setFixtureDir();2020const nestedExecaFail = nestedExeca.bind(undefined, 'nested-fail.js');21const parentExecaFail = parentExeca.bind(undefined, 'nested-fail.js');2223const 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};2727test('Prints error, verbose "short"', testPrintError, 'short', nestedExecaAsync);28test('Prints error, verbose "full"', testPrintError, 'full', nestedExecaAsync);29test('Prints error, verbose "short", sync', testPrintError, 'short', nestedExecaSync);30test('Prints error, verbose "full", sync', testPrintError, 'full', nestedExecaSync);28test('Prints error, verbose "short"', testPrintError, 'short', runErrorSubprocessAsync);29test('Prints error, verbose "full"', testPrintError, 'full', runErrorSubprocessAsync);30test('Prints error, verbose "short", sync', testPrintError, 'short', runErrorSubprocessSync);31test('Prints error, verbose "full", sync', testPrintError, 'full', runErrorSubprocessSync);3233const 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};3738test('Does not print error, verbose "none"', testNoPrintError, nestedExecaAsync);39test('Does not print error, verbose "none", sync', testNoPrintError, nestedExecaSync);38test('Does not print error, verbose "none"', testNoPrintError, runErrorSubprocessAsync);39test('Does not print error, verbose "none", sync', testNoPrintError, runErrorSubprocessSync);4041const testPrintNoError = async (t, execaMethod) => {42 const {stderr} = await execaMethod('noop.js', [foobarString], {verbose: 'short'});43 t.is(getErrorLine(stderr), undefined);44};4546test('Does not print error if none', testPrintNoError, nestedExecaAsync);47test('Does not print error if none, sync', testPrintNoError, nestedExecaSync);46test('Does not print error if none', testPrintNoError, parentExecaAsync);47test('Does not print error if none, sync', testPrintNoError, parentExecaSync);4849const 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};5354test('Prints early validation error', testPrintErrorEarly, nestedExecaAsync);55test('Prints early validation error, sync', testPrintErrorEarly, nestedExecaSync);54test('Prints early validation error', testPrintErrorEarly, runEarlyErrorSubprocessAsync);55test('Prints early validation error, sync', testPrintErrorEarly, runEarlyErrorSubprocessSync);5657test('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});6162test('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});6667const testPipeError = async (t, fixtureName, sourceVerbose, destinationVerbose) => {
23 unmodified lines
91test('Prints neither errors piped with .pipe`command`', testPipeError, 'script', false, false);92test('Prints neither errors piped with .pipe(subprocess)', testPipeError, 'subprocesses', false, false);9394test('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});101102test('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});109110test('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});117118test('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});125126test('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 line
modified:test/verbose/info.js+4 added-5 removed
1import test from 'ava';2import {setFixtureDir} from '../helpers/fixtures-dir.js';3import {execa, execaSync} from '../../index.js';4import {foobarString} from '../helpers/input.js';5import {parentExecaAsync, parentExecaSync} from '../helpers/nested.js';6import {7 QUOTE,7 nestedExecaAsync,8 nestedExecaSync,8 getCommandLine,9 getOutputLine,10 getNormalizedLines,11 testTimestamp,
16 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 => {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 lines
39 t.is(getCommandLine(stderr), `${testTimestamp} [0] $ noop.js ${foobarString}`);40 t.is(getOutputLine(stderr), undefined);41};4244test('NODE_DEBUG=execa has lower priority', testDebugEnvPriority, nestedExecaAsync);45test('NODE_DEBUG=execa has lower priority, sync', testDebugEnvPriority, nestedExecaSync);43test('NODE_DEBUG=execa has lower priority', testDebugEnvPriority, parentExecaAsync);44test('NODE_DEBUG=execa has lower priority, sync', testDebugEnvPriority, parentExecaSync);
modified:test/verbose/log.js+8 added-8 removed
1import {stripVTControlCharacters} from 'node:util';2import test from 'ava';3import {setFixtureDir} from '../helpers/fixtures-dir.js';4import {foobarString} from '../helpers/input.js';5import {nestedExecaAsync, nestedExecaSync} from '../helpers/verbose.js';5import {parentExecaAsync, parentExecaSync} from '../helpers/nested.js';67setFixtureDir();89const testNoStdout = async (t, verbose, execaMethod) => {10 const {stdout} = await execaMethod('noop.js', [foobarString], {verbose, stdio: 'inherit'});11 t.is(stdout, foobarString);12};1314test('Logs on stderr not stdout, verbose "none"', testNoStdout, 'none', nestedExecaAsync);15test('Logs on stderr not stdout, verbose "short"', testNoStdout, 'short', nestedExecaAsync);16test('Logs on stderr not stdout, verbose "full"', testNoStdout, 'full', nestedExecaAsync);17test('Logs on stderr not stdout, verbose "none", sync', testNoStdout, 'none', nestedExecaSync);18test('Logs on stderr not stdout, verbose "short", sync', testNoStdout, 'short', nestedExecaSync);19test('Logs on stderr not stdout, verbose "full", sync', testNoStdout, 'full', nestedExecaSync);14test('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);2021const 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};2526test('Prints with colors if supported', testColor, true, '1');
1 unmodified line
modified:test/verbose/output.js+60 added-64 removed
1import {once, on} from 'node:events';1import {on} from 'node:events';2import {rm, readFile} from 'node:fs/promises';3import {inspect} from 'node:util';4import test from 'ava';5import tempfile from 'tempfile';
2 unmodified lines
8import {setFixtureDir} from '../helpers/fixtures-dir.js';9import {foobarString, foobarObject, foobarUppercase} from '../helpers/input.js';10import {simpleFull, noNewlinesChunks} from '../helpers/lines.js';11import {fullStdio} from '../helpers/stdio.js';12import {nestedExecaAsync, parentExeca, parentExecaAsync, parentExecaSync} from '../helpers/nested.js';13import {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';2122setFixtureDir();2325const nestedExecaDouble = nestedExeca.bind(undefined, 'nested-double.js');2624const 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};2832test('Prints stdout, verbose "full"', testPrintOutput, 1, nestedExecaAsync);33test('Prints stdout, verbose "full", sync', testPrintOutput, 1, nestedExecaSync);34test('Prints stderr, verbose "full"', testPrintOutput, 2, nestedExecaAsync);35test('Prints stderr, verbose "full", sync', testPrintOutput, 2, nestedExecaSync);29test('Prints stdout, verbose "full"', testPrintOutput, 1, parentExecaAsync);30test('Prints stdout, verbose "full", sync', testPrintOutput, 1, parentExecaSync);31test('Prints stderr, verbose "full"', testPrintOutput, 2, parentExecaAsync);32test('Prints stderr, verbose "full", sync', testPrintOutput, 2, parentExecaSync);3334const 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};3842test('Does not print stdout, verbose "none"', testNoPrintOutput, 'none', 1, nestedExecaAsync);43test('Does not print stdout, verbose "short"', testNoPrintOutput, 'short', 1, nestedExecaAsync);44test('Does not print stdout, verbose "none", sync', testNoPrintOutput, 'none', 1, nestedExecaSync);45test('Does not print stdout, verbose "short", sync', testNoPrintOutput, 'short', 1, nestedExecaSync);46test('Does not print stderr, verbose "none"', testNoPrintOutput, 'none', 2, nestedExecaAsync);47test('Does not print stderr, verbose "short"', testNoPrintOutput, 'short', 2, nestedExecaAsync);48test('Does not print stderr, verbose "none", sync', testNoPrintOutput, 'none', 2, nestedExecaSync);49test('Does not print stderr, verbose "short", sync', testNoPrintOutput, 'short', 2, nestedExecaSync);50test('Does not print stdio[*], verbose "none"', testNoPrintOutput, 'none', 3, nestedExecaAsync);51test('Does not print stdio[*], verbose "short"', testNoPrintOutput, 'short', 3, nestedExecaAsync);52test('Does not print stdio[*], verbose "full"', testNoPrintOutput, 'full', 3, nestedExecaAsync);53test('Does not print stdio[*], verbose "none", sync', testNoPrintOutput, 'none', 3, nestedExecaSync);54test('Does not print stdio[*], verbose "short", sync', testNoPrintOutput, 'short', 3, nestedExecaSync);55test('Does not print stdio[*], verbose "full", sync', testNoPrintOutput, 'full', 3, nestedExecaSync);39test('Does not print stdout, verbose "none"', testNoPrintOutput, 'none', 1, parentExecaAsync);40test('Does not print stdout, verbose "short"', testNoPrintOutput, 'short', 1, parentExecaAsync);41test('Does not print stdout, verbose "none", sync', testNoPrintOutput, 'none', 1, parentExecaSync);42test('Does not print stdout, verbose "short", sync', testNoPrintOutput, 'short', 1, parentExecaSync);43test('Does not print stderr, verbose "none"', testNoPrintOutput, 'none', 2, parentExecaAsync);44test('Does not print stderr, verbose "short"', testNoPrintOutput, 'short', 2, parentExecaAsync);45test('Does not print stderr, verbose "none", sync', testNoPrintOutput, 'none', 2, parentExecaSync);46test('Does not print stderr, verbose "short", sync', testNoPrintOutput, 'short', 2, parentExecaSync);47test('Does not print stdio[*], verbose "none"', testNoPrintOutput, 'none', 3, parentExecaAsync);48test('Does not print stdio[*], verbose "short"', testNoPrintOutput, 'short', 3, parentExecaAsync);49test('Does not print stdio[*], verbose "full"', testNoPrintOutput, 'full', 3, parentExecaAsync);50test('Does not print stdio[*], verbose "none", sync', testNoPrintOutput, 'none', 3, parentExecaSync);51test('Does not print stdio[*], verbose "short", sync', testNoPrintOutput, 'short', 3, parentExecaSync);52test('Does not print stdio[*], verbose "full", sync', testNoPrintOutput, 'full', 3, parentExecaSync);5354const 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};5862test('Prints stdout after errors', testPrintError, nestedExecaAsync);63test('Prints stdout after errors, sync', testPrintError, nestedExecaSync);59test('Prints stdout after errors', testPrintError, runErrorSubprocessAsync);60test('Prints stdout after errors, sync', testPrintError, runErrorSubprocessSync);6162const testPipeOutput = async (t, fixtureName, sourceVerbose, destinationVerbose) => {63 const {stderr} = await execa(`nested-pipe-${fixtureName}.js`, [64 JSON.stringify(getVerboseOption(sourceVerbose, 'full')),
23 unmodified lines
88test('Does not print stdout if neither verbose with .pipe`command`', testPipeOutput, 'script', false, false);89test('Does not print stdout if neither verbose with .pipe(subprocess)', testPipeOutput, 'subprocesses', false, false);9091test('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});9596test('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});100101test('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});105106test('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});110111test('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});115116const 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};120121test('Does not change subprocess.stdout', testStdioSame, 1);
3 unmodified lines
125 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};128133test('Prints stdout, "lines: true"', testLines, false, nestedExecaAsync);134test('Prints stdout, "lines: true", stripFinalNewline', testLines, true, nestedExecaAsync);135test('Prints stdout, "lines: true", sync', testLines, false, nestedExecaSync);136test('Prints stdout, "lines: true", stripFinalNewline, sync', testLines, true, nestedExecaSync);129test('Prints stdout, "lines: true"', testLines, false, parentExecaAsync);130test('Prints stdout, "lines: true", stripFinalNewline', testLines, true, parentExecaAsync);131test('Prints stdout, "lines: true", sync', testLines, false, parentExecaSync);132test('Prints stdout, "lines: true", stripFinalNewline, sync', testLines, true, parentExecaSync);133134const 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};138139test('Prints stdout with only transforms', testOnlyTransforms, 'generator', false);140test('Prints stdout with only transforms, sync', testOnlyTransforms, 'generator', true);141test('Prints stdout with only duplexes', testOnlyTransforms, 'duplex', false);142143const 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};147148test('Prints stdout with object transforms', testObjectMode, false);149test('Prints stdout with object transforms, sync', testObjectMode, true);150151const 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 lines
159test('Prints stdout with big object transforms', testBigArray, false);160test('Prints stdout with big object transforms, sync', testBigArray, true);161162const 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};166167test('Prints stdout with string transforms in objectMode', testObjectModeString, false);168test('Prints stdout with string transforms in objectMode, sync', testObjectModeString, true);169170test('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'});172173 for await (const chunk of on(subprocess.stderr, 'data')) {174 const outputLine = getOutputLine(chunk.toString().trim());175 if (outputLine !== undefined) {
4 unmodified lines
180181 await subprocess;182});183188test('Prints stdout progressively, interleaved', async t => {189 const subprocess = nestedExecaDouble('noop-repeat.js', ['1', `${foobarString}\n`], {verbose: 'full'});184test.serial('Prints stdout progressively, interleaved', async t => {185 const subprocess = parentExeca('nested-double.js', 'noop-repeat.js', ['1', `${foobarString}\n`], {verbose: 'full'});186187 let firstSubprocessPrinted = false;188 let secondSubprocessPrinted = false;189 for await (const chunk of on(subprocess.stderr, 'data')) {
23 unmodified lines
213 const {stderr} = await execaMethod('noop-fd.js', ['1', '\n'], {verbose: 'full'});214 t.deepEqual(getOutputLines(stderr), [`${testTimestamp} [0] `]);215};216221test('Prints stdout, single newline', testSingleNewline, nestedExecaAsync);222test('Prints stdout, single newline, sync', testSingleNewline, nestedExecaSync);217test('Prints stdout, single newline', testSingleNewline, parentExecaAsync);218test('Prints stdout, single newline, sync', testSingleNewline, parentExecaSync);219220const 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};224225test('Can use encoding UTF16, verbose "full"', testUtf16, false);226test('Can use encoding UTF16, verbose "full", sync', testUtf16, true);227228const 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};232233test('Does not print stdout, encoding "buffer"', testNoOutputOptions, 'nested.js', {encoding: 'buffer'});
14 unmodified lines
248test('Does not print stdout, stdout 1, sync', testNoOutputOptions, 'nested-sync.js', {stdout: 1});249250const 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 lines
264 const {stderr} = await execaMethod('noop.js', [foobarString], {verbose: 'full', ...options});265 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);266};267272test('Prints stdout, stdout "pipe"', testPrintOutputOptions, {stdout: 'pipe'}, nestedExecaAsync);273test('Prints stdout, stdout "overlapped"', testPrintOutputOptions, {stdout: 'overlapped'}, nestedExecaAsync);274test('Prints stdout, stdout null', testPrintOutputOptions, {stdout: null}, nestedExecaAsync);275test('Prints stdout, stdout ["pipe"]', testPrintOutputOptions, {stdout: ['pipe']}, nestedExecaAsync);276test('Prints stdout, stdout "pipe", sync', testPrintOutputOptions, {stdout: 'pipe'}, nestedExecaSync);277test('Prints stdout, stdout null, sync', testPrintOutputOptions, {stdout: null}, nestedExecaSync);278test('Prints stdout, stdout ["pipe"], sync', testPrintOutputOptions, {stdout: ['pipe']}, nestedExecaSync);268test('Prints stdout, stdout "pipe"', testPrintOutputOptions, {stdout: 'pipe'}, parentExecaAsync);269test('Prints stdout, stdout "overlapped"', testPrintOutputOptions, {stdout: 'overlapped'}, parentExecaAsync);270test('Prints stdout, stdout null', testPrintOutputOptions, {stdout: null}, parentExecaAsync);271test('Prints stdout, stdout ["pipe"]', testPrintOutputOptions, {stdout: ['pipe']}, parentExecaAsync);272test('Prints stdout, stdout "pipe", sync', testPrintOutputOptions, {stdout: 'pipe'}, parentExecaSync);273test('Prints stdout, stdout null, sync', testPrintOutputOptions, {stdout: null}, parentExecaSync);274test('Prints stdout, stdout ["pipe"], sync', testPrintOutputOptions, {stdout: ['pipe']}, parentExecaSync);275276const 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};280285test('Prints stdout, buffer: false', testPrintOutputNoBuffer, nestedExecaAsync);286test('Prints stdout, buffer: false, sync', testPrintOutputNoBuffer, nestedExecaSync);281test('Prints stdout, buffer: false', testPrintOutputNoBuffer, parentExecaAsync);282test('Prints stdout, buffer: false, sync', testPrintOutputNoBuffer, parentExecaSync);283284const 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};288289test('Prints stdout, buffer: false, transform', testPrintOutputNoBufferTransform, false);290test('Prints stdout, buffer: false, transform, sync', testPrintOutputNoBufferTransform, true);291292const 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};296297test('Prints stdout, .pipe(stream) + .unpipe()', testPrintOutputFixture, 'nested-pipe-stream.js', 'true');
3 unmodified lines
301 const {stderr} = await execaMethod('noop-132.js', {verbose: 'full'});302 t.deepEqual(getOutputLines(stderr), expectedLines.map(line => `${testTimestamp} [0] ${line}`));303};304309test('Prints stdout + stderr interleaved', testInterleaved, [1, 2, 3], nestedExecaAsync);310test('Prints stdout + stderr not interleaved, sync', testInterleaved, [1, 3, 2], nestedExecaSync);305test('Prints stdout + stderr interleaved', testInterleaved, [1, 2, 3], parentExecaAsync);306test('Prints stdout + stderr not interleaved, sync', testInterleaved, [1, 3, 2], parentExecaSync);
modified:test/verbose/start.js+24 added-21 removed
1 unmodified line
2import {red} from 'yoctocolors';3import {execa} from '../../index.js';4import {setFixtureDir} from '../helpers/fixtures-dir.js';5import {foobarString} from '../helpers/input.js';6import {parentExecaAsync, parentExecaSync, parentWorker} from '../helpers/nested.js';7import {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 lines
22 const {stderr} = await execaMethod('noop.js', [foobarString], {verbose});23 t.is(getCommandLine(stderr), `${testTimestamp} [0] $ noop.js ${foobarString}`);24};2525test('Prints command, verbose "short"', testPrintCommand, 'short', nestedExecaAsync);26test('Prints command, verbose "full"', testPrintCommand, 'full', nestedExecaAsync);27test('Prints command, verbose "short", sync', testPrintCommand, 'short', nestedExecaSync);28test('Prints command, verbose "full", sync', testPrintCommand, 'full', nestedExecaSync);26test('Prints command, verbose "short"', testPrintCommand, 'short', parentExecaAsync);27test('Prints command, verbose "full"', testPrintCommand, 'full', parentExecaAsync);28test('Prints command, verbose "short", sync', testPrintCommand, 'short', parentExecaSync);29test('Prints command, verbose "full", sync', testPrintCommand, 'full', parentExecaSync);30test('Prints command, verbose "short", worker', testPrintCommand, 'short', parentWorker);31test('Prints command, verbose "full", work', testPrintCommand, 'full', parentWorker);3233const testNoPrintCommand = async (t, execaMethod) => {34 const {stderr} = await execaMethod('noop.js', [foobarString], {verbose: 'none'});35 t.is(stderr, '');36};3735test('Does not print command, verbose "none"', testNoPrintCommand, nestedExecaAsync);36test('Does not print command, verbose "none", sync', testNoPrintCommand, nestedExecaSync);38test('Does not print command, verbose "none"', testNoPrintCommand, parentExecaAsync);39test('Does not print command, verbose "none", sync', testNoPrintCommand, parentExecaSync);4041const 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};4543test('Prints command after errors', testPrintCommandError, nestedExecaAsync);44test('Prints command after errors, sync', testPrintCommandError, nestedExecaSync);46test('Prints command after errors', testPrintCommandError, runErrorSubprocessAsync);47test('Prints command after errors, sync', testPrintCommandError, runErrorSubprocessSync);4849const 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};5351test('Prints command before early validation errors', testPrintCommandEarly, nestedExecaAsync);52test('Prints command before early validation errors, sync', testPrintCommandEarly, nestedExecaSync);54test('Prints command before early validation errors', testPrintCommandEarly, runEarlyErrorSubprocessAsync);55test('Prints command before early validation errors, sync', testPrintCommandEarly, runEarlyErrorSubprocessSync);5657const testPipeCommand = async (t, fixtureName, sourceVerbose, destinationVerbose) => {58 const {stderr} = await execa(`nested-pipe-${fixtureName}.js`, [59 JSON.stringify(getVerboseOption(sourceVerbose)),
21 unmodified lines
81test('Prints neither commands piped with .pipe`command`', testPipeCommand, 'script', false, false);82test('Prints neither commands piped with .pipe(subprocess)', testPipeCommand, 'subprocesses', false, false);8384test('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});8889test('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});9394test('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});9899test('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});103104test('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});