help.sortOptions.test.js
This file
Path
tests/help.sortOptions.test.js
78 lines · 3.0 KiB · JavaScript
Last changed by
WYSIWYG sort (#1400)John Geebefore adoption9b087c8
History of this fileTake it
Refactor help internals into separate interface/class (#1365)John Geebefore adoption19ae912
lines 1–29why, one step back1const commander = require('../');23// These are tests of the Help class, not of the Command help.4// There is some overlap with the higher level Command tests (which predate Help).56describe('sortOptions', () => {7 test('when unsorted then options in order added', () => {8 const program = new commander.Command();9 program10 .option('--zzz', 'desc')11 .option('--aaa', 'desc')12 .option('--bbb', 'desc');13 const helper = program.createHelp();14 const visibleOptionNames = helper.visibleOptions(program).map(option => option.name());15 expect(visibleOptionNames).toEqual(['zzz', 'aaa', 'bbb', 'help']);16 });1718 test('when sortOptions:true then options sorted alphabetically', () => {19 const program = new commander.Command();20 program21 .configureHelp({ sortOptions: true })22 .option('--zzz', 'desc')23 .option('--aaa', 'desc')24 .option('--bbb', 'desc');25 const helper = program.createHelp();26 const visibleOptionNames = helper.visibleOptions(program).map(cmd => cmd.name());27 expect(visibleOptionNames).toEqual(['aaa', 'bbb', 'help', 'zzz']);28 });29WYSIWYG sort (#1400)John Geebefore adoption9b087c8
line 30why, one step back30 test('when both short and long flags then sort on short flag', () => {Refactor help internals into separate interface/class (#1365)John Geebefore adoption19ae912
lines 31–38why, one step back31 const program = new commander.Command();32 program33 .configureHelp({ sortOptions: true })34 .option('-m,--zzz', 'desc')35 .option('-n,--aaa', 'desc')36 .option('-o,--bbb', 'desc');37 const helper = program.createHelp();38 const visibleOptionNames = helper.visibleOptions(program).map(cmd => cmd.name());WYSIWYG sort (#1400)John Geebefore adoption9b087c8
line 39why, one step back39 expect(visibleOptionNames).toEqual(['help', 'zzz', 'aaa', 'bbb']);Refactor help internals into separate interface/class (#1365)John Geebefore adoption19ae912
lines 40–41why, one step back40 });41WYSIWYG sort (#1400)John Geebefore adoption9b087c8
line 42why, one step back42 test('when lone short and long flags then sort on lone flag', () => {Refactor help internals into separate interface/class (#1365)John Geebefore adoption19ae912
lines 43–45why, one step back43 const program = new commander.Command();44 program45 .configureHelp({ sortOptions: true })WYSIWYG sort (#1400)John Geebefore adoption9b087c8
lines 46–48why, one step back46 .option('--zzz', 'desc')47 .option('--aaa', 'desc')48 .option('-b', 'desc');Refactor help internals into separate interface/class (#1365)John Geebefore adoption19ae912
lines 49–50why, one step back49 const helper = program.createHelp();50 const visibleOptionNames = helper.visibleOptions(program).map(cmd => cmd.name());WYSIWYG sort (#1400)John Geebefore adoption9b087c8
line 51why, one step back51 expect(visibleOptionNames).toEqual(['aaa', 'b', 'help', 'zzz']);Refactor help internals into separate interface/class (#1365)John Geebefore adoption19ae912
lines 52–53why, one step back52 });53WYSIWYG sort (#1400)John Geebefore adoption9b087c8
line 54why, one step back54 test('when mixed case flags then sort is case insensitive', () => {Refactor help internals into separate interface/class (#1365)John Geebefore adoption19ae912
lines 55–57why, one step back55 const program = new commander.Command();56 program57 .configureHelp({ sortOptions: true })WYSIWYG sort (#1400)John Geebefore adoption9b087c8
lines 58–70why, one step back58 .option('-B', 'desc')59 .option('-a', 'desc')60 .option('-c', 'desc');61 const helper = program.createHelp();62 const visibleOptionNames = helper.visibleOptions(program).map(cmd => cmd.name());63 expect(visibleOptionNames).toEqual(['a', 'B', 'c', 'help']);64 });6566 test('when negated option then sort negated option separately', () => {67 const program = new commander.Command();68 program69 .configureHelp({ sortOptions: true })70 .option('--bbb', 'desc')Refactor help internals into separate interface/class (#1365)John Geebefore adoption19ae912
line 71why, one step back71 .option('--ccc', 'desc')WYSIWYG sort (#1400)John Geebefore adoption9b087c8
lines 72–73why, one step back72 .option('--no-bbb', 'desc')73 .option('--aaa', 'desc');Refactor help internals into separate interface/class (#1365)John Geebefore adoption19ae912
lines 74–75why, one step back74 const helper = program.createHelp();75 const visibleOptionNames = helper.visibleOptions(program).map(cmd => cmd.name());WYSIWYG sort (#1400)John Geebefore adoption9b087c8
line 76why, one step back76 expect(visibleOptionNames).toEqual(['aaa', 'bbb', 'ccc', 'help', 'no-bbb']);Refactor help internals into separate interface/class (#1365)John Geebefore adoption19ae912
lines 77–78why, one step back77 });78});