Add more tests for the `verbose: 'full'` option (#961)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent dce0393 · Browse files · 7 files·+108 added−55 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+108 added−55 removed
- tests:+108 added−55 removed
Provenance
- Commit
10fdc8b- Tree
0dda9bf- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
dce0393
7 files changed+108 added−55 removed
deleted:test/fixtures/nested-big-array.js-8 removed
12345678#!/usr/bin/env nodeimport process from 'node:process';import {execa} from '../../index.js';import {getOutputGenerator} from '../helpers/generator.js';
const bigArray = Array.from({length: 100}, (_, index) => index);const [options, file, ...args] = process.argv.slice(2);await execa(file, args, {stdout: getOutputGenerator(bigArray)(true), ...JSON.parse(options)});modified:test/fixtures/nested-input.js+8 added-3 removed
123345676789101112#!/usr/bin/env nodeimport process from 'node:process';import {execa} from '../../index.js';import {execa, execaSync} from '../../index.js';import {foobarUtf16Uint8Array} from '../helpers/input.js';
const [options, file, ...args] = process.argv.slice(2);await execa(file, args, {...JSON.parse(options), input: foobarUtf16Uint8Array});const [optionsString, file, isSync, ...args] = process.argv.slice(2);const options = {...JSON.parse(optionsString), input: foobarUtf16Uint8Array};if (isSync === 'true') { execaSync(file, args, options);} else { await execa(file, args, options);}deleted:test/fixtures/nested-object.js-7 removed
1234567#!/usr/bin/env nodeimport process from 'node:process';import {execa} from '../../index.js';import {outputObjectGenerator} from '../helpers/generator.js';
const [options, file, ...args] = process.argv.slice(2);await execa(file, args, {stdout: outputObjectGenerator(), ...JSON.parse(options)});modified:test/fixtures/nested-transform.js+24 added-3 removed
12345678910111213141516171819202122232425262778928293031323334#!/usr/bin/env nodeimport process from 'node:process';import {execa, execaSync} from '../../index.js';import {generatorsMap} from '../helpers/map.js';import {outputObjectGenerator, getOutputGenerator} from '../helpers/generator.js';import {simpleFull} from '../helpers/lines.js';
const getTransform = (type, transformName) => { if (type !== undefined) { return generatorsMap[type].uppercase(); }
if (transformName === 'object') { return outputObjectGenerator(); }
if (transformName === 'stringObject') { return getOutputGenerator(simpleFull)(true); }
if (transformName === 'bigArray') { const bigArray = Array.from({length: 100}, (_, index) => index); return getOutputGenerator(bigArray)(true); }};
const [optionsString, file, ...args] = process.argv.slice(2);const {type, isSync, ...options} = JSON.parse(optionsString);const newOptions = {stdout: generatorsMap[type].uppercase(), ...options};if (isSync === 'true') {const {type, transformName, isSync, ...options} = JSON.parse(optionsString);const newOptions = {stdout: getTransform(type, transformName), ...options};if (isSync) { execaSync(file, args, newOptions);} else { await execa(file, args, newOptions);}modified:test/fixtures/noop-132.js+3 added-5 removed
122344565867#!/usr/bin/env nodeimport process from 'node:process';console.log(1);console.warn(2);
process.stdout.write('1');process.stderr.write('3');
setTimeout(() => { process.stdout.write('2'); console.log(3);}, 1000);modified:test/stream/all.js+3 added-3 removed
48 unmodified lines495051525353545556565758585960616266 unmodified lines48 unmodified linestest('result.all is defined, lines, stripFinalNewline, failure, sync', testAllBoth, doubleFoobarArray, 'utf8', true, true, true, execaSync);
test.serial('result.all shows both `stdout` and `stderr` intermixed', async t => { const {all} = await execa('noop-132.js', {all: true}); t.is(all, '132'); t.is(all, '1\n2\n3');});
test('result.all shows both `stdout` and `stderr` not intermixed, sync', t => {test.serial('result.all shows both `stdout` and `stderr` not intermixed, sync', t => { const {all} = execaSync('noop-132.js', {all: true}); t.is(all, '123'); t.is(all, '1\n3\n2');});
const testAllIgnored = async (t, options, execaMethod) => { const {all} = await execaMethod('noop.js');66 unmodified linesmodified:test/verbose/output.js+70 added-26 removed
5 unmodified lines6 import {red} from 'yoctocolors';7 import {execa} from '../../index.js';8 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 {13 nestedExeca,14 nestedExecaAsync,106 unmodified lines121 const [[{stdio}]] = await Promise.all([once(subprocess, 'message'), subprocess]);122 t.is(stdio[fdNumber], foobarString);123 };124 124-test('Does not change stdout', testStdioSame, 1);125-test('Does not change stderr', testStdioSame, 2);125+test('Does not change subprocess.stdout', testStdioSame, 1);126+test('Does not change subprocess.stderr', testStdioSame, 2);127 128+const testLines = async (t, stripFinalNewline, execaMethod) => {129+ const {stderr} = await execaMethod('noop-fd.js', ['1', simpleFull], {verbose: 'full', lines: true});130+ t.deepEqual(getOutputLines(stderr), noNewlinesChunks.map(line => `${testTimestamp} [0] ${line}`));131+};132+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);137+127-const testOnlyTransforms = async (t, type) => {128- const {stderr} = await nestedExeca('nested-transform.js', 'noop.js', [foobarString], {verbose: 'full', type});138+const testOnlyTransforms = async (t, type, isSync) => {139+ const {stderr} = await nestedExeca('nested-transform.js', 'noop.js', [foobarString], {verbose: 'full', type, isSync});140 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString.toUpperCase()}`);141 };142 132-test('Prints stdout with only transforms', testOnlyTransforms, 'generator');133-test('Prints stdout with only duplexes', testOnlyTransforms, 'duplex');143+test('Prints stdout with only transforms', testOnlyTransforms, 'generator', false);144+test('Prints stdout with only transforms, sync', testOnlyTransforms, 'generator', true);145+test('Prints stdout with only duplexes', testOnlyTransforms, 'duplex', false);146 135-test('Prints stdout with object transforms', async t => {136- const {stderr} = await nestedExeca('nested-object.js', 'noop.js', {verbose: 'full'});147+const testObjectMode = async (t, isSync) => {148+ const {stderr} = await nestedExeca('nested-transform.js', 'noop.js', {verbose: 'full', transformName: 'object', isSync});149 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${inspect(foobarObject)}`);138-});150+};151 140-test('Prints stdout with big object transforms', async t => {141- const {stderr} = await nestedExeca('nested-big-array.js', 'noop.js', {verbose: 'full'});152+test('Prints stdout with object transforms', testObjectMode, false);153+test('Prints stdout with object transforms, sync', testObjectMode, true);154+155+const testBigArray = async (t, isSync) => {156+ const {stderr} = await nestedExeca('nested-transform.js', 'noop.js', {verbose: 'full', transformName: 'bigArray', isSync});157 const lines = getOutputLines(stderr);158 t.is(lines[0], `${testTimestamp} [0] [`);159 t.true(lines[1].startsWith(`${testTimestamp} [0] 0, 1,`));160 t.is(lines.at(-1), `${testTimestamp} [0] ]`);146-});161+};162 163+test('Prints stdout with big object transforms', testBigArray, false);164+test('Prints stdout with big object transforms, sync', testBigArray, true);165+166+const testObjectModeString = async (t, isSync) => {167+ const {stderr} = await nestedExeca('nested-transform.js', 'noop.js', {verbose: 'full', transformName: 'stringObject', isSync});168+ t.deepEqual(getOutputLines(stderr), noNewlinesChunks.map(line => `${testTimestamp} [0] ${line}`));169+};170+171+test('Prints stdout with string transforms in objectMode', testObjectModeString, false);172+test('Prints stdout with string transforms in objectMode, sync', testObjectModeString, true);173+174 test('Prints stdout one line at a time', async t => {175 const subprocess = nestedExecaAsync('noop-progressive.js', [foobarString], {verbose: 'full'});176 177 for await (const chunk of on(subprocess.stderr, 'data')) {42 unmodified lines220 221 test('Prints stdout, single newline', testSingleNewline, nestedExecaAsync);222 test('Prints stdout, single newline, sync', testSingleNewline, nestedExecaSync);223 198-test('Can use encoding UTF16, verbose "full"', async t => {199- const {stderr} = await nestedExeca('nested-input.js', 'stdin.js', {verbose: 'full', encoding: 'utf16le'});224+const testUtf16 = async (t, isSync) => {225+ const {stderr} = await nestedExeca('nested-input.js', 'stdin.js', [`${isSync}`], {verbose: 'full', encoding: 'utf16le'});226 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);201-});227+};228 229+test('Can use encoding UTF16, verbose "full"', testUtf16, false);230+test('Can use encoding UTF16, verbose "full", sync', testUtf16, true);231+203-const testNoOutputOptions = async (t, options, fixtureName = 'nested.js') => {232+const testNoOutputOptions = async (t, fixtureName, options = {}) => {233 const {stderr} = await nestedExeca(fixtureName, 'noop.js', [foobarString], {verbose: 'full', ...options});234 t.is(getOutputLine(stderr), undefined);235 };236 208-test('Does not print stdout, encoding "buffer"', testNoOutputOptions, {encoding: 'buffer'});209-test('Does not print stdout, encoding "hex"', testNoOutputOptions, {encoding: 'hex'});210-test('Does not print stdout, encoding "base64"', testNoOutputOptions, {encoding: 'base64'});211-test('Does not print stdout, stdout "ignore"', testNoOutputOptions, {stdout: 'ignore'});212-test('Does not print stdout, stdout "inherit"', testNoOutputOptions, {stdout: 'inherit'});213-test('Does not print stdout, stdout 1', testNoOutputOptions, {stdout: 1});214-test('Does not print stdout, stdout Writable', testNoOutputOptions, {}, 'nested-writable.js');215-test('Does not print stdout, stdout WritableStream', testNoOutputOptions, {}, 'nested-writable-web.js');216-test('Does not print stdout, .pipe(stream)', testNoOutputOptions, {}, 'nested-pipe-stream.js');217-test('Does not print stdout, .pipe(subprocess)', testNoOutputOptions, {}, 'nested-pipe-subprocess.js');237+test('Does not print stdout, encoding "buffer"', testNoOutputOptions, 'nested.js', {encoding: 'buffer'});238+test('Does not print stdout, encoding "hex"', testNoOutputOptions, 'nested.js', {encoding: 'hex'});239+test('Does not print stdout, encoding "base64"', testNoOutputOptions, 'nested.js', {encoding: 'base64'});240+test('Does not print stdout, stdout "ignore"', testNoOutputOptions, 'nested.js', {stdout: 'ignore'});241+test('Does not print stdout, stdout "inherit"', testNoOutputOptions, 'nested.js', {stdout: 'inherit'});242+test('Does not print stdout, stdout 1', testNoOutputOptions, 'nested.js', {stdout: 1});243+test('Does not print stdout, stdout Writable', testNoOutputOptions, 'nested-writable.js');244+test('Does not print stdout, stdout WritableStream', testNoOutputOptions, 'nested-writable-web.js');245+test('Does not print stdout, .pipe(stream)', testNoOutputOptions, 'nested-pipe-stream.js');246+test('Does not print stdout, .pipe(subprocess)', testNoOutputOptions, 'nested-pipe-subprocess.js');247+test('Does not print stdout, encoding "buffer", sync', testNoOutputOptions, 'nested-sync.js', {encoding: 'buffer'});248+test('Does not print stdout, encoding "hex", sync', testNoOutputOptions, 'nested-sync.js', {encoding: 'hex'});249+test('Does not print stdout, encoding "base64", sync', testNoOutputOptions, 'nested-sync.js', {encoding: 'base64'});250+test('Does not print stdout, stdout "ignore", sync', testNoOutputOptions, 'nested-sync.js', {stdout: 'ignore'});251+test('Does not print stdout, stdout "inherit", sync', testNoOutputOptions, 'nested-sync.js', {stdout: 'inherit'});252+test('Does not print stdout, stdout 1, sync', testNoOutputOptions, 'nested-sync.js', {stdout: 1});253 254 const testStdoutFile = async (t, fixtureName, getStdout) => {255 const file = tempfile();256 const {stderr} = await nestedExeca(fixtureName, 'noop.js', [foobarString], {verbose: 'full', stdout: getStdout(file)});4 unmodified lines261 };262 263 test('Does not print stdout, stdout { file }', testStdoutFile, 'nested.js', file => ({file}));264 test('Does not print stdout, stdout fileUrl', testStdoutFile, 'nested-file-url.js', file => file);265+test('Does not print stdout, stdout { file }, sync', testStdoutFile, 'nested-sync.js', file => ({file}));266 267 const testPrintOutputOptions = async (t, options, execaMethod) => {268 const {stderr} = await execaMethod('noop.js', [foobarString], {verbose: 'full', ...options});269 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);29 unmodified lines299 };300 301 test('Prints stdout, .pipe(stream) + .unpipe()', testPrintOutputFixture, 'nested-pipe-stream.js', 'true');302 test('Prints stdout, .pipe(subprocess) + .unpipe()', testPrintOutputFixture, 'nested-pipe-subprocess.js', 'true');303+304+const testInterleaved = async (t, expectedLines, execaMethod) => {305+ const {stderr} = await execaMethod('noop-132.js', {verbose: 'full'});306+ t.deepEqual(getOutputLines(stderr), expectedLines.map(line => `${testTimestamp} [0] ${line}`));307+};308+309+test('Prints stdout + stderr interleaved', testInterleaved, [1, 2, 3], nestedExecaAsync);310+test('Prints stdout + stderr not interleaved, sync', testInterleaved, [1, 3, 2], nestedExecaSync);