Skip to content
Myr

command.js

This file

Path

test/command.js

64 lines · 2.0 KiB · JavaScript

Last changed by

Separate command-related logic into its own file (#329)ehmickybefore adoption46daa7b

History of this file

Take it

Separate command-related logic into its own file (#329)ehmickybefore adoption46daa7b

lines 1–64why, one step back
1import path from 'path';
2import test from 'ava';3import execa from '..';45process.env.PATH = path.join(__dirname, 'fixtures') + path.delimiter + process.env.PATH;67const command = async (t, expected, ...args) => {8 const {command: failCommand} = await t.throwsAsync(execa('fail', args));9 t.is(failCommand, `fail${expected}`);1011 const {command} = await execa('noop', args);12 t.is(command, `noop${expected}`);13};1415command.title = (message, expected) => `command is: ${JSON.stringify(expected)}`;1617test(command, ' foo bar', 'foo', 'bar');18test(command, ' baz quz', 'baz', 'quz');19test(command, '');2021test('allow commands with spaces and no array arguments', async t => {22 const {stdout} = await execa('command with space');23 t.is(stdout, '');24});2526test('allow commands with spaces and array arguments', async t => {27 const {stdout} = await execa('command with space', ['foo', 'bar']);28 t.is(stdout, 'foo\nbar');29});3031test('execa.command()', async t => {32 const {stdout} = await execa.command('node test/fixtures/echo foo bar');33 t.is(stdout, 'foo\nbar');34});3536test('execa.command() ignores consecutive spaces', async t => {37 const {stdout} = await execa.command('node test/fixtures/echo foo bar');38 t.is(stdout, 'foo\nbar');39});4041test('execa.command() allows escaping spaces in commands', async t => {42 const {stdout} = await execa.command('command\\ with\\ space foo bar');43 t.is(stdout, 'foo\nbar');44});4546test('execa.command() allows escaping spaces in arguments', async t => {47 const {stdout} = await execa.command('node test/fixtures/echo foo\\ bar');48 t.is(stdout, 'foo bar');49});5051test('execa.command() escapes other whitespaces', async t => {52 const {stdout} = await execa.command('node test/fixtures/echo foo\tbar');53 t.is(stdout, 'foo\tbar');54});5556test('execa.command() trims', async t => {57 const {stdout} = await execa.command(' node test/fixtures/echo foo bar ');58 t.is(stdout, 'foo\nbar');59});6061test('execa.command.sync()', t => {62 const {stdout} = execa.commandSync('node test/fixtures/echo foo bar');63 t.is(stdout, 'foo\nbar');64});