command.js
This file
Path
test/command.js
62 lines · 2.3 KiB · JavaScript
Last changed by
Improve error message when passing wrong arguments to `execaCommand()` (#899)ehmickybefore adoptiond1889f6
History of this fileTake it
The walk stopped after 200 commits: lines older than bea94d6 point at it.
Add race condition-related tests (#618)ehmickybefore adoptionbea94d6
line 1why, one step back1import test from 'ava';Split files (#791)ehmickybefore adoption932fb26
line 2why, one step back2import {execaCommand, execaCommandSync} from '../index.js';Add race condition-related tests (#618)ehmickybefore adoptionbea94d6
lines 3–40why, one step back3import {setFixtureDir} from './helpers/fixtures-dir.js';45setFixtureDir();67test('execaCommand()', async t => {8 const {stdout} = await execaCommand('echo.js foo bar');9 t.is(stdout, 'foo\nbar');10});1112test('execaCommand() ignores consecutive spaces', async t => {13 const {stdout} = await execaCommand('echo.js foo bar');14 t.is(stdout, 'foo\nbar');15});1617test('execaCommand() allows escaping spaces in commands', async t => {18 const {stdout} = await execaCommand('command\\ with\\ space.js foo bar');19 t.is(stdout, 'foo\nbar');20});2122test('execaCommand() allows escaping spaces in arguments', async t => {23 const {stdout} = await execaCommand('echo.js foo\\ bar');24 t.is(stdout, 'foo bar');25});2627test('execaCommand() escapes other whitespaces', async t => {28 const {stdout} = await execaCommand('echo.js foo\tbar');29 t.is(stdout, 'foo\tbar');30});3132test('execaCommand() trims', async t => {33 const {stdout} = await execaCommand(' echo.js foo bar ');34 t.is(stdout, 'foo\nbar');35});3637test('execaCommandSync()', t => {38 const {stdout} = execaCommandSync('echo.js foo bar');39 t.is(stdout, 'foo\nbar');40});Improve input validation (#838)ehmickybefore adoption8ee137c
lines 41–52why, one step back4142const testInvalidCommand = (t, execaCommand, invalidArgument) => {43 t.throws(() => {44 execaCommand(invalidArgument);45 }, {message: /First argument must be a string/});46};4748test('execaCommand() must use a string', testInvalidCommand, execaCommand, true);49test('execaCommandSync() must use a string', testInvalidCommand, execaCommandSync, true);50test('execaCommand() must have an argument', testInvalidCommand, execaCommand, undefined);51test('execaCommandSync() must have an argument', testInvalidCommand, execaCommandSync, undefined);52Improve error message when passing wrong arguments to `execaCommand()` (#899)ehmickybefore adoptiond1889f6
line 53why, one step back53const testInvalidArgs = (t, secondArgument, execaCommand) => {Improve input validation (#838)ehmickybefore adoption8ee137c
line 54why, one step back54 t.throws(() => {Improve error message when passing wrong arguments to `execaCommand()` (#899)ehmickybefore adoptiond1889f6
lines 55–56why, one step back55 execaCommand('echo', secondArgument);56 }, {message: /The command and its arguments must be passed as a single string/});Improve input validation (#838)ehmickybefore adoption8ee137c
lines 57–58why, one step back57};58Improve error message when passing wrong arguments to `execaCommand()` (#899)ehmickybefore adoptiond1889f6
lines 59–62why, one step back59test('execaCommand() must not pass an array of arguments', testInvalidArgs, [''], execaCommand);60test('execaCommandSync() must not pass an array of arguments', testInvalidArgs, [''], execaCommandSync);61test('execaCommand() must not pass non-options as second argument', testInvalidArgs, '', execaCommand);62test('execaCommandSync() must not pass non-options as second argument', testInvalidArgs, '', execaCommandSync);