help.visibleOptions.test.js
This file
Path
tests/help.visibleOptions.test.js
70 lines · 2.8 KiB · JavaScript
Last changed by
Refactor help internals into separate interface/class (#1365)John Geebefore adoption19ae912
History of this fileTake it
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071const commander = require('../');
// These are tests of the Help class, not of the Command help.// There is some overlap with the higher level Command tests (which predate Help).
describe('visibleOptions', () => { test('when no options then just help visible', () => { const program = new commander.Command(); const helper = new commander.Help(); const visibleOptionNames = helper.visibleOptions(program).map(option => option.name()); expect(visibleOptionNames).toEqual(['help']); });
test('when no options and no help option then empty array', () => { const program = new commander.Command(); program.helpOption(false); const helper = new commander.Help(); expect(helper.visibleOptions(program)).toEqual([]); });
test('when add option then visible (with help)', () => { const program = new commander.Command(); program.option('-v,--visible'); const helper = new commander.Help(); const visibleOptionNames = helper.visibleOptions(program).map(option => option.name()); expect(visibleOptionNames).toEqual(['visible', 'help']); });
test('when option hidden then not visible', () => { const program = new commander.Command(); program .option('-v,--visible') .addOption(new commander.Option('--invisible').hideHelp()); const helper = new commander.Help(); const visibleOptionNames = helper.visibleOptions(program).map(option => option.name()); expect(visibleOptionNames).toEqual(['visible', 'help']); });});
describe('implicit help', () => { test('when default then help term is -h, --help', () => { const program = new commander.Command(); const helper = new commander.Help(); const implicitHelp = helper.visibleOptions(program)[0]; expect(helper.optionTerm(implicitHelp)).toEqual('-h, --help'); });
test('when short flag obscured then help term is --help', () => { const program = new commander.Command(); program.addOption(new commander.Option('-h, --huge').hideHelp()); const helper = new commander.Help(); const implicitHelp = helper.visibleOptions(program)[0]; expect(helper.optionTerm(implicitHelp)).toEqual('--help'); });
test('when long flag obscured then help term is --h', () => { const program = new commander.Command(); program.addOption(new commander.Option('-H, --help').hideHelp()); const helper = new commander.Help(); const implicitHelp = helper.visibleOptions(program)[0]; expect(helper.optionTerm(implicitHelp)).toEqual('-h'); });
test('when help flags obscured then implicit help hidden', () => { const program = new commander.Command(); program.addOption(new commander.Option('-h, --help').hideHelp()); const helper = new commander.Help(); expect(helper.visibleOptions(program)).toEqual([]); });});