parameters-command.js
This file
Path
test/methods/parameters-command.js
74 lines · 3.9 KiB · JavaScript
Last changed by
Remove `execaCommand()` and `execaCommandSync()` (#1244)Sindre Sorhusbefore adoption3ced394
History of this fileTake it
Upgrade dependencies (#1138)ehmickybefore adoptionabd9fd0
line 1why, one step back1import path from 'node:path';Rename files (#977)ehmickybefore adoption4b2e316
lines 2–3why, one step back2import {fileURLToPath} from 'node:url';3import test from 'ava';Upgrade xo (#980)ehmickybefore adoptionccfa412
lines 4–10why, one step back4import {5 execa,6 execaSync,7 execaNode,8 $,9} from '../../index.js';10import {setFixtureDirectory, FIXTURES_DIRECTORY_URL} from '../helpers/fixtures-directory.js';Rename files (#977)ehmickybefore adoption4b2e316
lines 11–12why, one step back11import {foobarString} from '../helpers/input.js';12Upgrade xo (#980)ehmickybefore adoptionccfa412
line 13why, one step back13setFixtureDirectory();Rename files (#977)ehmickybefore adoption4b2e316
lines 14–15why, one step back1415const testFileUrl = async (t, execaMethod) => {Upgrade xo (#980)ehmickybefore adoptionccfa412
line 16why, one step back16 const command = new URL('noop.js', FIXTURES_DIRECTORY_URL);Rename files (#977)ehmickybefore adoption4b2e316
lines 17–39why, one step back17 const {stdout} = await execaMethod(command);18 t.is(stdout, foobarString);19};2021test('execa()\'s command argument can be a file URL', testFileUrl, execa);22test('execaSync()\'s command argument can be a file URL', testFileUrl, execaSync);23test('execaNode()\'s command argument can be a file URL', testFileUrl, execaNode);24test('$\'s command argument can be a file URL', testFileUrl, $);25test('$.sync\'s command argument can be a file URL', testFileUrl, $.sync);2627const testInvalidFileUrl = async (t, execaMethod) => {28 const invalidUrl = new URL('https://invalid.com');29 t.throws(() => {30 execaMethod(invalidUrl);31 }, {code: 'ERR_INVALID_URL_SCHEME'});32};3334test('execa()\'s command argument cannot be a non-file URL', testInvalidFileUrl, execa);35test('execaSync()\'s command argument cannot be a non-file URL', testInvalidFileUrl, execaSync);36test('execaNode()\'s command argument cannot be a non-file URL', testInvalidFileUrl, execaNode);37test('$\'s command argument cannot be a non-file URL', testInvalidFileUrl, $);38test('$.sync\'s command argument cannot be a non-file URL', testInvalidFileUrl, $.sync);39Upgrade xo (#980)ehmickybefore adoptionccfa412
line 40why, one step back40const testInvalidCommand = async (t, commandArgument, execaMethod) => {Rename files (#977)ehmickybefore adoption4b2e316
line 41why, one step back41 t.throws(() => {Upgrade xo (#980)ehmickybefore adoptionccfa412
line 42why, one step back42 execaMethod(commandArgument);Rename files (#977)ehmickybefore adoption4b2e316
lines 43–62why, one step back43 }, {message: /First argument must be a string or a file URL/});44};4546test('execa()\'s first argument must be defined', testInvalidCommand, undefined, execa);47test('execaSync()\'s first argument must be defined', testInvalidCommand, undefined, execaSync);48test('execaNode()\'s first argument must be defined', testInvalidCommand, undefined, execaNode);49test('$\'s first argument must be defined', testInvalidCommand, undefined, $);50test('$.sync\'s first argument must be defined', testInvalidCommand, undefined, $.sync);51test('execa()\'s first argument must be valid', testInvalidCommand, true, execa);52test('execaSync()\'s first argument must be valid', testInvalidCommand, true, execaSync);53test('execaNode()\'s first argument must be valid', testInvalidCommand, true, execaNode);54test('$\'s first argument must be valid', testInvalidCommand, true, $);55test('$.sync\'s first argument must be valid', testInvalidCommand, true, $.sync);56test('execa()\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], execa);57test('execaSync()\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], execaSync);58test('execaNode()\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], execaNode);59test('$\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], $);60test('$.sync\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], $.sync);6162const testRelativePath = async (t, execaMethod) => {Add more code comments (#984)ehmickybefore adoptionfdd8a9f
line 63why, one step back63 // @todo: use import.meta.dirname after dropping support for Node <20.11.0Upgrade dependencies (#1138)ehmickybefore adoptionabd9fd0
lines 64–65why, one step back64 const rootDirectory = path.basename(fileURLToPath(new URL('../..', import.meta.url)));65 const pathViaParentDirectory = path.join('..', rootDirectory, 'test', 'fixtures', 'noop.js');Upgrade xo (#980)ehmickybefore adoptionccfa412
line 66why, one step back66 const {stdout} = await execaMethod(pathViaParentDirectory);Rename files (#977)ehmickybefore adoption4b2e316
lines 67–74why, one step back67 t.is(stdout, foobarString);68};6970test('execa() use relative path with \'..\' chars', testRelativePath, execa);71test('execaSync() use relative path with \'..\' chars', testRelativePath, execaSync);72test('execaNode() use relative path with \'..\' chars', testRelativePath, execaNode);73test('$ use relative path with \'..\' chars', testRelativePath, $);74test('$.sync use relative path with \'..\' chars', testRelativePath, $.sync);