Skip to content
Myr

command.js

This file

Path

test/command.js

89 lines · 3.0 KiB · JavaScript

Last changed by

Meta tweaksSindre Sorhusbefore adoption5bac052

History of this file

Take it

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

lines 1–3why, one step back
1import path from 'node:path';
2import process from 'node:process';3import {fileURLToPath} from 'node:url';

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

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

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

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

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

line 6why, one step back
6

Meta tweaksSindre Sorhusbefore adoption5bac052

line 7why, one step back
7process.env.PATH = fileURLToPath(new URL('fixtures', import.meta.url)) + path.delimiter + process.env.PATH;

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

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

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

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

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

line 12why, one step back
12

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

line 31why, one step back
31

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

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

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

line 34why, one step back
34

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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