parameters-command.js
This file
Path
test/methods/parameters-command.js
80 lines · 5.0 KiB · JavaScript
Last changed by
Rename files (#977)ehmickybefore adoption4b2e316
History of this fileTake it
Rename files (#977)ehmickybefore adoption4b2e316
lines 1–80why, one step back1import {join, basename} from 'node:path';2import {fileURLToPath} from 'node:url';3import test from 'ava';4import {execa, execaSync, execaCommand, execaCommandSync, execaNode, $} from '../../index.js';5import {setFixtureDir, FIXTURES_DIR_URL} from '../helpers/fixtures-dir.js';6import {foobarString} from '../helpers/input.js';78setFixtureDir();910const testFileUrl = async (t, execaMethod) => {11 const command = new URL('noop.js', FIXTURES_DIR_URL);12 const {stdout} = await execaMethod(command);13 t.is(stdout, foobarString);14};1516test('execa()\'s command argument can be a file URL', testFileUrl, execa);17test('execaSync()\'s command argument can be a file URL', testFileUrl, execaSync);18test('execaCommand()\'s command argument can be a file URL', testFileUrl, execaCommand);19test('execaCommandSync()\'s command argument can be a file URL', testFileUrl, execaCommandSync);20test('execaNode()\'s command argument can be a file URL', testFileUrl, execaNode);21test('$\'s command argument can be a file URL', testFileUrl, $);22test('$.sync\'s command argument can be a file URL', testFileUrl, $.sync);2324const testInvalidFileUrl = async (t, execaMethod) => {25 const invalidUrl = new URL('https://invalid.com');26 t.throws(() => {27 execaMethod(invalidUrl);28 }, {code: 'ERR_INVALID_URL_SCHEME'});29};3031test('execa()\'s command argument cannot be a non-file URL', testInvalidFileUrl, execa);32test('execaSync()\'s command argument cannot be a non-file URL', testInvalidFileUrl, execaSync);33test('execaCommand()\'s command argument cannot be a non-file URL', testInvalidFileUrl, execaCommand);34test('execaCommandSync()\'s command argument cannot be a non-file URL', testInvalidFileUrl, execaCommandSync);35test('execaNode()\'s command argument cannot be a non-file URL', testInvalidFileUrl, execaNode);36test('$\'s command argument cannot be a non-file URL', testInvalidFileUrl, $);37test('$.sync\'s command argument cannot be a non-file URL', testInvalidFileUrl, $.sync);3839const testInvalidCommand = async (t, arg, execaMethod) => {40 t.throws(() => {41 execaMethod(arg);42 }, {message: /First argument must be a string or a file URL/});43};4445test('execa()\'s first argument must be defined', testInvalidCommand, undefined, execa);46test('execaSync()\'s first argument must be defined', testInvalidCommand, undefined, execaSync);47test('execaCommand()\'s first argument must be defined', testInvalidCommand, undefined, execaCommand);48test('execaCommandSync()\'s first argument must be defined', testInvalidCommand, undefined, execaCommandSync);49test('execaNode()\'s first argument must be defined', testInvalidCommand, undefined, execaNode);50test('$\'s first argument must be defined', testInvalidCommand, undefined, $);51test('$.sync\'s first argument must be defined', testInvalidCommand, undefined, $.sync);52test('execa()\'s first argument must be valid', testInvalidCommand, true, execa);53test('execaSync()\'s first argument must be valid', testInvalidCommand, true, execaSync);54test('execaCommand()\'s first argument must be valid', testInvalidCommand, true, execaCommand);55test('execaCommandSync()\'s first argument must be valid', testInvalidCommand, true, execaCommandSync);56test('execaNode()\'s first argument must be valid', testInvalidCommand, true, execaNode);57test('$\'s first argument must be valid', testInvalidCommand, true, $);58test('$.sync\'s first argument must be valid', testInvalidCommand, true, $.sync);59test('execa()\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], execa);60test('execaSync()\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], execaSync);61test('execaCommand()\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], execaCommand);62test('execaCommandSync()\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], execaCommandSync);63test('execaNode()\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], execaNode);64test('$\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], $);65test('$.sync\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], $.sync);6667const testRelativePath = async (t, execaMethod) => {68 const rootDir = basename(fileURLToPath(new URL('../..', import.meta.url)));69 const pathViaParentDir = join('..', rootDir, 'test', 'fixtures', 'noop.js');70 const {stdout} = await execaMethod(pathViaParentDir);71 t.is(stdout, foobarString);72};7374test('execa() use relative path with \'..\' chars', testRelativePath, execa);75test('execaSync() use relative path with \'..\' chars', testRelativePath, execaSync);76test('execaCommand() use relative path with \'..\' chars', testRelativePath, execaCommand);77test('execaCommandSync() use relative path with \'..\' chars', testRelativePath, execaCommandSync);78test('execaNode() use relative path with \'..\' chars', testRelativePath, execaNode);79test('$ use relative path with \'..\' chars', testRelativePath, $);80test('$.sync use relative path with \'..\' chars', testRelativePath, $.sync);