Skip to content
Myr

command.js

This file

Path

test/command.js

87 lines · 2.9 KiB · JavaScript

Last changed by

Re-enable Windows in CI (#500)ehmickybefore adoption071d0a2

History of this file

Take it

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

line 1why, one step back
1import test from 'ava';

Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880

line 2why, one step back
2import {execa, execaSync, execaCommand, execaCommandSync} from '../index.js';

Re-enable Windows in CI (#500)ehmickybefore adoption071d0a2

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

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

line 4why, one step back
4

Re-enable Windows in CI (#500)ehmickybefore adoption071d0a2

line 5why, one step back
5setFixtureDir();

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

lines 6–7why, one step back
6
7const command = async (t, expected, ...args) => {

Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880

lines 8–9why, one step back
8 const {command: failCommand} = await t.throwsAsync(execa('fail.js', args));
9 t.is(failCommand, `fail.js${expected}`);

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

line 10why, one step back
10

Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880

lines 11–12why, one step back
11 const {command} = await execa('noop.js', args);
12 t.is(command, `noop.js${expected}`);

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

lines 13–20why, one step back
13};
1415command.title = (message, expected) => `command is: ${JSON.stringify(expected)}`;1617test(command, ' foo bar', 'foo', 'bar');18test(command, ' baz quz', 'baz', 'quz');19test(command, '');20

Add `.escapedCommand` property (#466)ehmickybefore adoption712bafc

line 21why, one step back
21const testEscapedCommand = async (t, expected, args) => {

Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880

lines 22–23why, one step back
22 const {escapedCommand: failEscapedCommand} = await t.throwsAsync(execa('fail.js', args));
23 t.is(failEscapedCommand, `fail.js ${expected}`);

Add `.escapedCommand` property (#466)ehmickybefore adoption712bafc

lines 24–25why, one step back
24
25 const {escapedCommand: failEscapedCommandSync} = t.throws(() => {

Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880

line 26why, one step back
26 execaSync('fail.js', args);

Add `.escapedCommand` property (#466)ehmickybefore adoption712bafc

line 27why, one step back
27 });

Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880

line 28why, one step back
28 t.is(failEscapedCommandSync, `fail.js ${expected}`);

Add `.escapedCommand` property (#466)ehmickybefore adoption712bafc

line 29why, one step back
29

Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880

lines 30–31why, one step back
30 const {escapedCommand} = await execa('noop.js', args);
31 t.is(escapedCommand, `noop.js ${expected}`);

Add `.escapedCommand` property (#466)ehmickybefore adoption712bafc

line 32why, one step back
32

Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880

lines 33–34why, one step back
33 const {escapedCommand: escapedCommandSync} = execaSync('noop.js', args);
34 t.is(escapedCommandSync, `noop.js ${expected}`);

Add `.escapedCommand` property (#466)ehmickybefore adoption712bafc

lines 35–43why, one step back
35};
3637testEscapedCommand.title = (message, expected) => `escapedCommand is: ${JSON.stringify(expected)}`;3839test(testEscapedCommand, 'foo bar', ['foo', 'bar']);40test(testEscapedCommand, '"foo bar"', ['foo bar']);41test(testEscapedCommand, '"\\"foo\\""', ['"foo"']);42test(testEscapedCommand, '"*"', ['*']);43

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

line 44why, one step back
44test('allow commands with spaces and no array arguments', async t => {

Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880

line 45why, one step back
45 const {stdout} = await execa('command with space.js');

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

lines 46–49why, one step back
46 t.is(stdout, '');
47});4849test('allow commands with spaces and array arguments', async t => {

Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880

line 50why, one step back
50 const {stdout} = await execa('command with space.js', ['foo', 'bar']);

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

lines 51–53why, one step back
51 t.is(stdout, 'foo\nbar');
52});53

Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880

lines 54–55why, one step back
54test('execaCommand()', async t => {
55 const {stdout} = await execaCommand('node test/fixtures/echo.js foo bar');

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

lines 56–58why, one step back
56 t.is(stdout, 'foo\nbar');
57});58

Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880

lines 59–60why, one step back
59test('execaCommand() ignores consecutive spaces', async t => {
60 const {stdout} = await execaCommand('node test/fixtures/echo.js foo bar');

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

lines 61–63why, one step back
61 t.is(stdout, 'foo\nbar');
62});63

Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880

lines 64–65why, one step back
64test('execaCommand() allows escaping spaces in commands', async t => {
65 const {stdout} = await execaCommand('command\\ with\\ space.js foo bar');

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

lines 66–68why, one step back
66 t.is(stdout, 'foo\nbar');
67});68

Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880

lines 69–70why, one step back
69test('execaCommand() allows escaping spaces in arguments', async t => {
70 const {stdout} = await execaCommand('node test/fixtures/echo.js foo\\ bar');

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

lines 71–73why, one step back
71 t.is(stdout, 'foo bar');
72});73

Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880

lines 74–75why, one step back
74test('execaCommand() escapes other whitespaces', async t => {
75 const {stdout} = await execaCommand('node test/fixtures/echo.js foo\tbar');

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

lines 76–78why, one step back
76 t.is(stdout, 'foo\tbar');
77});78

Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880

lines 79–80why, one step back
79test('execaCommand() trims', async t => {
80 const {stdout} = await execaCommand(' node test/fixtures/echo.js foo bar ');

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

lines 81–83why, one step back
81 t.is(stdout, 'foo\nbar');
82});83

Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880

lines 84–85why, one step back
84test('execaCommandSync()', t => {
85 const {stdout} = execaCommandSync('node test/fixtures/echo.js foo bar');

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

lines 86–87why, one step back
86 t.is(stdout, 'foo\nbar');
87});