options.values.test.js
This file
Path
tests/options.values.test.js
83 lines · 3.0 KiB · JavaScript
Last changed by
Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71
History of this fileTake it
The walk stopped after 200 commits: lines older than 669190d point at it.
Merge branch 'master' into developJohn Geebefore adoption669190d
lines 1–20why, one step back1const commander = require('../');23// Test the ways values can be specified for options.4// See also references on "Utility Conventions" in command.parseOptions.test.js56// options with required values can eat values starting with a dash, including just dash sometimes used as alias for stdin7//8// option with required value, using describe.each to test all matrix of values and tests9describe.each([['str'], ['80'], ['-'], ['-5'], ['--flag']])(10 'option with required value specified as %s', (value) => {11 function createPortProgram() {12 const program = new commander.Command();13 program14 .option('-p,--port <number>', 'specify port');15 return program;16 }1718 test('when short flag followed by value then value is as specified', () => {19 const program = createPortProgram();20 program.parse(['node', 'test', '-p', value]);Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71
line 21why, one step back21 expect(program.opts().port).toBe(value);Merge branch 'master' into developJohn Geebefore adoption669190d
lines 22–26why, one step back22 });2324 test('when short flag concatenated with value then value is as specified', () => {25 const program = createPortProgram();26 program.parse(['node', 'test', `-p${value}`]);Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71
line 27why, one step back27 expect(program.opts().port).toBe(value);Merge branch 'master' into developJohn Geebefore adoption669190d
lines 28–32why, one step back28 });2930 test('when long flag followed by value then value is as specified', () => {31 const program = createPortProgram();32 program.parse(['node', 'test', '--port', value]);Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71
line 33why, one step back33 expect(program.opts().port).toBe(value);Merge branch 'master' into developJohn Geebefore adoption669190d
lines 34–38why, one step back34 });3536 test('when long flag = value then value is as specified', () => {37 const program = createPortProgram();38 program.parse(['node', 'test', `--port=${value}`]);Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71
line 39why, one step back39 expect(program.opts().port).toBe(value);Merge branch 'master' into developJohn Geebefore adoption669190d
lines 40–54why, one step back40 });41 });4243// option with optional value44describe('option with optional value', () => {45 function createPortProgram() {46 const program = new commander.Command();47 program48 .option('-p,--port [number]', 'specify port');49 return program;50 }5152 test('when short flag followed by value then value is as specified', () => {53 const program = createPortProgram();54 program.parse('node test -p 80'.split(' '));Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71
line 55why, one step back55 expect(program.opts().port).toBe('80');Merge branch 'master' into developJohn Geebefore adoption669190d
lines 56–60why, one step back56 });5758 test('when short flag concatenated with value then value is as specified', () => {59 const program = createPortProgram();60 program.parse('node test -p80'.split(' '));Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71
line 61why, one step back61 expect(program.opts().port).toBe('80');Merge branch 'master' into developJohn Geebefore adoption669190d
lines 62–66why, one step back62 });6364 test('when long flag followed by value then value is as specified', () => {65 const program = createPortProgram();66 program.parse('node test --port 80'.split(' '));Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71
line 67why, one step back67 expect(program.opts().port).toBe('80');Merge branch 'master' into developJohn Geebefore adoption669190d
lines 68–72why, one step back68 });6970 test('when long flag = value then value is as specified', () => {71 const program = createPortProgram();72 program.parse('node test --port=80'.split(' '));Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71
line 73why, one step back73 expect(program.opts().port).toBe('80');Merge branch 'master' into developJohn Geebefore adoption669190d
lines 74–80why, one step back74 });7576 test('when long flag followed empty string then value is empty string', () => {77 const program = createPortProgram();78 program79 .option('-c, --cheese [type]', 'optionally specify the type of cheese');80 program.parse(['node', 'test', '--cheese', '']);Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71
line 81why, one step back81 expect(program.opts().cheese).toBe('');Merge branch 'master' into developJohn Geebefore adoption669190d
lines 82–83why, one step back82 });83});