options.version.test.js
This file
Path
tests/options.version.test.js
178 lines · 5.6 KiB · JavaScript
Last changed by
configure output (#1387)John Geebefore adoptioned7f13e
History of this fileTake it
The walk stopped after 200 commits: lines older than 2aad525 point at it.
Update dependencies (#1214)John Geebefore adoption2aad525
lines 1–27why, one step back1const commander = require('../');23// Test .version. Using exitOverride to check behaviour (instead of mocking process.exit).45describe('.version', () => {6 test('when no .version and specify --version then unknown option error', () => {7 const errorMessage = 'unknownOption';8 const program = new commander.Command();9 // Override unknownOption as convenient way to check fails as expected.10 jest.spyOn(program, 'unknownOption').mockImplementation(() => { throw new Error(errorMessage); });1112 expect(() => {13 program.parse(['node', 'test', '--version']);14 }).toThrow(errorMessage);15 });1617 test('when no .version then helpInformation does not include version', () => {18 const program = new commander.Command();1920 const helpInformation = program.helpInformation();2122 expect(helpInformation.includes('Usage')).toBe(true);23 expect(helpInformation.includes('version')).toBe(false);24 });2526 test('when specify default short flag then display version', () => {27 const myVersion = '1.2.3';configure output (#1387)John Geebefore adoptioned7f13e
line 28why, one step back28 const writeMock = jest.fn();Update dependencies (#1214)John Geebefore adoption2aad525
lines 29–31why, one step back29 const program = new commander.Command();30 program31 .exitOverride()configure output (#1387)John Geebefore adoptioned7f13e
line 32why, one step back32 .configureOutput({ writeOut: writeMock })Update dependencies (#1214)John Geebefore adoption2aad525
lines 33–37why, one step back33 .version(myVersion);3435 expect(() => {36 program.parse(['node', 'test', '-V']);37 }).toThrow(myVersion);configure output (#1387)John Geebefore adoptioned7f13e
line 38why, one step back38 expect(writeMock).toHaveBeenCalledWith(`${myVersion}\n`);Update dependencies (#1214)John Geebefore adoption2aad525
lines 39–42why, one step back39 });4041 test('when specify default long flag then display version', () => {42 const myVersion = '1.2.3';configure output (#1387)John Geebefore adoptioned7f13e
line 43why, one step back43 const writeMock = jest.fn();Update dependencies (#1214)John Geebefore adoption2aad525
lines 44–46why, one step back44 const program = new commander.Command();45 program46 .exitOverride()configure output (#1387)John Geebefore adoptioned7f13e
line 47why, one step back47 .configureOutput({ writeOut: writeMock })Update dependencies (#1214)John Geebefore adoption2aad525
lines 48–52why, one step back48 .version(myVersion);4950 expect(() => {51 program.parse(['node', 'test', '--version']);52 }).toThrow(myVersion);configure output (#1387)John Geebefore adoptioned7f13e
line 53why, one step back53 expect(writeMock).toHaveBeenCalledWith(`${myVersion}\n`);Update dependencies (#1214)John Geebefore adoption2aad525
lines 54–69why, one step back54 });5556 test('when default .version then helpInformation includes default version help', () => {57 const myVersion = '1.2.3';58 const program = new commander.Command();59 program60 .version(myVersion);6162 const helpInformation = program.helpInformation();6364 expect(helpInformation.includes('-V, --version')).toBe(true);65 expect(helpInformation.includes('output the version number')).toBe(true);66 });6768 test('when specify custom short flag then display version', () => {69 const myVersion = '1.2.3';configure output (#1387)John Geebefore adoptioned7f13e
line 70why, one step back70 const writeMock = jest.fn();Update dependencies (#1214)John Geebefore adoption2aad525
lines 71–73why, one step back71 const program = new commander.Command();72 program73 .exitOverride()configure output (#1387)John Geebefore adoptioned7f13e
line 74why, one step back74 .configureOutput({ writeOut: writeMock })Update dependencies (#1214)John Geebefore adoption2aad525
lines 75–79why, one step back75 .version(myVersion, '-r, --revision');7677 expect(() => {78 program.parse(['node', 'test', '-r']);79 }).toThrow(myVersion);configure output (#1387)John Geebefore adoptioned7f13e
line 80why, one step back80 expect(writeMock).toHaveBeenCalledWith(`${myVersion}\n`);Update dependencies (#1214)John Geebefore adoption2aad525
lines 81–82why, one step back81 });82Merge pull request #1305 from tj/release/6.xTomoaki Abebefore adoptionc5a5e7b
lines 83–84why, one step back83 test('when specify just custom short flag then display version', () => {84 const myVersion = '1.2.3';configure output (#1387)John Geebefore adoptioned7f13e
line 85why, one step back85 const writeMock = jest.fn();Merge pull request #1305 from tj/release/6.xTomoaki Abebefore adoptionc5a5e7b
lines 86–88why, one step back86 const program = new commander.Command();87 program88 .exitOverride()configure output (#1387)John Geebefore adoptioned7f13e
line 89why, one step back89 .configureOutput({ writeOut: writeMock })Merge pull request #1305 from tj/release/6.xTomoaki Abebefore adoptionc5a5e7b
lines 90–94why, one step back90 .version(myVersion, '-r');9192 expect(() => {93 program.parse(['node', 'test', '-r']);94 }).toThrow(myVersion);configure output (#1387)John Geebefore adoptioned7f13e
line 95why, one step back95 expect(writeMock).toHaveBeenCalledWith(`${myVersion}\n`);Merge pull request #1305 from tj/release/6.xTomoaki Abebefore adoptionc5a5e7b
lines 96–97why, one step back96 });97Update dependencies (#1214)John Geebefore adoption2aad525
lines 98–99why, one step back98 test('when specify custom long flag then display version', () => {99 const myVersion = '1.2.3';configure output (#1387)John Geebefore adoptioned7f13e
line 100why, one step back100 const writeMock = jest.fn();Update dependencies (#1214)John Geebefore adoption2aad525
lines 101–103why, one step back101 const program = new commander.Command();102 program103 .exitOverride()configure output (#1387)John Geebefore adoptioned7f13e
line 104why, one step back104 .configureOutput({ writeOut: writeMock })Update dependencies (#1214)John Geebefore adoption2aad525
line 105why, one step back105 .version(myVersion, '-r, --revision');Merge pull request #1305 from tj/release/6.xTomoaki Abebefore adoptionc5a5e7b
lines 106–109why, one step back106107 expect(() => {108 program.parse(['node', 'test', '--revision']);109 }).toThrow(myVersion);configure output (#1387)John Geebefore adoptioned7f13e
line 110why, one step back110 expect(writeMock).toHaveBeenCalledWith(`${myVersion}\n`);Merge pull request #1305 from tj/release/6.xTomoaki Abebefore adoptionc5a5e7b
lines 111–114why, one step back111 });112113 test('when specify just custom long flag then display version', () => {114 const myVersion = '1.2.3';configure output (#1387)John Geebefore adoptioned7f13e
line 115why, one step back115 const writeMock = jest.fn();Merge pull request #1305 from tj/release/6.xTomoaki Abebefore adoptionc5a5e7b
lines 116–118why, one step back116 const program = new commander.Command();117 program118 .exitOverride()configure output (#1387)John Geebefore adoptioned7f13e
line 119why, one step back119 .configureOutput({ writeOut: writeMock })Merge pull request #1305 from tj/release/6.xTomoaki Abebefore adoptionc5a5e7b
line 120why, one step back120 .version(myVersion, '--revision');Update dependencies (#1214)John Geebefore adoption2aad525
lines 121–124why, one step back121122 expect(() => {123 program.parse(['node', 'test', '--revision']);124 }).toThrow(myVersion);configure output (#1387)John Geebefore adoptioned7f13e
line 125why, one step back125 expect(writeMock).toHaveBeenCalledWith(`${myVersion}\n`);Update dependencies (#1214)John Geebefore adoption2aad525
lines 126–156why, one step back126 });127128 test('when custom .version then helpInformation includes custom version help', () => {129 const myVersion = '1.2.3';130 const myVersionFlags = '-r, --revision';131 const myVersionDescription = 'custom description';132 const program = new commander.Command();133 program134 .version(myVersion, myVersionFlags, myVersionDescription);135136 const helpInformation = program.helpInformation();137138 expect(helpInformation.includes(myVersionFlags)).toBe(true);139 expect(helpInformation.includes(myVersionDescription)).toBe(true);140 });141142 test('when have .version+version and specify version then command called', () => {143 const actionMock = jest.fn();144 const program = new commander.Command();145 program146 .version('1.2.3')147 .command('version')148 .action(actionMock);149150 program.parse(['node', 'test', 'version']);151152 expect(actionMock).toHaveBeenCalled();153 });154155 test('when have .version+version and specify --version then version displayed', () => {156 const myVersion = '1.2.3';configure output (#1387)John Geebefore adoptioned7f13e
line 157why, one step back157 const writeMock = jest.fn();Update dependencies (#1214)John Geebefore adoption2aad525
lines 158–160why, one step back158 const program = new commander.Command();159 program160 .exitOverride()configure output (#1387)John Geebefore adoptioned7f13e
line 161why, one step back161 .configureOutput({ writeOut: writeMock })Update dependencies (#1214)John Geebefore adoption2aad525
lines 162–168why, one step back162 .version(myVersion)163 .command('version')164 .action(() => {});165166 expect(() => {167 program.parse(['node', 'test', '--version']);168 }).toThrow(myVersion);configure output (#1387)John Geebefore adoptioned7f13e
line 169why, one step back169 expect(writeMock).toHaveBeenCalledWith(`${myVersion}\n`);Update dependencies (#1214)John Geebefore adoption2aad525
line 170why, one step back170 });Merge branch 'develop' into release/7.xJohn Geebefore adoptiond90ef12
lines 171–177why, one step back171172 test('when specify version then can get version', () => {173 const myVersion = '1.2.3';174 const program = new commander.Command();175 program.version(myVersion);176 expect(program.version()).toEqual(myVersion);177 });Update dependencies (#1214)John Geebefore adoption2aad525
line 178why, one step back178});