Skip to content
Myr

start.js

This file

Path

test/verbose/start.js

173 lines · 11.3 KiB · JavaScript

Last changed by

Fix `escapedCommand` and `verbose` quoting arguments when using the `shell` optionSindre Sorhusbefore adoptionb2c3a54

History of this file

Take it

The walk stopped after 200 commits: lines older than 9f65b86 point at it.

TweaksSindre Sorhusbefore adoption698a1b8

lines 1–2why, one step back
1import assert from 'node:assert/strict';
2import test from 'node:test';

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 3why, one step back
3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';

Require Node.js 22 (#1243)Sindre Sorhusbefore adoption04b4454

line 4why, one step back
4import {foobarString, foobarRed} from '../helpers/input.js';

Refactor test helpers for the `verbose` option (#1128)ehmickybefore adoption18d320f

line 5why, one step back
5import {nestedSubprocess} from '../helpers/nested.js';

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 6–7why, one step back
6import {
7 QUOTE,

Refactor test helpers for the `verbose` option (#1128)ehmickybefore adoption18d320f

lines 8–9why, one step back
8 runErrorSubprocess,
9 runEarlyErrorSubprocess,

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 10–13why, one step back
10 getCommandLine,
11 getCommandLines,12 testTimestamp,13 getVerboseOption,

Fix fd-specific options to account for `ipc` (#1241)Sindre Sorhusbefore adoptionb886883

line 14why, one step back
14 getStdioForFd3Option,

Add more tests for the `verbose` option (#1127)ehmickybefore adoption37e0024

lines 15–26why, one step back
15 stdoutNoneOption,
16 stdoutShortOption,17 stdoutFullOption,18 stderrNoneOption,19 stderrShortOption,20 stderrFullOption,21 fd3NoneOption,22 fd3ShortOption,23 fd3FullOption,24 ipcNoneOption,25 ipcShortOption,26 ipcFullOption,

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 27–30why, one step back
27} from '../helpers/verbose.js';
2829setFixtureDirectory();30

TweaksSindre Sorhusbefore adoption698a1b8

line 31why, one step back
31const testPrintCommand = async (verbose, worker, isSync) => {

Fix fd-specific options to account for `ipc` (#1241)Sindre Sorhusbefore adoptionb886883

lines 32–37why, one step back
32 const {stderr} = await nestedSubprocess('noop.js', [foobarString], {
33 verbose,34 ...getStdioForFd3Option(verbose),35 worker,36 isSync,37 });

TweaksSindre Sorhusbefore adoption698a1b8

line 38why, one step back
38 assert.equal(getCommandLine(stderr), `${testTimestamp} [0] $ noop.js ${foobarString}`);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 39–40why, one step back
39};
40

TweaksSindre Sorhusbefore adoption698a1b8

lines 41–80why, one step back
41test('Prints command, verbose "short"', () => testPrintCommand('short', false, false));
42test('Prints command, verbose "full"', () => testPrintCommand('full', false, false));43test('Prints command, verbose "short", fd-specific stdout', () => testPrintCommand(stdoutShortOption, false, false));44test('Prints command, verbose "full", fd-specific stdout', () => testPrintCommand(stdoutFullOption, false, false));45test('Prints command, verbose "short", fd-specific stderr', () => testPrintCommand(stderrShortOption, false, false));46test('Prints command, verbose "full", fd-specific stderr', () => testPrintCommand(stderrFullOption, false, false));47test('Prints command, verbose "short", fd-specific fd3', () => testPrintCommand(fd3ShortOption, false, false));48test('Prints command, verbose "full", fd-specific fd3', () => testPrintCommand(fd3FullOption, false, false));49test('Prints command, verbose "short", fd-specific ipc', () => testPrintCommand(ipcShortOption, false, false));50test('Prints command, verbose "full", fd-specific ipc', () => testPrintCommand(ipcFullOption, false, false));51test('Prints command, verbose "short", sync', () => testPrintCommand('short', false, true));52test('Prints command, verbose "full", sync', () => testPrintCommand('full', false, true));53test('Prints command, verbose "short", fd-specific stdout, sync', () => testPrintCommand(stdoutShortOption, false, true));54test('Prints command, verbose "full", fd-specific stdout, sync', () => testPrintCommand(stdoutFullOption, false, true));55test('Prints command, verbose "short", fd-specific stderr, sync', () => testPrintCommand(stderrShortOption, false, true));56test('Prints command, verbose "full", fd-specific stderr, sync', () => testPrintCommand(stderrFullOption, false, true));57test('Prints command, verbose "short", fd-specific fd3, sync', () => testPrintCommand(fd3ShortOption, false, true));58test('Prints command, verbose "full", fd-specific fd3, sync', () => testPrintCommand(fd3FullOption, false, true));59test('Prints command, verbose "short", fd-specific ipc, sync', () => testPrintCommand(ipcShortOption, false, true));60test('Prints command, verbose "full", fd-specific ipc, sync', () => testPrintCommand(ipcFullOption, false, true));61test('Prints command, verbose "short", worker', () => testPrintCommand('short', true, false));62test('Prints command, verbose "full", worker', () => testPrintCommand('full', true, false));63test('Prints command, verbose "short", fd-specific stdout, worker', () => testPrintCommand(stdoutShortOption, true, false));64test('Prints command, verbose "full", fd-specific stdout, worker', () => testPrintCommand(stdoutFullOption, true, false));65test('Prints command, verbose "short", fd-specific stderr, worker', () => testPrintCommand(stderrShortOption, true, false));66test('Prints command, verbose "full", fd-specific stderr, worker', () => testPrintCommand(stderrFullOption, true, false));67test('Prints command, verbose "short", fd-specific fd3, worker', () => testPrintCommand(fd3ShortOption, true, false));68test('Prints command, verbose "full", fd-specific fd3, worker', () => testPrintCommand(fd3FullOption, true, false));69test('Prints command, verbose "short", fd-specific ipc, worker', () => testPrintCommand(ipcShortOption, true, false));70test('Prints command, verbose "full", fd-specific ipc, worker', () => testPrintCommand(ipcFullOption, true, false));71test('Prints command, verbose "short", worker, sync', () => testPrintCommand('short', true, true));72test('Prints command, verbose "full", worker, sync', () => testPrintCommand('full', true, true));73test('Prints command, verbose "short", fd-specific stdout, worker, sync', () => testPrintCommand(stdoutShortOption, true, true));74test('Prints command, verbose "full", fd-specific stdout, worker, sync', () => testPrintCommand(stdoutFullOption, true, true));75test('Prints command, verbose "short", fd-specific stderr, worker, sync', () => testPrintCommand(stderrShortOption, true, true));76test('Prints command, verbose "full", fd-specific stderr, worker, sync', () => testPrintCommand(stderrFullOption, true, true));77test('Prints command, verbose "short", fd-specific fd3, worker, sync', () => testPrintCommand(fd3ShortOption, true, true));78test('Prints command, verbose "full", fd-specific fd3, worker, sync', () => testPrintCommand(fd3FullOption, true, true));79test('Prints command, verbose "short", fd-specific ipc, worker, sync', () => testPrintCommand(ipcShortOption, true, true));80test('Prints command, verbose "full", fd-specific ipc, worker, sync', () => testPrintCommand(ipcFullOption, true, true));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 81why, one step back
81

TweaksSindre Sorhusbefore adoption698a1b8

line 82why, one step back
82const testNoPrintCommand = async (verbose, isSync) => {

Fix fd-specific options to account for `ipc` (#1241)Sindre Sorhusbefore adoptionb886883

line 83why, one step back
83 const {stderr} = await nestedSubprocess('noop.js', [foobarString], {verbose, ...getStdioForFd3Option(verbose), isSync});

TweaksSindre Sorhusbefore adoption698a1b8

line 84why, one step back
84 assert.equal(stderr, '');

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 85–86why, one step back
85};
86

TweaksSindre Sorhusbefore adoption698a1b8

lines 87–100why, one step back
87test('Does not print command, verbose "none"', () => testNoPrintCommand('none', false));
88test('Does not print command, verbose default', () => testNoPrintCommand(undefined, false));89test('Does not print command, verbose "none", fd-specific stdout', () => testNoPrintCommand(stdoutNoneOption, false));90test('Does not print command, verbose "none", fd-specific stderr', () => testNoPrintCommand(stderrNoneOption, false));91test('Does not print command, verbose "none", fd-specific fd3', () => testNoPrintCommand(fd3NoneOption, false));92test('Does not print command, verbose "none", fd-specific ipc', () => testNoPrintCommand(ipcNoneOption, false));93test('Does not print command, verbose default, fd-specific', () => testNoPrintCommand({}, false));94test('Does not print command, verbose "none", sync', () => testNoPrintCommand('none', true));95test('Does not print command, verbose default, sync', () => testNoPrintCommand(undefined, true));96test('Does not print command, verbose "none", fd-specific stdout, sync', () => testNoPrintCommand(stdoutNoneOption, true));97test('Does not print command, verbose "none", fd-specific stderr, sync', () => testNoPrintCommand(stderrNoneOption, true));98test('Does not print command, verbose "none", fd-specific fd3, sync', () => testNoPrintCommand(fd3NoneOption, true));99test('Does not print command, verbose "none", fd-specific ipc, sync', () => testNoPrintCommand(ipcNoneOption, true));100test('Does not print command, verbose default, fd-specific, sync', () => testNoPrintCommand({}, true));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 101why, one step back
101

TweaksSindre Sorhusbefore adoption698a1b8

lines 102–104why, one step back
102const testPrintCommandError = async isSync => {
103 const stderr = await runErrorSubprocess('short', isSync);104 assert.equal(getCommandLine(stderr), `${testTimestamp} [0] $ noop-fail.js 1 ${foobarString}`);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 105–106why, one step back
105};
106

TweaksSindre Sorhusbefore adoption698a1b8

lines 107–108why, one step back
107test('Prints command after errors', () => testPrintCommandError(false));
108test('Prints command after errors, sync', () => testPrintCommandError(true));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 109why, one step back
109

TweaksSindre Sorhusbefore adoption698a1b8

lines 110–112why, one step back
110const testPrintCommandEarly = async isSync => {
111 const stderr = await runEarlyErrorSubprocess(isSync);112 assert.equal(getCommandLine(stderr), `${testTimestamp} [0] $ noop.js ${foobarString}`);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 113–114why, one step back
113};
114

TweaksSindre Sorhusbefore adoption698a1b8

lines 115–116why, one step back
115test('Prints command before early validation errors', () => testPrintCommandEarly(false));
116test('Prints command before early validation errors, sync', () => testPrintCommandEarly(true));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 117why, one step back
117

TweaksSindre Sorhusbefore adoption698a1b8

line 118why, one step back
118const testPipeCommand = async (parentFixture, sourceVerbose, destinationVerbose) => {

Refactor test helpers for the `verbose` option (#1128)ehmickybefore adoption18d320f

lines 119–126why, one step back
119 const {stderr} = await nestedSubprocess('noop.js', [foobarString], {
120 parentFixture,121 sourceOptions: getVerboseOption(sourceVerbose),122 destinationFile: 'stdin.js',123 destinationOptions: getVerboseOption(destinationVerbose),124 });125126 const pipeSymbol = parentFixture === 'nested-pipe-subprocesses.js' ? '$' : '|';

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 127why, one step back
127 const lines = getCommandLines(stderr);

TweaksSindre Sorhusbefore adoption698a1b8

lines 128–129why, one step back
128 assert.equal(lines.includes(`${testTimestamp} [0] $ noop.js ${foobarString}`), sourceVerbose);
129 assert.equal(lines.includes(`${testTimestamp} [${sourceVerbose ? 1 : 0}] ${pipeSymbol} stdin.js`), destinationVerbose);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 130–131why, one step back
130};
131

TweaksSindre Sorhusbefore adoption698a1b8

lines 132–143why, one step back
132test('Prints both commands piped with .pipe("file")', () => testPipeCommand('nested-pipe-file.js', true, true));
133test('Prints both commands piped with .pipe`command`', () => testPipeCommand('nested-pipe-script.js', true, true));134test('Prints both commands piped with .pipe(subprocess)', () => testPipeCommand('nested-pipe-subprocesses.js', true, true));135test('Prints first command piped with .pipe("file")', () => testPipeCommand('nested-pipe-file.js', true, false));136test('Prints first command piped with .pipe`command`', () => testPipeCommand('nested-pipe-script.js', true, false));137test('Prints first command piped with .pipe(subprocess)', () => testPipeCommand('nested-pipe-subprocesses.js', true, false));138test('Prints second command piped with .pipe("file")', () => testPipeCommand('nested-pipe-file.js', false, true));139test('Prints second command piped with .pipe`command`', () => testPipeCommand('nested-pipe-script.js', false, true));140test('Prints second command piped with .pipe(subprocess)', () => testPipeCommand('nested-pipe-subprocesses.js', false, true));141test('Prints neither commands piped with .pipe("file")', () => testPipeCommand('nested-pipe-file.js', false, false));142test('Prints neither commands piped with .pipe`command`', () => testPipeCommand('nested-pipe-script.js', false, false));143test('Prints neither commands piped with .pipe(subprocess)', () => testPipeCommand('nested-pipe-subprocesses.js', false, false));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 144why, one step back
144

TweaksSindre Sorhusbefore adoption698a1b8

line 145why, one step back
145test('Quotes spaces from command', async () => {

Refactor test helpers for the `verbose` option (#1128)ehmickybefore adoption18d320f

line 146why, one step back
146 const {stderr} = await nestedSubprocess('noop.js', ['foo bar'], {verbose: 'short'});

TweaksSindre Sorhusbefore adoption698a1b8

line 147why, one step back
147 assert.equal(getCommandLine(stderr), `${testTimestamp} [0] $ noop.js ${QUOTE}foo bar${QUOTE}`);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 148–149why, one step back
148});
149

Fix `escapedCommand` and `verbose` quoting arguments when using the `shell` optionSindre Sorhusbefore adoptionb2c3a54

lines 150–154why, one step back
150test('Does not quote command with "shell"', async () => {
151 const {stderr} = await nestedSubprocess('echo', ['foo', '|', 'sort'], {verbose: 'short', shell: true});152 assert.equal(getCommandLine(stderr), `${testTimestamp} [0] $ echo foo | sort`);153});154

TweaksSindre Sorhusbefore adoption698a1b8

line 155why, one step back
155test('Quotes special punctuation from command', async () => {

Refactor test helpers for the `verbose` option (#1128)ehmickybefore adoption18d320f

line 156why, one step back
156 const {stderr} = await nestedSubprocess('noop.js', ['%'], {verbose: 'short'});

TweaksSindre Sorhusbefore adoption698a1b8

line 157why, one step back
157 assert.equal(getCommandLine(stderr), `${testTimestamp} [0] $ noop.js ${QUOTE}%${QUOTE}`);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 158–159why, one step back
158});
159

TweaksSindre Sorhusbefore adoption698a1b8

line 160why, one step back
160test('Does not escape internal characters from command', async () => {

Refactor test helpers for the `verbose` option (#1128)ehmickybefore adoption18d320f

line 161why, one step back
161 const {stderr} = await nestedSubprocess('noop.js', ['ã'], {verbose: 'short'});

TweaksSindre Sorhusbefore adoption698a1b8

line 162why, one step back
162 assert.equal(getCommandLine(stderr), `${testTimestamp} [0] $ noop.js ${QUOTE}ã${QUOTE}`);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 163–164why, one step back
163});
164

TweaksSindre Sorhusbefore adoption698a1b8

line 165why, one step back
165test('Escapes color sequences from command', async () => {

Require Node.js 22 (#1243)Sindre Sorhusbefore adoption04b4454

line 166why, one step back
166 const {stderr} = await nestedSubprocess('noop.js', [foobarRed], {verbose: 'short'});

TweaksSindre Sorhusbefore adoption698a1b8

line 167why, one step back
167 assert.ok(getCommandLine(stderr).includes(`${QUOTE}\\u001b[31m${foobarString}\\u001b[39m${QUOTE}`));

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 168–169why, one step back
168});
169

TweaksSindre Sorhusbefore adoption698a1b8

line 170why, one step back
170test('Escapes control characters from command', async () => {

Require Node.js 22 (#1243)Sindre Sorhusbefore adoption04b4454

line 171why, one step back
171 const {stderr} = await nestedSubprocess('noop.js', ['\u{1}'], {verbose: 'short'});

TweaksSindre Sorhusbefore adoption698a1b8

line 172why, one step back
172 assert.equal(getCommandLine(stderr), `${testTimestamp} [0] $ noop.js ${QUOTE}\\u0001${QUOTE}`);

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 173why, one step back
173});