command.js
This file
Path
test/methods/command.js
110 lines · 4.7 KiB · JavaScript
Last changed by
TweaksSindre Sorhusbefore adoption698a1b8
History of this fileTake it
The walk stopped after 200 commits: lines older than 08eb743 point at it.
TweaksSindre Sorhusbefore adoption698a1b8
lines 1–3why, one step back1import assert from 'node:assert/strict';2import test from 'node:test';3import {assertThrows} from '../helpers/assert.js';Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
lines 4–14why, one step back4import {5 execa,6 execaSync,7 $,8 execaNode,9 parseCommandString,10} from '../../index.js';11import {12 setFixtureDirectory,13 FIXTURES_DIRECTORY_URL,14} from '../helpers/fixtures-directory.js';Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743
lines 15–16why, one step back1516setFixtureDirectory();Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
line 17why, one step back17const ECHO_FIXTURE_URL = new URL('echo.js', FIXTURES_DIRECTORY_URL);Upgrade `tsd` and `c8` (#982)ehmickybefore adoption08eb743
line 18why, one step back18Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
lines 19–20why, one step back19const parseAndRunCommand = command => execa`${parseCommandString(command)}`;20TweaksSindre Sorhusbefore adoption698a1b8
line 21why, one step back21test('parseCommandString() + execa()', async () => {Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
line 22why, one step back22 const {stdout} = await execa('echo.js', parseCommandString('foo bar'));TweaksSindre Sorhusbefore adoption698a1b8
line 23why, one step back23 assert.equal(stdout, 'foo\nbar');Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
lines 24–25why, one step back24});25TweaksSindre Sorhusbefore adoption698a1b8
line 26why, one step back26test('parseCommandString() + execaSync()', () => {Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
line 27why, one step back27 const {stdout} = execaSync('echo.js', parseCommandString('foo bar'));TweaksSindre Sorhusbefore adoption698a1b8
line 28why, one step back28 assert.equal(stdout, 'foo\nbar');Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
lines 29–30why, one step back29});30TweaksSindre Sorhusbefore adoption698a1b8
line 31why, one step back31test('parseCommandString() + execa`...`', async () => {Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
line 32why, one step back32 const {stdout} = await execa`${parseCommandString('echo.js foo bar')}`;TweaksSindre Sorhusbefore adoption698a1b8
line 33why, one step back33 assert.equal(stdout, 'foo\nbar');Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
lines 34–35why, one step back34});35TweaksSindre Sorhusbefore adoption698a1b8
line 36why, one step back36test('parseCommandString() + execa`...`, only arguments', async () => {Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
line 37why, one step back37 const {stdout} = await execa`echo.js ${parseCommandString('foo bar')}`;TweaksSindre Sorhusbefore adoption698a1b8
line 38why, one step back38 assert.equal(stdout, 'foo\nbar');Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
lines 39–40why, one step back39});40TweaksSindre Sorhusbefore adoption698a1b8
line 41why, one step back41test('parseCommandString() + execa`...`, only some arguments', async () => {Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
line 42why, one step back42 const {stdout} = await execa`echo.js ${'foo bar'} ${parseCommandString('foo bar')}`;TweaksSindre Sorhusbefore adoption698a1b8
line 43why, one step back43 assert.equal(stdout, 'foo bar\nfoo\nbar');Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
lines 44–45why, one step back44});45TweaksSindre Sorhusbefore adoption698a1b8
line 46why, one step back46test('parseCommandString() + execaSync`...`', () => {Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
line 47why, one step back47 const {stdout} = execaSync`${parseCommandString('echo.js foo bar')}`;TweaksSindre Sorhusbefore adoption698a1b8
line 48why, one step back48 assert.equal(stdout, 'foo\nbar');Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
lines 49–50why, one step back49});50TweaksSindre Sorhusbefore adoption698a1b8
line 51why, one step back51test('parseCommandString() + execaSync`...`, only arguments', () => {Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
line 52why, one step back52 const {stdout} = execaSync`echo.js ${parseCommandString('foo bar')}`;TweaksSindre Sorhusbefore adoption698a1b8
line 53why, one step back53 assert.equal(stdout, 'foo\nbar');Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
lines 54–55why, one step back54});55TweaksSindre Sorhusbefore adoption698a1b8
line 56why, one step back56test('parseCommandString() + execaSync`...`, only some arguments', () => {Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
line 57why, one step back57 const {stdout} = execaSync`echo.js ${'foo bar'} ${parseCommandString('foo bar')}`;TweaksSindre Sorhusbefore adoption698a1b8
line 58why, one step back58 assert.equal(stdout, 'foo bar\nfoo\nbar');Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
lines 59–60why, one step back59});60TweaksSindre Sorhusbefore adoption698a1b8
line 61why, one step back61test('parseCommandString() + $', async () => {Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
line 62why, one step back62 const {stdout} = await $`${parseCommandString('echo.js foo bar')}`;TweaksSindre Sorhusbefore adoption698a1b8
line 63why, one step back63 assert.equal(stdout, 'foo\nbar');Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
lines 64–65why, one step back64});65TweaksSindre Sorhusbefore adoption698a1b8
line 66why, one step back66test('parseCommandString() + $.sync', () => {Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
line 67why, one step back67 const {stdout} = $.sync`${parseCommandString('echo.js foo bar')}`;TweaksSindre Sorhusbefore adoption698a1b8
line 68why, one step back68 assert.equal(stdout, 'foo\nbar');Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
lines 69–70why, one step back69});70TweaksSindre Sorhusbefore adoption698a1b8
line 71why, one step back71test('parseCommandString() + execaNode', async () => {Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
line 72why, one step back72 const {stdout} = await execaNode(ECHO_FIXTURE_URL, parseCommandString('foo bar'));TweaksSindre Sorhusbefore adoption698a1b8
line 73why, one step back73 assert.equal(stdout, 'foo\nbar');Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
lines 74–75why, one step back74});75TweaksSindre Sorhusbefore adoption698a1b8
lines 76–77why, one step back76const testInvalidArgumentsParse = command => {77 assertThrows(() => parseCommandString(command), {Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
lines 78–81why, one step back78 message: /The command must be a string/,79 });80};81TweaksSindre Sorhusbefore adoption698a1b8
lines 82–87why, one step back82test('parseCommandString() must not pass a number', () => testInvalidArgumentsParse(0));83test('parseCommandString() must not pass undefined', () => testInvalidArgumentsParse(undefined));84test('parseCommandString() must not pass null', () => testInvalidArgumentsParse(null));85test('parseCommandString() must not pass a symbol', () => testInvalidArgumentsParse(Symbol('test')));86test('parseCommandString() must not pass an object', () => testInvalidArgumentsParse({}));87test('parseCommandString() must not pass an array', () => testInvalidArgumentsParse([]));Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
line 88why, one step back88TweaksSindre Sorhusbefore adoption698a1b8
line 89why, one step back89const testParseCommandOutput = async (command, expectedOutput, execaMethod) => {Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
line 90why, one step back90 const {stdout} = await execaMethod(command);TweaksSindre Sorhusbefore adoption698a1b8
line 91why, one step back91 assert.equal(stdout, expectedOutput);Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
lines 92–93why, one step back92};93TweaksSindre Sorhusbefore adoption698a1b8
lines 94–101why, one step back94test('parseCommandString() allows escaping spaces in commands', () => testParseCommandOutput('command\\ with\\ space.js foo bar', 'foo\nbar', parseAndRunCommand));95test('parseCommandString() trims', () => testParseCommandOutput(' echo.js foo bar ', 'foo\nbar', parseAndRunCommand));96test('parseCommandString() ignores consecutive spaces', () => testParseCommandOutput('echo.js foo bar', 'foo\nbar', parseAndRunCommand));97test('parseCommandString() escapes other whitespaces', () => testParseCommandOutput('echo.js foo\tbar', 'foo\tbar', parseAndRunCommand));98test('parseCommandString() allows escaping spaces', () => testParseCommandOutput('echo.js foo\\ bar', 'foo bar', parseAndRunCommand));99test('parseCommandString() allows escaping backslashes before spaces', () => testParseCommandOutput('echo.js foo\\\\ bar', 'foo\\ bar', parseAndRunCommand));100test('parseCommandString() allows escaping multiple backslashes before spaces', () => testParseCommandOutput('echo.js foo\\\\\\\\ bar', 'foo\\\\\\ bar', parseAndRunCommand));101test('parseCommandString() allows escaping backslashes not before spaces', () => testParseCommandOutput('echo.js foo\\bar baz', 'foo\\bar\nbaz', parseAndRunCommand));Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
line 102why, one step back102TweaksSindre Sorhusbefore adoption698a1b8
lines 103–104why, one step back103test('parseCommandString() can get empty strings', () => {104 assert.deepEqual(parseCommandString(''), []);Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
lines 105–106why, one step back105});106TweaksSindre Sorhusbefore adoption698a1b8
line 107why, one step back107test('parseCommandString() can get only whitespaces', () => {Require Node.js 22 (#1243)Sindre Sorhusbefore adoption04b4454
line 108why, one step back108 // eslint-disable-next-line unicorn/prefer-string-repeatTweaksSindre Sorhusbefore adoption698a1b8
line 109why, one step back109 assert.deepEqual(parseCommandString(' '), []);Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
line 110why, one step back110});