argument.choices.test.js
This file
Path
tests/argument.choices.test.js
57 lines · 2.1 KiB · JavaScript
Last changed by
Switching to esm-only (#2464)John Geebefore adoptionf4bd470
History of this fileTake it
The walk stopped after 200 commits: lines older than 471ec40 point at it.
Switching to esm-only (#2464)John Geebefore adoptionf4bd470
lines 1–4why, one step back1import * as commander from '../index.js';2import { createTestCommand } from './testHelpers.js';3import { test, describe } from 'node:test';4import assert from 'node:assert/strict';Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 5why, one step back5Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 6–17why, one step back6describe('Argument.choices()', () => {7 test('when command argument in choices then argument set', () => {8 const program = createTestCommand();9 let shade;10 program11 .addArgument(new commander.Argument('<shade>').choices(['red', 'blue']))12 .action((shadeParam) => {13 shade = shadeParam;14 });15 program.parse(['red'], { from: 'user' });16 assert.equal(shade, 'red');17 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 18why, one step back18Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 19–27why, one step back19 test('when command argument is not in choices then error', () => {20 // Lightweight check, more detailed testing of behaviour in command.exitOverride.test.js21 const program = createTestCommand();22 program.addArgument(23 new commander.Argument('<shade>').choices(['red', 'blue']),24 );25 assert.throws(() => {26 program.parse(['orange'], { from: 'user' });27 });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 28why, one step back28 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 29–30why, one step back29});30Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 31why, one step back31describe('Argument.choices() parameter is treated as readonly, per TypeScript declaration', () => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 32–36why, one step back32 test('when choices called then parameter does not change', () => {33 // Unlikely this could break, but check the API we are declaring in TypeScript.34 const original = ['red', 'blue', 'green'];35 const param = original.slice();36 new commander.Argument('<shade>').choices(param);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 37why, one step back37 assert.deepEqual(param, original);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 38–44why, one step back38 });3940 test('when choices called and argChoices later changed then parameter does not change', () => {41 const original = ['red', 'blue', 'green'];42 const param = original.slice();43 const argument = new commander.Argument('<shade>').choices(param);44 argument.argChoices.push('purple');Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 45why, one step back45 assert.deepEqual(param, original);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 46–48why, one step back46 });4748 test('when choices called and parameter changed the choices does not change', () => {Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 49why, one step back49 const program = createTestCommand();Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 50why, one step back50 const param = ['red', 'blue'];Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 51why, one step back51 program.addArgument(new commander.Argument('<shade>').choices(param));Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 52why, one step back52 param.push('orange');Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 53why, one step back53 assert.throws(() => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 54why, one step back54 program.parse(['orange'], { from: 'user' });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 55why, one step back55 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 56–57why, one step back56 });57});