Skip to content
Myr

parameters-options.js

This file

Path

test/methods/parameters-options.js

159 lines · 9.8 KiB · JavaScript

Last changed by

Fix `execaNode()` and the `node` option missing IPC in their typesSindre Sorhusbefore adoption2633abb

History of this file

Take it

The walk stopped after 200 commits: lines older than 9f65b86 point at 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

lines 3–4why, one step back
3import test from 'node:test';
4import {assertThrows} from '../helpers/assert.js';

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 5–14why, one step back
5import {
6 execa,7 execaSync,8 execaNode,9 $,10} from '../../index.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');

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 16why, one step back
16

TweaksSindre Sorhusbefore adoption698a1b8

line 17why, one step back
17const testSerializeArgument = async (commandArgument, execaMethod) => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 18why, one step back
18 const {stdout} = await execaMethod(NOOP_PATH, [commandArgument]);

TweaksSindre Sorhusbefore adoption698a1b8

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

100% test coverage (#1018)ehmickybefore adoption9f65b86

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

TweaksSindre Sorhusbefore adoption698a1b8

lines 22–61why, one step back
22test('execa()\'s arguments can be numbers', () => testSerializeArgument(1, execa));
23test('execa()\'s arguments can be booleans', () => testSerializeArgument(true, execa));24test('execa()\'s arguments can be NaN', () => testSerializeArgument(NaN, execa));25test('execa()\'s arguments can be Infinity', () => testSerializeArgument(Infinity, execa));26test('execa()\'s arguments can be null', () => testSerializeArgument(null, execa));27test('execa()\'s arguments can be undefined', () => testSerializeArgument(undefined, execa));28test('execa()\'s arguments can be bigints', () => testSerializeArgument(1n, execa));29test('execa()\'s arguments can be symbols', () => testSerializeArgument(Symbol('test'), execa));30test('execaSync()\'s arguments can be numbers', () => testSerializeArgument(1, execaSync));31test('execaSync()\'s arguments can be booleans', () => testSerializeArgument(true, execaSync));32test('execaSync()\'s arguments can be NaN', () => testSerializeArgument(NaN, execaSync));33test('execaSync()\'s arguments can be Infinity', () => testSerializeArgument(Infinity, execaSync));34test('execaSync()\'s arguments can be null', () => testSerializeArgument(null, execaSync));35test('execaSync()\'s arguments can be undefined', () => testSerializeArgument(undefined, execaSync));36test('execaSync()\'s arguments can be bigints', () => testSerializeArgument(1n, execaSync));37test('execaSync()\'s arguments can be symbols', () => testSerializeArgument(Symbol('test'), execaSync));38test('execaNode()\'s arguments can be numbers', () => testSerializeArgument(1, execaNode));39test('execaNode()\'s arguments can be booleans', () => testSerializeArgument(true, execaNode));40test('execaNode()\'s arguments can be NaN', () => testSerializeArgument(NaN, execaNode));41test('execaNode()\'s arguments can be Infinity', () => testSerializeArgument(Infinity, execaNode));42test('execaNode()\'s arguments can be null', () => testSerializeArgument(null, execaNode));43test('execaNode()\'s arguments can be undefined', () => testSerializeArgument(undefined, execaNode));44test('execaNode()\'s arguments can be bigints', () => testSerializeArgument(1n, execaNode));45test('execaNode()\'s arguments can be symbols', () => testSerializeArgument(Symbol('test'), execaNode));46test('$\'s arguments can be numbers', () => testSerializeArgument(1, $));47test('$\'s arguments can be booleans', () => testSerializeArgument(true, $));48test('$\'s arguments can be NaN', () => testSerializeArgument(NaN, $));49test('$\'s arguments can be Infinity', () => testSerializeArgument(Infinity, $));50test('$\'s arguments can be null', () => testSerializeArgument(null, $));51test('$\'s arguments can be undefined', () => testSerializeArgument(undefined, $));52test('$\'s arguments can be bigints', () => testSerializeArgument(1n, $));53test('$\'s arguments can be symbols', () => testSerializeArgument(Symbol('test'), $));54test('$.sync\'s arguments can be numbers', () => testSerializeArgument(1, $.sync));55test('$.sync\'s arguments can be booleans', () => testSerializeArgument(true, $.sync));56test('$.sync\'s arguments can be NaN', () => testSerializeArgument(NaN, $.sync));57test('$.sync\'s arguments can be Infinity', () => testSerializeArgument(Infinity, $.sync));58test('$.sync\'s arguments can be null', () => testSerializeArgument(null, $.sync));59test('$.sync\'s arguments can be undefined', () => testSerializeArgument(undefined, $.sync));60test('$.sync\'s arguments can be bigints', () => testSerializeArgument(1n, $.sync));61test('$.sync\'s arguments can be symbols', () => testSerializeArgument(Symbol('test'), $.sync));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 62why, one step back
62

TweaksSindre Sorhusbefore adoption698a1b8

lines 63–64why, one step back
63const testInvalidOptions = async execaMethod => {
64 assertThrows(() => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 65–68why, one step back
65 execaMethod('echo', [], new Map());
66 }, {message: /Last argument must be an options object/});67};68

