command.js
This file
Path
test/command.js
89 lines · 3.0 KiB · JavaScript
Last changed by
Meta tweaksSindre Sorhusbefore adoption5bac052
History of this fileTake it
Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
lines 1–3why, one step back1import 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 back4import test from 'ava';Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 5why, one step back5import {execa, execaSync, execaCommand, execaCommandSync} from '../index.js';Separate command-related logic into its own file (#329)ehmickybefore adoption46daa7b
line 6why, one step back6Meta tweaksSindre Sorhusbefore adoption5bac052
line 7why, one step back7process.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 back89const command = async (t, expected, ...args) => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
lines 10–11why, one step back10 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 back12Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
lines 13–14why, one step back13 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 back15};1617command.title = (message, expected) => `command is: ${JSON.stringify(expected)}`;1819test(command, ' foo bar', 'foo', 'bar');20test(command, ' baz quz', 'baz', 'quz');21test(command, '');22Add `.escapedCommand` property (#466)ehmickybefore adoption712bafc
line 23why, one step back23const testEscapedCommand = async (t, expected, args) => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
lines 24–25why, one step back24 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 back2627 const {escapedCommand: failEscapedCommandSync} = t.throws(() => {Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 28why, one step back28 execaSync('fail.js', args);Add `.escapedCommand` property (#466)ehmickybefore adoption712bafc
line 29why, one step back29 });Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 30why, one step back30 t.is(failEscapedCommandSync, `fail.js ${expected}`);Add `.escapedCommand` property (#466)ehmickybefore adoption712bafc
line 31why, one step back31Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
lines 32–33why, one step back32 const {escapedCommand} = await execa('noop.js', args);33 t.is(escapedCommand, `noop.js ${expected}`);Add `.escapedCommand` property (#466)ehmickybefore adoption712bafc
line 34why, one step back34Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
lines 35–36why, one step back35 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 back37};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, '"*"', ['*']);45Separate command-related logic into its own file (#329)ehmickybefore adoption46daa7b
line 46why, one step back46test('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 back47 const {stdout} = await execa('command with space.js');Separate command-related logic into its own file (#329)ehmickybefore adoption46daa7b
lines 48–51why, one step back48 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 back52 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 back53 t.is(stdout, 'foo\nbar');54});55Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
lines 56–57why, one step back56test('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 back58 t.is(stdout, 'foo\nbar');59});60Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
lines 61–62why, one step back61test('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 back63 t.is(stdout, 'foo\nbar');64});65Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
lines 66–67why, one step back66test('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 back68 t.is(stdout, 'foo\nbar');69});70Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
lines 71–72why, one step back71test('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 back73 t.is(stdout, 'foo bar');74});75Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
lines 76–77why, one step back76test('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 back78 t.is(stdout, 'foo\tbar');79});80Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
lines 81–82why, one step back81test('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 back83 t.is(stdout, 'foo\nbar');84});85Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
lines 86–87why, one step back86test('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 back88 t.is(stdout, 'foo\nbar');89});