parameters-args.js
This file
Path
test/methods/parameters-args.js
47 lines · 2.1 KiB · JavaScript
Last changed by
TweaksSindre Sorhusbefore adoption698a1b8
History of this fileTake it
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748import test from 'node:test';import {assertThrows} from '../helpers/assert.js';import { execa, execaSync, execaNode, $,} from '../../index.js';import {setFixtureDirectory} from '../helpers/fixtures-directory.js';
setFixtureDirectory();
const testInvalidArguments = async execaMethod => { assertThrows(() => { execaMethod('echo', true); }, {message: /Second argument must be either/});};
test('execa()\'s second argument must be valid', () => testInvalidArguments(execa));test('execaSync()\'s second argument must be valid', () => testInvalidArguments(execaSync));test('execaNode()\'s second argument must be valid', () => testInvalidArguments(execaNode));test('$\'s second argument must be valid', () => testInvalidArguments($));test('$.sync\'s second argument must be valid', () => testInvalidArguments($.sync));
const testInvalidArgumentsItems = async execaMethod => { assertThrows(() => { execaMethod('echo', [{}]); }, {message: 'Second argument must be an array of strings: [object Object]'});};
test('execa()\'s second argument must not be objects', () => testInvalidArgumentsItems(execa));test('execaSync()\'s second argument must not be objects', () => testInvalidArgumentsItems(execaSync));test('execaNode()\'s second argument must not be objects', () => testInvalidArgumentsItems(execaNode));test('$\'s second argument must not be objects', () => testInvalidArgumentsItems($));test('$.sync\'s second argument must not be objects', () => testInvalidArgumentsItems($.sync));
const testNullByteArgument = async execaMethod => { assertThrows(() => { execaMethod('echo', ['a\0b']); }, {message: /null bytes/});};
test('execa()\'s second argument must not include \\0', () => testNullByteArgument(execa));test('execaSync()\'s second argument must not include \\0', () => testNullByteArgument(execaSync));test('execaNode()\'s second argument must not include \\0', () => testNullByteArgument(execaNode));test('$\'s second argument must not include \\0', () => testNullByteArgument($));test('$.sync\'s second argument must not include \\0', () => testNullByteArgument($.sync));