Skip to content
Myr

create.js

This file

Path

test/methods/create.js

64 lines · 3.0 KiB · JavaScript

Last changed by

TweaksSindre Sorhusbefore adoption698a1b8

History of this file

Take it

TweaksSindre Sorhusbefore adoption698a1b8

line 1why, one step back
1import assert from 'node:assert/strict';

Upgrade dependencies (#1138)ehmickybefore adoptionabd9fd0

line 2why, one step back
2import path from 'node:path';

TweaksSindre Sorhusbefore adoption698a1b8

line 3why, one step back
3import test from 'node:test';

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

lines 4–14why, one step back
4import {
5 execa,6 execaSync,7 execaNode,8 $,9} from '../../index.js';10import {foobarString, foobarArray} from '../helpers/input.js';11import {setFixtureDirectory, FIXTURES_DIRECTORY} from '../helpers/fixtures-directory.js';1213setFixtureDirectory();14

Upgrade dependencies (#1138)ehmickybefore adoptionabd9fd0

line 15why, one step back
15const NOOP_PATH = path.join(FIXTURES_DIRECTORY, 'noop.js');

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

line 16why, one step back
16

TweaksSindre Sorhusbefore adoption698a1b8

line 17why, one step back
17const testTemplate = async execaMethod => {

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

line 18why, one step back
18 const {stdout} = await execaMethod`${NOOP_PATH} ${foobarString}`;

TweaksSindre Sorhusbefore adoption698a1b8

line 19why, one step back
19 assert.equal(stdout, foobarString);

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

lines 20–21why, one step back
20};
21

TweaksSindre Sorhusbefore adoption698a1b8

lines 22–24why, one step back
22test('execa() can use template strings', () => testTemplate(execa));
23test('execaNode() can use template strings', () => testTemplate(execaNode));24test('$ can use template strings', () => testTemplate($));

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

line 25why, one step back
25

TweaksSindre Sorhusbefore adoption698a1b8

line 26why, one step back
26const testTemplateSync = execaMethod => {

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

line 27why, one step back
27 const {stdout} = execaMethod`${NOOP_PATH} ${foobarString}`;

TweaksSindre Sorhusbefore adoption698a1b8

line 28why, one step back
28 assert.equal(stdout, foobarString);

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

lines 29–30why, one step back
29};
30

TweaksSindre Sorhusbefore adoption698a1b8

lines 31–32why, one step back
31test('execaSync() can use template strings', () => testTemplateSync(execaSync));
32test('$.sync can use template strings', () => testTemplateSync($.sync));

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

line 33why, one step back
33

TweaksSindre Sorhusbefore adoption698a1b8

line 34why, one step back
34const testTemplateOptions = async execaMethod => {

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

line 35why, one step back
35 const {stdout} = await execaMethod({stripFinalNewline: false})`${NOOP_PATH} ${foobarString}`;

TweaksSindre Sorhusbefore adoption698a1b8

line 36why, one step back
36 assert.equal(stdout, `${foobarString}\n`);

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

lines 37–38why, one step back
37};
38

TweaksSindre Sorhusbefore adoption698a1b8

lines 39–41why, one step back
39test('execa() can use template strings with options', () => testTemplateOptions(execa));
40test('execaNode() can use template strings with options', () => testTemplateOptions(execaNode));41test('$ can use template strings with options', () => testTemplateOptions($));

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

line 42why, one step back
42

TweaksSindre Sorhusbefore adoption698a1b8

line 43why, one step back
43const testTemplateOptionsSync = execaMethod => {

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

line 44why, one step back
44 const {stdout} = execaMethod({stripFinalNewline: false})`${NOOP_PATH} ${foobarString}`;

TweaksSindre Sorhusbefore adoption698a1b8

line 45why, one step back
45 assert.equal(stdout, `${foobarString}\n`);

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

lines 46–47why, one step back
46};
47

TweaksSindre Sorhusbefore adoption698a1b8

lines 48–49why, one step back
48test('execaSync() can use template strings with options', () => testTemplateOptionsSync(execaSync));
49test('$.sync can use template strings with options', () => testTemplateOptionsSync($.sync));

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

line 50why, one step back
50

TweaksSindre Sorhusbefore adoption698a1b8

line 51why, one step back
51const testSpacedCommand = async (commandArguments, execaMethod) => {

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

lines 52–53why, one step back
52 const {stdout} = await execaMethod('command with space.js', commandArguments);
53 const expectedStdout = commandArguments === undefined ? '' : commandArguments.join('\n');

TweaksSindre Sorhusbefore adoption698a1b8

line 54why, one step back
54 assert.equal(stdout, expectedStdout);

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

lines 55–56why, one step back
55};
56

TweaksSindre Sorhusbefore adoption698a1b8

lines 57–64why, one step back
57test('allow commands with spaces and no array arguments', () => testSpacedCommand(undefined, execa));
58test('allow commands with spaces and array arguments', () => testSpacedCommand(foobarArray, execa));59test('allow commands with spaces and no array arguments, execaSync', () => testSpacedCommand(undefined, execaSync));60test('allow commands with spaces and array arguments, execaSync', () => testSpacedCommand(foobarArray, execaSync));61test('allow commands with spaces and no array arguments, $', () => testSpacedCommand(undefined, $));62test('allow commands with spaces and array arguments, $', () => testSpacedCommand(foobarArray, $));63test('allow commands with spaces and no array arguments, $.sync', () => testSpacedCommand(undefined, $.sync));64test('allow commands with spaces and array arguments, $.sync', () => testSpacedCommand(foobarArray, $.sync));