Skip to content
Myr

create.js

This file

Path

test/arguments/create.js

85 lines · 4.0 KiB · JavaScript

Last changed by

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

History of this file

Take it

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

lines 1–85why, one step back
1import {join} from 'node:path';
2import test from 'ava';3import {execa, execaSync, execaNode, $} from '../../index.js';4import {foobarString, foobarArray} from '../helpers/input.js';5import {setFixtureDir, FIXTURES_DIR} from '../helpers/fixtures-dir.js';67setFixtureDir();8const NOOP_PATH = join(FIXTURES_DIR, 'noop.js');910const testTemplate = async (t, execaMethod) => {11 const {stdout} = await execaMethod`${NOOP_PATH} ${foobarString}`;12 t.is(stdout, foobarString);13};1415test('execa() can use template strings', testTemplate, execa);16test('execaNode() can use template strings', testTemplate, execaNode);17test('$ can use template strings', testTemplate, $);1819const testTemplateSync = (t, execaMethod) => {20 const {stdout} = execaMethod`${NOOP_PATH} ${foobarString}`;21 t.is(stdout, foobarString);22};2324test('execaSync() can use template strings', testTemplateSync, execaSync);25test('$.sync can use template strings', testTemplateSync, $.sync);2627const testTemplateOptions = async (t, execaMethod) => {28 const {stdout} = await execaMethod({stripFinalNewline: false})`${NOOP_PATH} ${foobarString}`;29 t.is(stdout, `${foobarString}\n`);30};3132test('execa() can use template strings with options', testTemplateOptions, execa);33test('execaNode() can use template strings with options', testTemplateOptions, execaNode);34test('$ can use template strings with options', testTemplateOptions, $);3536const testTemplateOptionsSync = (t, execaMethod) => {37 const {stdout} = execaMethod({stripFinalNewline: false})`${NOOP_PATH} ${foobarString}`;38 t.is(stdout, `${foobarString}\n`);39};4041test('execaSync() can use template strings with options', testTemplateOptionsSync, execaSync);42test('$.sync can use template strings with options', testTemplateOptionsSync, $.sync);4344const testBindOptions = async (t, execaMethod) => {45 const {stdout} = await execaMethod({stripFinalNewline: false})(NOOP_PATH, [foobarString]);46 t.is(stdout, `${foobarString}\n`);47};4849test('execa() can bind options', testBindOptions, execa);50test('execaNode() can bind options', testBindOptions, execaNode);51test('$ can bind options', testBindOptions, $);5253const testBindOptionsSync = (t, execaMethod) => {54 const {stdout} = execaMethod({stripFinalNewline: false})(NOOP_PATH, [foobarString]);55 t.is(stdout, `${foobarString}\n`);56};5758test('execaSync() can bind options', testBindOptionsSync, execaSync);59test('$.sync can bind options', testBindOptionsSync, $.sync);6061const testBindPriority = async (t, execaMethod) => {62 const {stdout} = await execaMethod({stripFinalNewline: false})(NOOP_PATH, [foobarString], {stripFinalNewline: true});63 t.is(stdout, foobarString);64};6566test('execa() bound options have lower priority', testBindPriority, execa);67test('execaSync() bound options have lower priority', testBindPriority, execaSync);68test('execaNode() bound options have lower priority', testBindPriority, execaNode);69test('$ bound options have lower priority', testBindPriority, $);70test('$.sync bound options have lower priority', testBindPriority, $.sync);7172const testSpacedCommand = async (t, args, execaMethod) => {73 const {stdout} = await execaMethod('command with space.js', args);74 const expectedStdout = args === undefined ? '' : args.join('\n');75 t.is(stdout, expectedStdout);76};7778test('allow commands with spaces and no array arguments', testSpacedCommand, undefined, execa);79test('allow commands with spaces and array arguments', testSpacedCommand, foobarArray, execa);80test('allow commands with spaces and no array arguments, execaSync', testSpacedCommand, undefined, execaSync);81test('allow commands with spaces and array arguments, execaSync', testSpacedCommand, foobarArray, execaSync);82test('allow commands with spaces and no array arguments, $', testSpacedCommand, undefined, $);83test('allow commands with spaces and array arguments, $', testSpacedCommand, foobarArray, $);84test('allow commands with spaces and no array arguments, $.sync', testSpacedCommand, undefined, $.sync);85test('allow commands with spaces and array arguments, $.sync', testSpacedCommand, foobarArray, $.sync);