Fix wrong-typed options and arguments being silently ignored or coercedSindre Sorhusbefore adoptionb57d643

lines 69–89why, one step back
69const testTwoOptionsObjects = execaMethod => {
70 assertThrows(() => {71 execaMethod('echo', {all: true}, {timeout: 1});72 }, {message: /Please merge the second and third arguments/});73};7475test('execa() rejects two options objects', () => testTwoOptionsObjects(execa));76test('execaSync() rejects two options objects', () => testTwoOptionsObjects(execaSync));77test('execaNode() rejects two options objects', () => testTwoOptionsObjects(execaNode));78test('$ rejects two options objects', () => testTwoOptionsObjects($));79test('$.sync rejects two options objects', () => testTwoOptionsObjects($.sync));8081const testFourthArgument = execaMethod => {82 assertThrows(() => {83 execaMethod('echo', ['foo'], {}, {});84 }, {message: /at most three arguments/});85};8687test('execa() rejects a fourth argument', () => testFourthArgument(execa));88test('execaSync() rejects a fourth argument', () => testFourthArgument(execaSync));89

TweaksSindre Sorhusbefore adoption698a1b8

lines 90–94why, one step back
90test('execa()\'s third argument must be a plain object', () => testInvalidOptions(execa));
91test('execaSync()\'s third argument must be a plain object', () => testInvalidOptions(execaSync));92test('execaNode()\'s third argument must be a plain object', () => testInvalidOptions(execaNode));93test('$\'s third argument must be a plain object', () => testInvalidOptions($));94test('$.sync\'s third argument must be a plain object', () => testInvalidOptions($.sync));

Fix wrong-typed options and arguments being silently ignored or coercedSindre Sorhusbefore adoptionb57d643

