options.required.test.js
This file
Path
tests/options.required.test.js
70 lines · 2.4 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
lines 5–6why, one step back56// option with required value, no defaultAdd describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 7why, one step back7describe('option with required option-argument, no default', () => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 8–9why, one step back8 test('when option not specified then value is undefined', () => {9 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 10why, one step back10 program.option('--cheese <type>', 'cheese type');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 11why, one step back11 program.parse(['node', 'test']);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 12why, one step back12 assert.equal(program.opts().cheese, undefined);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 13–16why, one step back13 });1415 test('when option specified then value is as specified', () => {16 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 17why, one step back17 program.option('--cheese <type>', 'cheese type');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 18–19why, one step back18 const cheeseType = 'blue';19 program.parse(['node', 'test', '--cheese', cheeseType]);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 20why, one step back20 assert.equal(program.opts().cheese, cheeseType);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 21–23why, one step back21 });2223 test('when option value not specified then error', () => {Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 24why, one step back24 const program = createTestCommand();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 25why, one step back25 program.option('--cheese <type>', 'cheese type');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 26–27why, one step back2627 // Act. The throw is due to the above mock, and not default behaviour.Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 28–35why, one step back28 assert.throws(29 () => {30 program.parse(['node', 'test', '--cheese']);31 },32 {33 code: 'commander.optionMissingArgument',34 },35 );Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 36–39why, one step back36 });37});3839// option with required value, with defaultAdd describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 40why, one step back40describe('option with required option-argument, with default', () => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 41–43why, one step back41 test('when option not specified then value is default', () => {42 const defaultValue = 'default';43 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 44why, one step back44 program.option('--cheese <type>', 'cheese type', defaultValue);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 45why, one step back45 program.parse(['node', 'test']);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 46why, one step back46 assert.equal(program.opts().cheese, defaultValue);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 47–51why, one step back47 });4849 test('when option specified then value is as specified', () => {50 const defaultValue = 'default';51 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 52why, one step back52 program.option('--cheese <type>', 'cheese type', defaultValue);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 53–54why, one step back53 const cheeseType = 'blue';54 program.parse(['node', 'test', '--cheese', cheeseType]);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 55why, one step back55 assert.equal(program.opts().cheese, cheeseType);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 56–57why, one step back56 });57Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 58why, one step back58 test('when option value not specified then error', (t) => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 59why, one step back59 const defaultValue = 'default';Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 60why, one step back60 const program = createTestCommand();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 61why, one step back61 program.option('--cheese <type>', 'cheese type', defaultValue);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 62why, one step back62Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 63–68why, one step back63 assert.throws(64 () => {65 program.parse(['node', 'test', '--cheese']);66 },67 { code: 'commander.optionMissingArgument' },68 );Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 69–70why, one step back69 });70});