command.js
This file
Path
test/methods/command.js
108 lines · 4.4 KiB · JavaScript
Last changed by
Remove `execaCommand()` and `execaCommandSync()` (#1244)Sindre Sorhusbefore adoption3ced394
History of this fileTake it
Rename files (#977)ehmickybefore adoption4b2e316
line 1why, one step back1import test from 'ava';Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
lines 2–12why, one step back2import {3 execa,4 execaSync,5 $,6 execaNode,7 parseCommandString,8} from '../../index.js';9import {10 setFixtureDirectory,11 FIXTURES_DIRECTORY_URL,12} from '../helpers/fixtures-directory.js';Rename files (#977)ehmickybefore adoption4b2e316
line 13why, one step back13Upgrade xo (#980)ehmickybefore adoptionccfa412
line 14why, one step back14setFixtureDirectory();Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
line 15why, one step back15const ECHO_FIXTURE_URL = new URL('echo.js', FIXTURES_DIRECTORY_URL);Rename files (#977)ehmickybefore adoption4b2e316
line 16why, one step back16Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
lines 17–79why, one step back17const parseAndRunCommand = command => execa`${parseCommandString(command)}`;1819test('parseCommandString() + execa()', async t => {20 const {stdout} = await execa('echo.js', parseCommandString('foo bar'));21 t.is(stdout, 'foo\nbar');22});2324test('parseCommandString() + execaSync()', t => {25 const {stdout} = execaSync('echo.js', parseCommandString('foo bar'));26 t.is(stdout, 'foo\nbar');27});2829test('parseCommandString() + execa`...`', async t => {30 const {stdout} = await execa`${parseCommandString('echo.js foo bar')}`;31 t.is(stdout, 'foo\nbar');32});3334test('parseCommandString() + execa`...`, only arguments', async t => {35 const {stdout} = await execa`echo.js ${parseCommandString('foo bar')}`;36 t.is(stdout, 'foo\nbar');37});3839test('parseCommandString() + execa`...`, only some arguments', async t => {40 const {stdout} = await execa`echo.js ${'foo bar'} ${parseCommandString('foo bar')}`;41 t.is(stdout, 'foo bar\nfoo\nbar');42});4344test('parseCommandString() + execaSync`...`', t => {45 const {stdout} = execaSync`${parseCommandString('echo.js foo bar')}`;46 t.is(stdout, 'foo\nbar');47});4849test('parseCommandString() + execaSync`...`, only arguments', t => {50 const {stdout} = execaSync`echo.js ${parseCommandString('foo bar')}`;51 t.is(stdout, 'foo\nbar');52});5354test('parseCommandString() + execaSync`...`, only some arguments', t => {55 const {stdout} = execaSync`echo.js ${'foo bar'} ${parseCommandString('foo bar')}`;56 t.is(stdout, 'foo bar\nfoo\nbar');57});5859test('parseCommandString() + $', async t => {60 const {stdout} = await $`${parseCommandString('echo.js foo bar')}`;61 t.is(stdout, 'foo\nbar');62});6364test('parseCommandString() + $.sync', t => {65 const {stdout} = $.sync`${parseCommandString('echo.js foo bar')}`;66 t.is(stdout, 'foo\nbar');67});6869test('parseCommandString() + execaNode', async t => {70 const {stdout} = await execaNode(ECHO_FIXTURE_URL, parseCommandString('foo bar'));71 t.is(stdout, 'foo\nbar');72});7374const testInvalidArgumentsParse = (t, command) => {75 t.throws(() => parseCommandString(command), {76 message: /The command must be a string/,77 });78};79Remove `execaCommand()` and `execaCommandSync()` (#1244)Sindre Sorhusbefore adoption3ced394
lines 80–85why, one step back80test('parseCommandString() must not pass a number', testInvalidArgumentsParse, 0);81test('parseCommandString() must not pass undefined', testInvalidArgumentsParse, undefined);82test('parseCommandString() must not pass null', testInvalidArgumentsParse, null);83test('parseCommandString() must not pass a symbol', testInvalidArgumentsParse, Symbol('test'));84test('parseCommandString() must not pass an object', testInvalidArgumentsParse, {});85test('parseCommandString() must not pass an array', testInvalidArgumentsParse, []);Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
line 86why, one step back86Remove `execaCommand()` and `execaCommandSync()` (#1244)Sindre Sorhusbefore adoption3ced394
line 87why, one step back87const testParseCommandOutput = async (t, command, expectedOutput, execaMethod) => {Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
lines 88–91why, one step back88 const {stdout} = await execaMethod(command);89 t.is(stdout, expectedOutput);90};91Remove `execaCommand()` and `execaCommandSync()` (#1244)Sindre Sorhusbefore adoption3ced394
lines 92–99why, one step back92test('parseCommandString() allows escaping spaces in commands', testParseCommandOutput, 'command\\ with\\ space.js foo bar', 'foo\nbar', parseAndRunCommand);93test('parseCommandString() trims', testParseCommandOutput, ' echo.js foo bar ', 'foo\nbar', parseAndRunCommand);94test('parseCommandString() ignores consecutive spaces', testParseCommandOutput, 'echo.js foo bar', 'foo\nbar', parseAndRunCommand);95test('parseCommandString() escapes other whitespaces', testParseCommandOutput, 'echo.js foo\tbar', 'foo\tbar', parseAndRunCommand);96test('parseCommandString() allows escaping spaces', testParseCommandOutput, 'echo.js foo\\ bar', 'foo bar', parseAndRunCommand);97test('parseCommandString() allows escaping backslashes before spaces', testParseCommandOutput, 'echo.js foo\\\\ bar', 'foo\\ bar', parseAndRunCommand);98test('parseCommandString() allows escaping multiple backslashes before spaces', testParseCommandOutput, 'echo.js foo\\\\\\\\ bar', 'foo\\\\\\ bar', parseAndRunCommand);99test('parseCommandString() allows escaping backslashes not before spaces', testParseCommandOutput, 'echo.js foo\\bar baz', 'foo\\bar\nbaz', parseAndRunCommand);Add `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
lines 100–105why, one step back100101test('parseCommandString() can get empty strings', t => {102 t.deepEqual(parseCommandString(''), []);103});104105test('parseCommandString() can get only whitespaces', t => {Require Node.js 22 (#1243)Sindre Sorhusbefore adoption04b4454
line 106why, one step back106 // eslint-disable-next-line unicorn/prefer-string-repeatAdd `parseCommandString()` (#1054)ehmickybefore adoptionb9474c3
lines 107–108why, one step back107 t.deepEqual(parseCommandString(' '), []);108});