lines 95–129why, one step back
95
96const testInvalidFdSpecificOption = (execaMethod, optionName, optionValue, fdName = 'stdout') => {97 assertThrows(() => {98 execaMethod('noop.js', {[optionName]: {[fdName]: optionValue}});99 }, {instanceOf: TypeError, message: `The \`${optionName}.${fdName}\` option must use ${optionName === 'maxBuffer' ? 'a number' : 'a boolean'}.`});100};101102test('The "lines.stdout" option must be a boolean', () => testInvalidFdSpecificOption(execa, 'lines', 'true'));103test('The "buffer.stdout" option must be a boolean', () => testInvalidFdSpecificOption(execa, 'buffer', 'false'));104test('The "stripFinalNewline.stdout" option must be a boolean', () => testInvalidFdSpecificOption(execa, 'stripFinalNewline', 1));105test('The "maxBuffer.stdout" option must be a number', () => testInvalidFdSpecificOption(execa, 'maxBuffer', '1024'));106test('The "maxBuffer.stdout" option must not be NaN', () => testInvalidFdSpecificOption(execa, 'maxBuffer', NaN));107test('The "maxBuffer.stderr" option must be a number - sync', () => testInvalidFdSpecificOption(execaSync, 'maxBuffer', '1024', 'stderr'));108test('The "lines.all" option is reported as "lines.all"', () => testInvalidFdSpecificOption(execa, 'lines', 'true', 'all'));109test('The "buffer.ipc" option is reported as "buffer.ipc"', () => testInvalidFdSpecificOption(execaNode, 'buffer', 'false', 'ipc'));110111const testInfiniteMaxBuffer = async (execaMethod, maxBuffer) => {112 const {stdout} = await execaMethod('noop.js', ['.'.repeat(10)], {maxBuffer});113 assert.equal(stdout, '.'.repeat(10));114};115116test('The "maxBuffer" option can be Infinity', () => testInfiniteMaxBuffer(execa, Infinity));117test('The "maxBuffer" option can be Infinity - sync', () => testInfiniteMaxBuffer(execaSync, Infinity));118test('The "maxBuffer.stdout" option can be Infinity', () => testInfiniteMaxBuffer(execa, {stdout: Infinity}));119120const testInvalidBooleanOption = (execaMethod, optionName, optionValue) => {121 assertThrows(() => {122 execaMethod('noop.js', {[optionName]: optionValue});123 }, {instanceOf: TypeError, message: `The \`${optionName}\` option must use a boolean.`});124};125126test('The "all" option must use a boolean', () => testInvalidBooleanOption(execa, 'all', 'false'));127test('The "reject" option must use a boolean', () => testInvalidBooleanOption(execa, 'reject', 'no'));128test('The "cleanup" option must use a boolean', () => testInvalidBooleanOption(execa, 'cleanup', 'false'));129test('The "ipc" option must use a boolean', () => testInvalidBooleanOption(execa, 'ipc', 'yes'));

Fix `execaNode()` and the `node` option missing IPC in their typesSindre Sorhusbefore adoption2633abb

line 130why, one step back
130test('The "ipc" option must use a boolean - execaNode()', () => testInvalidBooleanOption(execaNode, 'ipc', null));

Fix wrong-typed options and arguments being silently ignored or coercedSindre Sorhusbefore adoptionb57d643

lines 131–159why, one step back
131test('The "extendEnv" option must use a boolean', () => testInvalidBooleanOption(execa, 'extendEnv', 'false'));
132test('The "preferLocal" option must use a boolean', () => testInvalidBooleanOption(execa, 'preferLocal', 1));133test('The "node" option must use a boolean', () => testInvalidBooleanOption(execa, 'node', 'yes'));134test('The "gracefulCancel" option must use a boolean', () => testInvalidBooleanOption(execa, 'gracefulCancel', 'yes'));135test('The "node" option must use a boolean - sync', () => testInvalidBooleanOption(execaSync, 'node', 'yes'));136137const testInvalidEnv = (execaMethod, env) => {138 assertThrows(() => {139 execaMethod('noop.js', {env});140 }, {instanceOf: TypeError, message: `The \`env\` option must be an object: ${String(env)}.`});141};142143test('The "env" option must be an object', () => testInvalidEnv(execa, 'PATH=/bin'));144test('The "env" option must be an object - sync', () => testInvalidEnv(execaSync, 'PATH=/bin'));145test('The "env" option must not be null', () => testInvalidEnv(execa, null));146test('The "env" option must not be an array', () => testInvalidEnv(execa, ['PATH=/bin']));147test('The "env" option must not be a symbol', () => testInvalidEnv(execa, Symbol('env')));148149test('Wrong-typed scalar "maxBuffer" values are reported without a file descriptor', () => {150 assertThrows(() => {151 execa('noop.js', {maxBuffer: '1024'});152 }, {instanceOf: TypeError, message: /^The `maxBuffer` option must use a number\.$/});153});154155test('Wrong-typed scalar "lines" values are reported without a file descriptor', () => {156 assertThrows(() => {157 execa('noop.js', {lines: 'true'});158 }, {instanceOf: TypeError, message: /^The `lines` option must use a boolean\.$/});159});