Skip to content
Myr

command.js

This file

Path

test/methods/command.js

112 lines · 4.0 KiB · JavaScript

Last changed by

Upgrade xo (#980)ehmickybefore adoptionccfa412

History of this file

Take it

Rename files (#977)ehmickybefore adoption4b2e316

lines 1–3why, one step back
1import {join} from 'node:path';
2import test from 'ava';3import {execaCommand, execaCommandSync} from '../../index.js';

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 4why, one step back
4import {setFixtureDirectory, FIXTURES_DIRECTORY} from '../helpers/fixtures-directory.js';

Rename files (#977)ehmickybefore adoption4b2e316

lines 5–6why, one step back
5import {QUOTE} from '../helpers/verbose.js';
6

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 7–8why, one step back
7setFixtureDirectory();
8const STDIN_FIXTURE = join(FIXTURES_DIRECTORY, 'stdin.js');

Rename files (#977)ehmickybefore adoption4b2e316

lines 9–94why, one step back
9
10test('execaCommand()', async t => {11 const {stdout} = await execaCommand('echo.js foo bar');12 t.is(stdout, 'foo\nbar');13});1415test('execaCommandSync()', t => {16 const {stdout} = execaCommandSync('echo.js foo bar');17 t.is(stdout, 'foo\nbar');18});1920test('execaCommand`...`', async t => {21 const {stdout} = await execaCommand`${'echo.js foo bar'}`;22 t.is(stdout, 'foo\nbar');23});2425test('execaCommandSync`...`', t => {26 const {stdout} = execaCommandSync`${'echo.js foo bar'}`;27 t.is(stdout, 'foo\nbar');28});2930test('execaCommand(options)`...`', async t => {31 const {stdout} = await execaCommand({stripFinalNewline: false})`${'echo.js foo bar'}`;32 t.is(stdout, 'foo\nbar\n');33});3435test('execaCommandSync(options)`...`', t => {36 const {stdout} = execaCommandSync({stripFinalNewline: false})`${'echo.js foo bar'}`;37 t.is(stdout, 'foo\nbar\n');38});3940test('execaCommand(options)()', async t => {41 const {stdout} = await execaCommand({stripFinalNewline: false})('echo.js foo bar');42 t.is(stdout, 'foo\nbar\n');43});4445test('execaCommandSync(options)()', t => {46 const {stdout} = execaCommandSync({stripFinalNewline: false})('echo.js foo bar');47 t.is(stdout, 'foo\nbar\n');48});4950test('execaCommand().pipe(execaCommand())', async t => {51 const {stdout} = await execaCommand('echo.js foo bar').pipe(execaCommand(`node ${STDIN_FIXTURE}`));52 t.is(stdout, 'foo\nbar');53});5455test('execaCommand().pipe(...) does not use execaCommand', async t => {56 const {escapedCommand} = await execaCommand('echo.js foo bar').pipe(`node ${STDIN_FIXTURE}`, {reject: false});57 t.true(escapedCommand.startsWith(`${QUOTE}node `));58});5960test('execaCommand() bound options have lower priority', async t => {61 const {stdout} = await execaCommand({stripFinalNewline: false})('echo.js foo bar', {stripFinalNewline: true});62 t.is(stdout, 'foo\nbar');63});6465test('execaCommandSync() bound options have lower priority', t => {66 const {stdout} = execaCommandSync({stripFinalNewline: false})('echo.js foo bar', {stripFinalNewline: true});67 t.is(stdout, 'foo\nbar');68});6970test('execaCommand() ignores consecutive spaces', async t => {71 const {stdout} = await execaCommand('echo.js foo bar');72 t.is(stdout, 'foo\nbar');73});7475test('execaCommand() allows escaping spaces in commands', async t => {76 const {stdout} = await execaCommand('command\\ with\\ space.js foo bar');77 t.is(stdout, 'foo\nbar');78});7980test('execaCommand() allows escaping spaces in arguments', async t => {81 const {stdout} = await execaCommand('echo.js foo\\ bar');82 t.is(stdout, 'foo bar');83});8485test('execaCommand() escapes other whitespaces', async t => {86 const {stdout} = await execaCommand('echo.js foo\tbar');87 t.is(stdout, 'foo\tbar');88});8990test('execaCommand() trims', async t => {91 const {stdout} = await execaCommand(' echo.js foo bar ');92 t.is(stdout, 'foo\nbar');93});94

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 95why, one step back
95const testInvalidArgumentsArray = (t, execaMethod) => {

Rename files (#977)ehmickybefore adoption4b2e316

lines 96–100why, one step back
96 t.throws(() => {
97 execaMethod('echo', ['foo']);98 }, {message: /The command and its arguments must be passed as a single string/});99};100

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 101–102why, one step back
101test('execaCommand() must not pass an array of arguments', testInvalidArgumentsArray, execaCommand);
102test('execaCommandSync() must not pass an array of arguments', testInvalidArgumentsArray, execaCommandSync);

Rename files (#977)ehmickybefore adoption4b2e316

line 103why, one step back
103

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 104why, one step back
104const testInvalidArgumentsTemplate = (t, execaMethod) => {

Rename files (#977)ehmickybefore adoption4b2e316

lines 105–110why, one step back
105 t.throws(() => {
106 // eslint-disable-next-line no-unused-expressions107 execaMethod`echo foo`;108 }, {message: /The command and its arguments must be passed as a single string/});109};110

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 111–112why, one step back
111test('execaCommand() must not pass an array of arguments with a template string', testInvalidArgumentsTemplate, execaCommand);
112test('execaCommandSync() must not pass an array of arguments with a template string', testInvalidArgumentsTemplate, execaCommandSync);