help.visibleOptions.test.js
This file
Path
tests/help.visibleOptions.test.js
78 lines · 2.9 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–3why, one step back1import { test, describe } from 'node:test';2import assert from 'node:assert/strict';3import * as commander from '../index.js';Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 4–7why, one step back45// These are tests of the Help class, not of the Command help.6// There is some overlap with the higher level Command tests (which predate Help).7Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 8why, one step back8describe('Help.visibleOptions()', () => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 9–11why, one step back9 test('when no options then just help visible', () => {10 const program = new commander.Command();11 const helper = new commander.Help();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 12–14why, one step back12 const visibleOptionNames = helper13 .visibleOptions(program)14 .map((option) => option.name());Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 15why, one step back15 assert.deepEqual(visibleOptionNames, ['help']);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 16–21why, one step back16 });1718 test('when no options and no help option then empty array', () => {19 const program = new commander.Command();20 program.helpOption(false);21 const helper = new commander.Help();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 22why, one step back22 assert.deepEqual(helper.visibleOptions(program), []);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 23–28why, one step back23 });2425 test('when add option then visible (with help)', () => {26 const program = new commander.Command();27 program.option('-v,--visible');28 const helper = new commander.Help();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 29–31why, one step back29 const visibleOptionNames = helper30 .visibleOptions(program)31 .map((option) => option.name());Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 32why, one step back32 assert.deepEqual(visibleOptionNames, ['visible', 'help']);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 33–40why, one step back33 });3435 test('when option hidden then not visible', () => {36 const program = new commander.Command();37 program38 .option('-v,--visible')39 .addOption(new commander.Option('--invisible').hideHelp());40 const helper = new commander.Help();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 41–43why, one step back41 const visibleOptionNames = helper42 .visibleOptions(program)43 .map((option) => option.name());Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 44why, one step back44 assert.deepEqual(visibleOptionNames, ['visible', 'help']);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 45–52why, one step back45 });46});4748describe('implicit help', () => {49 test('when default then help term is -h, --help', () => {50 const program = new commander.Command();51 const helper = new commander.Help();52 const implicitHelp = helper.visibleOptions(program)[0];Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 53why, one step back53 assert.equal(helper.optionTerm(implicitHelp), '-h, --help');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 54–60why, one step back54 });5556 test('when short flag obscured then help term is --help', () => {57 const program = new commander.Command();58 program.addOption(new commander.Option('-h, --huge').hideHelp());59 const helper = new commander.Help();60 const implicitHelp = helper.visibleOptions(program)[0];Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 61why, one step back61 assert.equal(helper.optionTerm(implicitHelp), '--help');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 62–68why, one step back62 });6364 test('when long flag obscured then help term is --h', () => {65 const program = new commander.Command();66 program.addOption(new commander.Option('-H, --help').hideHelp());67 const helper = new commander.Help();68 const implicitHelp = helper.visibleOptions(program)[0];Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 69why, one step back69 assert.equal(helper.optionTerm(implicitHelp), '-h');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 70–75why, one step back70 });7172 test('when help flags obscured then implicit help hidden', () => {73 const program = new commander.Command();74 program.addOption(new commander.Option('-h, --help').hideHelp());75 const helper = new commander.Help();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 76why, one step back76 assert.deepEqual(helper.visibleOptions(program), []);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 77–78why, one step back77 });78});