helpGroup.test.js
This file
Path
tests/helpGroup.test.js
255 lines · 9.2 KiB · JavaScript
Last changed by
Switching to esm-only (#2464)John Geebefore adoptionf4bd470
History of this fileTake 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 { Command, Option } from '../index.js';Add support for groups of options and commands in the help (#2328)John Geebefore adoptionc324ea3
lines 4–12why, one step back45// Similar tests for Option.helpGroup() and Command.helpGroup(),6// and for Command.optionsGroup() and Command.commandsGroup().78describe('Option.helpGroup', () => {9 test('when add one option with helpGroup then help contains group', () => {10 const program = new Command();11 program.addOption(new Option('--alpha').helpGroup('Greek:'));12 const helpInfo = program.helpInformation();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 13why, one step back13 assert.match(helpInfo, /Greek:\n *--alpha/);Add support for groups of options and commands in the help (#2328)John Geebefore adoptionc324ea3
lines 14–20why, one step back14 });1516 test('when add two options with helpGroup then help contains group', () => {17 const program = new Command();18 program.addOption(new Option('--alpha').helpGroup('Greek:'));19 program.addOption(new Option('--beta').helpGroup('Greek:'));20 const helpInfo = program.helpInformation();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 21why, one step back21 assert.match(helpInfo, /Greek:\n *--alpha\n *--beta/);Add support for groups of options and commands in the help (#2328)John Geebefore adoptionc324ea3
lines 22–29why, one step back22 });23});2425describe('Command.helpGroup', () => {26 test('when add one command with helpGroup then help contains group', () => {27 const program = new Command();28 program.command('alpha').helpGroup('Greek:');29 const helpInfo = program.helpInformation();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 30why, one step back30 assert.match(helpInfo, /Greek:\n *alpha/);Add support for groups of options and commands in the help (#2328)John Geebefore adoptionc324ea3
lines 31–37why, one step back31 });3233 test('when add two commands with helpGroup then help contains group', () => {34 const program = new Command();35 program.command('alpha').helpGroup('Greek:');36 program.command('beta').helpGroup('Greek:');37 const helpInfo = program.helpInformation();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 38why, one step back38 assert.match(helpInfo, /Greek:\n *alpha\n *beta/);Add support for groups of options and commands in the help (#2328)John Geebefore adoptionc324ea3
lines 39–41why, one step back39 });40});41Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 42why, one step back42describe('Command.optionsGroup', () => {Add support for groups of options and commands in the help (#2328)John Geebefore adoptionc324ea3
lines 43–47why, one step back43 test('when add one option then help contains group', () => {44 const program = new Command();45 program.optionsGroup('Greek:');46 program.option('--alpha');47 const helpInfo = program.helpInformation();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 48why, one step back48 assert.match(helpInfo, /Greek:\n *--alpha/);Add support for groups of options and commands in the help (#2328)John Geebefore adoptionc324ea3
lines 49–56why, one step back49 });5051 test('when add two options then help contains group with two options', () => {52 const program = new Command();53 program.optionsGroup('Greek:');54 program.option('--alpha');55 program.option('--beta');56 const helpInfo = program.helpInformation();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 57why, one step back57 assert.match(helpInfo, /Greek:\n *--alpha\n *--beta/);Add support for groups of options and commands in the help (#2328)John Geebefore adoptionc324ea3
lines 58–66why, one step back58 });5960 test('when add options with different groups then help contains two groups', () => {61 const program = new Command();62 program.optionsGroup('Greek:');63 program.option('--alpha');64 program.optionsGroup('Latin:');65 program.option('--unus');66 const helpInfo = program.helpInformation();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 67–68why, one step back67 assert.match(helpInfo, /Greek:\n *--alpha/);68 assert.match(helpInfo, /Latin:\n *--unus/);Add support for groups of options and commands in the help (#2328)John Geebefore adoptionc324ea3
lines 69–75why, one step back69 });7071 test('when implicit help option then help option not affected', () => {72 const program = new Command();73 program.optionsGroup('Greek:');74 program.option('--alpha');75 const helpInfo = program.helpInformation();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 76why, one step back76 assert.match(helpInfo, /Options:\n *-h, --help/);Add support for groups of options and commands in the help (#2328)John Geebefore adoptionc324ea3
lines 77–83why, one step back77 });7879 test('when option with helpGroup then helpGroup wins', () => {80 const program = new Command();81 program.optionsGroup('Greek:');82 program.addOption(new Option('--unus').helpGroup('Latin:'));83 const helpInfo = program.helpInformation();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 84why, one step back84 assert.match(helpInfo, /Latin:\n *--unus/);Add support for groups of options and commands in the help (#2328)John Geebefore adoptionc324ea3
lines 85–90why, one step back85 });8687 test('when add no options with heading then heading does not appear', () => {88 const program = new Command();89 program.optionsGroup('Greek:');90 const helpInfo = program.helpInformation();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 91why, one step back91 assert.doesNotMatch(helpInfo, /Greek/);Add support for groups of options and commands in the help (#2328)John Geebefore adoptionc324ea3
lines 92–98why, one step back92 });9394 test('when add no visible options with heading then heading does not appear', () => {95 const program = new Command();96 program.optionsGroup('Greek:');97 program.addOption(new Option('--alpha').hideHelp());98 const helpInfo = program.helpInformation();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 99why, one step back99 assert.doesNotMatch(helpInfo, /Greek/);Add support for groups of options and commands in the help (#2328)John Geebefore adoptionc324ea3
lines 100–106why, one step back100 });101102 test('when .helpOption(flags) then help option in group', () => {103 const program = new Command();104 program.optionsGroup('Greek:');105 program.helpOption('--assist');106 const helpInfo = program.helpInformation();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 107why, one step back107 assert.match(helpInfo, /Greek:\n *--assist/);Add support for groups of options and commands in the help (#2328)John Geebefore adoptionc324ea3
lines 108–114why, one step back108 });109110 test('when .helpOption(true) then help option in group', () => {111 const program = new Command();112 program.optionsGroup('Greek:');113 program.helpOption(true);114 const helpInfo = program.helpInformation();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 115why, one step back115 assert.match(helpInfo, /Greek:\n *-h, --help/);Add support for groups of options and commands in the help (#2328)John Geebefore adoptionc324ea3
lines 116–122why, one step back116 });117118 test('when .version(str) then version option in group', () => {119 const program = new Command();120 program.optionsGroup('Greek:');121 program.version('1.2.3');122 const helpInfo = program.helpInformation();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 123why, one step back123 assert.match(helpInfo, /Greek:\n *-V, --version/);Add support for groups of options and commands in the help (#2328)John Geebefore adoptionc324ea3
lines 124–135why, one step back124 });125126 test('when set sortOptions then options are sorted within groups', () => {127 const program = new Command();128 program.configureHelp({ sortOptions: true });129 program.optionsGroup('Latin:');130 program.option('--unus');131 program.option('--duo');132 program.optionsGroup('Greek:');133 program.option('--beta');134 program.option('--alpha');135 const helpInfo = program.helpInformation();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 136–137why, one step back136 assert.match(helpInfo, /Latin:\n *--duo\n *--unus/);137 assert.match(helpInfo, /Greek:\n *--alpha\n *--beta/);Add support for groups of options and commands in the help (#2328)John Geebefore adoptionc324ea3
lines 138–146why, one step back138 });139140 test('when set sortOptions then groups are in order added not sorted', () => {141 const program = new Command();142 program.configureHelp({ sortOptions: true });143 program.addOption(new Option('--bbb').helpGroup('BBB:'));144 program.addOption(new Option('--ccc').helpGroup('CCC:'));145 program.addOption(new Option('--aaa').helpGroup('AAA:'));146 const helpInfo = program.helpInformation();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 147–148why, one step back147 assert.match(148 helpInfo,Add support for groups of options and commands in the help (#2328)John Geebefore adoptionc324ea3
lines 149–153why, one step back149 /BBB:\n *--bbb.*\n\nCCC:\n *--ccc.*\n\nAAA:\n *--aaa/,150 );151 });152});153Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 154why, one step back154describe('Command.commandsGroup', () => {Add support for groups of options and commands in the help (#2328)John Geebefore adoptionc324ea3
lines 155–159why, one step back155 test('when add one command then help contains group', () => {156 const program = new Command();157 program.commandsGroup('Greek:');158 program.command('alpha');159 const helpInfo = program.helpInformation();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 160why, one step back160 assert.match(helpInfo, /Greek:\n *alpha/);Add support for groups of options and commands in the help (#2328)John Geebefore adoptionc324ea3
lines 161–168why, one step back161 });162163 test('when add two commands then help contains group with two commands', () => {164 const program = new Command();165 program.commandsGroup('Greek:');166 program.command('alpha');167 program.command('beta');168 const helpInfo = program.helpInformation();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 169why, one step back169 assert.match(helpInfo, /Greek:\n *alpha\n *beta/);Add support for groups of options and commands in the help (#2328)John Geebefore adoptionc324ea3
lines 170–178why, one step back170 });171172 test('when add commands with different groups then help contains two groups', () => {173 const program = new Command();174 program.commandsGroup('Greek:');175 program.command('alpha');176 program.commandsGroup('Latin:');177 program.command('unus');178 const helpInfo = program.helpInformation();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 179–180why, one step back179 assert.match(helpInfo, /Greek:\n *alpha/);180 assert.match(helpInfo, /Latin:\n *unus/);Add support for groups of options and commands in the help (#2328)John Geebefore adoptionc324ea3
lines 181–187why, one step back181 });182183 test('when implicit help command then help command not affected', () => {184 const program = new Command();185 program.commandsGroup('Greek:');186 program.command('alpha');187 const helpInfo = program.helpInformation();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 188why, one step back188 assert.match(helpInfo, /Commands:\n *help/);Add support for groups of options and commands in the help (#2328)John Geebefore adoptionc324ea3
lines 189–195why, one step back189 });190191 test('when command with custom helpGroup then helpGroup wins', () => {192 const program = new Command();193 program.commandsGroup('Greek:');194 program.command('unus').helpGroup('Latin:');195 const helpInfo = program.helpInformation();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 196why, one step back196 assert.match(helpInfo, /Latin:\n *unus/);Add support for groups of options and commands in the help (#2328)John Geebefore adoptionc324ea3
lines 197–202why, one step back197 });198199 test('when add no commands with heading then heading does not appear', () => {200 const program = new Command();201 program.commandsGroup('Greek:');202 const helpInfo = program.helpInformation();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 203why, one step back203 assert.doesNotMatch(helpInfo, /Greek/);Add support for groups of options and commands in the help (#2328)John Geebefore adoptionc324ea3
lines 204–210why, one step back204 });205206 test('when add no visible command with heading then heading does not appear', () => {207 const program = new Command();208 program.commandsGroup('Greek:');209 program.command('alpha', { hidden: true });210 const helpInfo = program.helpInformation();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 211why, one step back211 assert.doesNotMatch(helpInfo, /Greek/);Add support for groups of options and commands in the help (#2328)John Geebefore adoptionc324ea3
lines 212–219why, one step back212 });213214 test('when .helpCommand(name) then help command in group', () => {215 const program = new Command();216 program.command('foo');217 program.commandsGroup('Greek:');218 program.helpCommand('assist');219 const helpInfo = program.helpInformation();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 220why, one step back220 assert.match(helpInfo, /Greek:\n *assist/);Add support for groups of options and commands in the help (#2328)John Geebefore adoptionc324ea3
lines 221–228why, one step back221 });222223 test('when .helpCommand(true) then help command in group', () => {224 const program = new Command();225 program.command('foo');226 program.commandsGroup('Greek:');227 program.helpCommand(true);228 const helpInfo = program.helpInformation();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 229why, one step back229 assert.match(helpInfo, /Greek:\n *help/);Add support for groups of options and commands in the help (#2328)John Geebefore adoptionc324ea3
lines 230–241why, one step back230 });231232 test('when set sortCommands then commands are sorted within groups', () => {233 const program = new Command();234 program.configureHelp({ sortSubcommands: true });235 program.commandsGroup('Latin:');236 program.command('unus');237 program.command('duo');238 program.commandsGroup('Greek:');239 program.command('beta');240 program.command('alpha');241 const helpInfo = program.helpInformation();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 242–243why, one step back242 assert.match(helpInfo, /Latin:\n *duo\n *unus/);243 assert.match(helpInfo, /Greek:\n *alpha\n *beta/);Add support for groups of options and commands in the help (#2328)John Geebefore adoptionc324ea3
lines 244–252why, one step back244 });245246 test('when set sortOptions then groups are in order added not sorted', () => {247 const program = new Command();248 program.configureHelp({ sortSubcommands: true });249 program.command('bbb').helpGroup('BBB:');250 program.command('ccc').helpGroup('CCC:');251 program.command('aaa').helpGroup('AAA:');252 const helpInfo = program.helpInformation();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 253why, one step back253 assert.match(helpInfo, /BBB:\n *bbb.*\n\nCCC:\n *ccc.*\n\nAAA:\n *aaa/);Add support for groups of options and commands in the help (#2328)John Geebefore adoptionc324ea3
lines 254–255why, one step back254 });255});