commander.configureCommand.test.js
This file
Path
tests/commander.configureCommand.test.js
86 lines · 2.8 KiB · JavaScript
Last changed by
More consistent way of adding command arguments (#1490)John Geebefore adoptionb286da9
History of this fileTake it
The walk stopped after 200 commits: lines older than f47bdf5 point at it.
Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 1–6why, one step back1const commander = require('../');23// Mostly testing direct on program, limited check that (sub)command working same.45// Default behaviours6Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71
line 7why, one step back7test('when default then options not stored on command', () => {Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 8–11why, one step back8 const program = new commander.Command();9 program10 .option('--foo <value>', 'description');11 program.parse(['node', 'test', '--foo', 'bar']);Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71
lines 12–13why, one step back12 expect(program.foo).toBeUndefined();13 expect(program.opts().foo).toBe('bar');Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 14–15why, one step back14});15Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71
line 16why, one step back16test('when default then options+command passed to action', () => {Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 17–19why, one step back17 const program = new commander.Command();18 const callback = jest.fn();19 programMore consistent way of adding command arguments (#1490)John Geebefore adoptionb286da9
line 20why, one step back20 .argument('<value>')Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 21–22why, one step back21 .action(callback);22 program.parse(['node', 'test', 'value']);Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71
line 23why, one step back23 expect(callback).toHaveBeenCalledWith('value', program.opts(), program);Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 24–34why, one step back24});2526// storeOptionsAsProperties2728test('when storeOptionsAsProperties() then options stored on command', () => {29 const program = new commander.Command();30 program31 .storeOptionsAsProperties()32 .option('--foo <value>', 'description');33 program.parse(['node', 'test', '--foo', 'bar']);34 expect(program.foo).toBe('bar');Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71
line 35why, one step back35 expect(program.opts().foo).toBe('bar');Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 36–44why, one step back36});3738test('when storeOptionsAsProperties(true) then options stored on command', () => {39 const program = new commander.Command();40 program41 .storeOptionsAsProperties(true)42 .option('--foo <value>', 'description');43 program.parse(['node', 'test', '--foo', 'bar']);44 expect(program.foo).toBe('bar');Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71
line 45why, one step back45 expect(program.opts().foo).toBe('bar');Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 46–54why, one step back46});4748test('when storeOptionsAsProperties(false) then options not stored on command', () => {49 const program = new commander.Command();50 program51 .storeOptionsAsProperties(false)52 .option('--foo <value>', 'description');53 program.parse(['node', 'test', '--foo', 'bar']);54 expect(program.foo).toBeUndefined();Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71
line 55why, one step back55 expect(program.opts().foo).toBe('bar');Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 56–57why, one step back56});57Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71
line 58why, one step back58test('when storeOptionsAsProperties() then command+command passed to action', () => {Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 59–61why, one step back59 const program = new commander.Command();60 const callback = jest.fn();61 programChange to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71
line 62why, one step back62 .storeOptionsAsProperties()More consistent way of adding command arguments (#1490)John Geebefore adoptionb286da9
line 63why, one step back63 .argument('<value>')Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 64–65why, one step back64 .action(callback);65 program.parse(['node', 'test', 'value']);Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71
line 66why, one step back66 expect(callback).toHaveBeenCalledWith('value', program, program);Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 67–68why, one step back67});68Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71
line 69why, one step back69test('when storeOptionsAsProperties(false) then opts+command passed to action', () => {Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 70–72why, one step back70 const program = new commander.Command();71 const callback = jest.fn();72 programChange to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71
line 73why, one step back73 .storeOptionsAsProperties(false)More consistent way of adding command arguments (#1490)John Geebefore adoptionb286da9
line 74why, one step back74 .argument('<value>')Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 75–76why, one step back75 .action(callback);76 program.parse(['node', 'test', 'value']);Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71
line 77why, one step back77 expect(callback).toHaveBeenCalledWith('value', program.opts(), program);Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
line 78why, one step back78});Increase test coverage, including incrementNodeInspectorPort (#1428)John Geebefore adoptiond8faba2
lines 79–86why, one step back7980test('when storeOptionsAsProperties() after adding option then throw', () => {81 const program = new commander.Command();82 program.option('--port <number>', 'port number', '80');83 expect(() => {84 program.storeOptionsAsProperties(false);85 }).toThrow();86});