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 fileTake it
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586import {join} from 'node:path';import test from 'ava';import {execa, execaSync, execaNode, $} from '../../index.js';import {foobarString, foobarArray} from '../helpers/input.js';import {setFixtureDir, FIXTURES_DIR} from '../helpers/fixtures-dir.js';
setFixtureDir();const NOOP_PATH = join(FIXTURES_DIR, 'noop.js');
const testTemplate = async (t, execaMethod) => { const {stdout} = await execaMethod`${NOOP_PATH} ${foobarString}`; t.is(stdout, foobarString);};
test('execa() can use template strings', testTemplate, execa);test('execaNode() can use template strings', testTemplate, execaNode);test('$ can use template strings', testTemplate, $);
const testTemplateSync = (t, execaMethod) => { const {stdout} = execaMethod`${NOOP_PATH} ${foobarString}`; t.is(stdout, foobarString);};
test('execaSync() can use template strings', testTemplateSync, execaSync);test('$.sync can use template strings', testTemplateSync, $.sync);
const testTemplateOptions = async (t, execaMethod) => { const {stdout} = await execaMethod({stripFinalNewline: false})`${NOOP_PATH} ${foobarString}`; t.is(stdout, `${foobarString}\n`);};
test('execa() can use template strings with options', testTemplateOptions, execa);test('execaNode() can use template strings with options', testTemplateOptions, execaNode);test('$ can use template strings with options', testTemplateOptions, $);
const testTemplateOptionsSync = (t, execaMethod) => { const {stdout} = execaMethod({stripFinalNewline: false})`${NOOP_PATH} ${foobarString}`; t.is(stdout, `${foobarString}\n`);};
test('execaSync() can use template strings with options', testTemplateOptionsSync, execaSync);test('$.sync can use template strings with options', testTemplateOptionsSync, $.sync);
const testBindOptions = async (t, execaMethod) => { const {stdout} = await execaMethod({stripFinalNewline: false})(NOOP_PATH, [foobarString]); t.is(stdout, `${foobarString}\n`);};
test('execa() can bind options', testBindOptions, execa);test('execaNode() can bind options', testBindOptions, execaNode);test('$ can bind options', testBindOptions, $);
const testBindOptionsSync = (t, execaMethod) => { const {stdout} = execaMethod({stripFinalNewline: false})(NOOP_PATH, [foobarString]); t.is(stdout, `${foobarString}\n`);};
test('execaSync() can bind options', testBindOptionsSync, execaSync);test('$.sync can bind options', testBindOptionsSync, $.sync);
const testBindPriority = async (t, execaMethod) => { const {stdout} = await execaMethod({stripFinalNewline: false})(NOOP_PATH, [foobarString], {stripFinalNewline: true}); t.is(stdout, foobarString);};
test('execa() bound options have lower priority', testBindPriority, execa);test('execaSync() bound options have lower priority', testBindPriority, execaSync);test('execaNode() bound options have lower priority', testBindPriority, execaNode);test('$ bound options have lower priority', testBindPriority, $);test('$.sync bound options have lower priority', testBindPriority, $.sync);
const testSpacedCommand = async (t, args, execaMethod) => { const {stdout} = await execaMethod('command with space.js', args); const expectedStdout = args === undefined ? '' : args.join('\n'); t.is(stdout, expectedStdout);};
test('allow commands with spaces and no array arguments', testSpacedCommand, undefined, execa);test('allow commands with spaces and array arguments', testSpacedCommand, foobarArray, execa);test('allow commands with spaces and no array arguments, execaSync', testSpacedCommand, undefined, execaSync);test('allow commands with spaces and array arguments, execaSync', testSpacedCommand, foobarArray, execaSync);test('allow commands with spaces and no array arguments, $', testSpacedCommand, undefined, $);test('allow commands with spaces and array arguments, $', testSpacedCommand, foobarArray, $);test('allow commands with spaces and no array arguments, $.sync', testSpacedCommand, undefined, $.sync);test('allow commands with spaces and array arguments, $.sync', testSpacedCommand, foobarArray, $.sync);