help.sortOptions.test.js
This file
Path
tests/help.sortOptions.test.js
98 lines · 3.2 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 * as commander from '../index.js';2import { test, describe } from 'node:test';3import assert from 'node:assert/strict';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.configureHelp({ sortOptions: true })', () => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 9–15why, one step back9 test('when unsorted then options in order added', () => {10 const program = new commander.Command();11 program12 .option('--zzz', 'desc')13 .option('--aaa', 'desc')14 .option('--bbb', 'desc');15 const helper = program.createHelp();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 16–18why, one step back16 const visibleOptionNames = helper17 .visibleOptions(program)18 .map((option) => option.name());Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 19why, one step back19 assert.deepEqual(visibleOptionNames, ['zzz', 'aaa', 'bbb', 'help']);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 20–29why, one step back20 });2122 test('when sortOptions:true then options sorted alphabetically', () => {23 const program = new commander.Command();24 program25 .configureHelp({ sortOptions: true })26 .option('--zzz', 'desc')27 .option('--aaa', 'desc')28 .option('--bbb', 'desc');29 const helper = program.createHelp();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 30–32why, one step back30 const visibleOptionNames = helper31 .visibleOptions(program)32 .map((cmd) => cmd.name());Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 33why, one step back33 assert.deepEqual(visibleOptionNames, ['aaa', 'bbb', 'help', 'zzz']);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 34–43why, one step back34 });3536 test('when both short and long flags then sort on short flag', () => {37 const program = new commander.Command();38 program39 .configureHelp({ sortOptions: true })40 .option('-m,--zzz', 'desc')41 .option('-n,--aaa', 'desc')42 .option('-o,--bbb', 'desc');43 const helper = program.createHelp();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 44–46why, one step back44 const visibleOptionNames = helper45 .visibleOptions(program)46 .map((cmd) => cmd.name());Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 47why, one step back47 assert.deepEqual(visibleOptionNames, ['help', 'zzz', 'aaa', 'bbb']);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 48–57why, one step back48 });4950 test('when lone short and long flags then sort on lone flag', () => {51 const program = new commander.Command();52 program53 .configureHelp({ sortOptions: true })54 .option('--zzz', 'desc')55 .option('--aaa', 'desc')56 .option('-b', 'desc');57 const helper = program.createHelp();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 58–60why, one step back58 const visibleOptionNames = helper59 .visibleOptions(program)60 .map((cmd) => cmd.name());Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 61why, one step back61 assert.deepEqual(visibleOptionNames, ['aaa', 'b', 'help', 'zzz']);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 62–71why, one step back62 });6364 test('when mixed case flags then sort is case insensitive', () => {65 const program = new commander.Command();66 program67 .configureHelp({ sortOptions: true })68 .option('-B', 'desc')69 .option('-a', 'desc')70 .option('-c', 'desc');71 const helper = program.createHelp();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 72–74why, one step back72 const visibleOptionNames = helper73 .visibleOptions(program)74 .map((cmd) => cmd.name());Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 75why, one step back75 assert.deepEqual(visibleOptionNames, ['a', 'B', 'c', 'help']);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 76–86why, one step back76 });7778 test('when negated option then sort negated option separately', () => {79 const program = new commander.Command();80 program81 .configureHelp({ sortOptions: true })82 .option('--bbb', 'desc')83 .option('--ccc', 'desc')84 .option('--no-bbb', 'desc')85 .option('--aaa', 'desc');86 const helper = program.createHelp();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 87–89why, one step back87 const visibleOptionNames = helper88 .visibleOptions(program)89 .map((cmd) => cmd.name());Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 90–96why, one step back90 assert.deepEqual(visibleOptionNames, [91 'aaa',92 'bbb',93 'ccc',94 'help',95 'no-bbb',96 ]);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 97–98why, one step back97 });98});