Skip to content
Myr

create.js

This file

Path

test/methods/create.js

63 lines · 2.8 KiB · JavaScript

Last changed by

Refactor logic and rename some variables (#983)ehmickybefore adoptionbd3b478

History of this file

Take it

Refactor logic and rename some variables (#983)ehmickybefore adoptionbd3b478

lines 1–63why, one step back
1import {join} from 'node:path';
2import test from 'ava';3import {4 execa,5 execaSync,6 execaNode,7 $,8} from '../../index.js';9import {foobarString, foobarArray} from '../helpers/input.js';10import {setFixtureDirectory, FIXTURES_DIRECTORY} from '../helpers/fixtures-directory.js';1112setFixtureDirectory();1314const NOOP_PATH = join(FIXTURES_DIRECTORY, 'noop.js');1516const testTemplate = async (t, execaMethod) => {17 const {stdout} = await execaMethod`${NOOP_PATH} ${foobarString}`;18 t.is(stdout, foobarString);19};2021test('execa() can use template strings', testTemplate, execa);22test('execaNode() can use template strings', testTemplate, execaNode);23test('$ can use template strings', testTemplate, $);2425const testTemplateSync = (t, execaMethod) => {26 const {stdout} = execaMethod`${NOOP_PATH} ${foobarString}`;27 t.is(stdout, foobarString);28};2930test('execaSync() can use template strings', testTemplateSync, execaSync);31test('$.sync can use template strings', testTemplateSync, $.sync);3233const testTemplateOptions = async (t, execaMethod) => {34 const {stdout} = await execaMethod({stripFinalNewline: false})`${NOOP_PATH} ${foobarString}`;35 t.is(stdout, `${foobarString}\n`);36};3738test('execa() can use template strings with options', testTemplateOptions, execa);39test('execaNode() can use template strings with options', testTemplateOptions, execaNode);40test('$ can use template strings with options', testTemplateOptions, $);4142const testTemplateOptionsSync = (t, execaMethod) => {43 const {stdout} = execaMethod({stripFinalNewline: false})`${NOOP_PATH} ${foobarString}`;44 t.is(stdout, `${foobarString}\n`);45};4647test('execaSync() can use template strings with options', testTemplateOptionsSync, execaSync);48test('$.sync can use template strings with options', testTemplateOptionsSync, $.sync);4950const testSpacedCommand = async (t, commandArguments, execaMethod) => {51 const {stdout} = await execaMethod('command with space.js', commandArguments);52 const expectedStdout = commandArguments === undefined ? '' : commandArguments.join('\n');53 t.is(stdout, expectedStdout);54};5556test('allow commands with spaces and no array arguments', testSpacedCommand, undefined, execa);57test('allow commands with spaces and array arguments', testSpacedCommand, foobarArray, execa);58test('allow commands with spaces and no array arguments, execaSync', testSpacedCommand, undefined, execaSync);59test('allow commands with spaces and array arguments, execaSync', testSpacedCommand, foobarArray, execaSync);60test('allow commands with spaces and no array arguments, $', testSpacedCommand, undefined, $);61test('allow commands with spaces and array arguments, $', testSpacedCommand, foobarArray, $);62test('allow commands with spaces and no array arguments, $.sync', testSpacedCommand, undefined, $.sync);63test('allow commands with spaces and array arguments, $.sync', testSpacedCommand, foobarArray, $.sync);