command.helpOption.test.js
This file
Path
tests/command.helpOption.test.js
133 lines · 4.2 KiB · JavaScript
Last changed by
Add showHelpAfterError (#1534)John Geebefore adoption082717f
History of this fileTake it
The walk stopped after 200 commits: lines older than 1704022 point at it.
Use this instead of Command as a return type in TypeScript (#1180)Dmitrii Maganovbefore adoption1704022
lines 1–2why, one step back1const commander = require('../');2Merge pull request #1305 from tj/release/6.xTomoaki Abebefore adoptionc5a5e7b
lines 3–4why, one step back3describe('helpOption', () => {4 let writeSpy;configure output (#1387)John Geebefore adoptioned7f13e
line 5why, one step back5 let writeErrorSpy;Use this instead of Command as a return type in TypeScript (#1180)Dmitrii Maganovbefore adoption1704022
line 6why, one step back6Merge pull request #1305 from tj/release/6.xTomoaki Abebefore adoptionc5a5e7b
line 7why, one step back7 beforeAll(() => {Allow disabling the built-in help option (#1325)John Geebefore adoption6b2e42c
line 8why, one step back8 // Optional. Suppress expected output to keep test output clean.Merge pull request #1305 from tj/release/6.xTomoaki Abebefore adoptionc5a5e7b
line 9why, one step back9 writeSpy = jest.spyOn(process.stdout, 'write').mockImplementation(() => { });configure output (#1387)John Geebefore adoptioned7f13e
line 10why, one step back10 writeErrorSpy = jest.spyOn(process.stderr, 'write').mockImplementation(() => { });Merge pull request #1305 from tj/release/6.xTomoaki Abebefore adoptionc5a5e7b
lines 11–14why, one step back11 });1213 afterEach(() => {14 writeSpy.mockClear();configure output (#1387)John Geebefore adoptioned7f13e
line 15why, one step back15 writeErrorSpy.mockClear();Merge pull request #1305 from tj/release/6.xTomoaki Abebefore adoptionc5a5e7b
lines 16–19why, one step back16 });1718 afterAll(() => {19 writeSpy.mockRestore();configure output (#1387)John Geebefore adoptioned7f13e
line 20why, one step back20 writeErrorSpy.mockRestore();Merge pull request #1305 from tj/release/6.xTomoaki Abebefore adoptionc5a5e7b
lines 21–68why, one step back21 });2223 test('when helpOption has custom flags then custom short flag invokes help', () => {24 const program = new commander.Command();25 program26 .exitOverride()27 .helpOption('-c,--custom-help', 'custom help output');28 expect(() => {29 program.parse(['-c'], { from: 'user' });30 }).toThrow('(outputHelp)');31 });3233 test('when helpOption has custom flags then custom long flag invokes help', () => {34 const program = new commander.Command();35 program36 .exitOverride()37 .helpOption('-c,--custom-help', 'custom help output');38 expect(() => {39 program.parse(['--custom-help'], { from: 'user' });40 }).toThrow('(outputHelp)');41 });4243 test('when helpOption has just custom short flag then custom short flag invokes help', () => {44 const program = new commander.Command();45 program46 .exitOverride()47 .helpOption('-c', 'custom help output');48 expect(() => {49 program.parse(['-c'], { from: 'user' });50 }).toThrow('(outputHelp)');51 });5253 test('when helpOption has just custom long flag then custom long flag invokes help', () => {54 const program = new commander.Command();55 program56 .exitOverride()57 .helpOption('--custom-help', 'custom help output');58 expect(() => {59 program.parse(['--custom-help'], { from: 'user' });60 }).toThrow('(outputHelp)');61 });6263 test('when helpOption has custom description then helpInformation include custom description', () => {64 const program = new commander.Command();65 program66 .helpOption('-C,--custom-help', 'custom help output');67 const helpInformation = program.helpInformation();68 expect(helpInformation).toMatch(/-C,--custom-help +custom help output/);Allow disabling the built-in help option (#1325)John Geebefore adoption6b2e42c
lines 69–70why, one step back69 });70Test coverage (#1433)John Geebefore adoption891e23d
lines 71–86why, one step back71 test('when helpOption has just flags then helpInformation includes default description', () => {72 const program = new commander.Command();73 program74 .helpOption('-C,--custom-help');75 const helpInformation = program.helpInformation();76 expect(helpInformation).toMatch(/-C,--custom-help +display help for command/);77 });7879 test('when helpOption has just description then helpInformation includes default flags', () => {80 const program = new commander.Command();81 program82 .helpOption(undefined, 'custom help output');83 const helpInformation = program.helpInformation();84 expect(helpInformation).toMatch(/-h, --help +custom help output/);85 });86Allow disabling the built-in help option (#1325)John Geebefore adoption6b2e42c
lines 87–130why, one step back87 test('when helpOption(false) then helpInformation does not include --help', () => {88 const program = new commander.Command();89 program90 .helpOption(false);91 const helpInformation = program.helpInformation();92 expect(helpInformation).not.toMatch('--help');93 });9495 test('when helpOption(false) then --help is an unknown option', () => {96 const program = new commander.Command();97 program98 .exitOverride()99 .helpOption(false);100 let caughtErr;101 try {102 program.parse(['--help'], { from: 'user' });103 } catch (err) {104 caughtErr = err;105 }106 expect(caughtErr.code).toBe('commander.unknownOption');107 });108109 test('when helpOption(false) then -h is an unknown option', () => {110 const program = new commander.Command();111 program112 .exitOverride()113 .helpOption(false);114 let caughtErr;115 try {116 program.parse(['-h'], { from: 'user' });117 } catch (err) {118 caughtErr = err;119 }120 expect(caughtErr.code).toBe('commander.unknownOption');121 });122123 test('when helpOption(false) then unknown command error does not suggest --help', () => {124 const program = new commander.Command();125 program126 .exitOverride()127 .helpOption(false)128 .command('foo');129 expect(() => {130 program.parse(['UNKNOWN'], { from: 'user' });Add showHelpAfterError (#1534)John Geebefore adoption082717f
line 131why, one step back131 }).toThrow("error: unknown command 'UNKNOWN'");Merge pull request #1305 from tj/release/6.xTomoaki Abebefore adoptionc5a5e7b
line 132why, one step back132 });Use this instead of Command as a return type in TypeScript (#1180)Dmitrii Maganovbefore adoption1704022
line 133why, one step back133});