options.version.test.js
This file
Path
tests/options.version.test.js
183 lines · 6.0 KiB · JavaScript
Last changed by
Switching to esm-only (#2464)John Geebefore adoptionf4bd470
History of this fileTake it
The walk stopped after 200 commits: lines older than 471ec40 point at it.
Switching to esm-only (#2464)John Geebefore adoptionf4bd470
lines 1–3why, one step back1import * as commander from '../index.js';2import { test, describe } from 'node:test';3import assert from 'node:assert/strict';Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 4–6why, one step back45// Test .version. Using exitOverride to check behaviour (instead of mocking process.exit).6Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 7why, one step back7describe('Command.version()', () => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 8–9why, one step back8 test('when no .version and specify --version then unknown option error', () => {9 const program = new commander.Command();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 10why, one step back10 program.exitOverride().configureOutput({ writeErr: () => {} });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 11why, one step back11Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 12–17why, one step back12 assert.throws(13 () => {14 program.parse(['node', 'test', '--version']);15 },16 { code: 'commander.unknownOption' },17 );Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 18–24why, one step back18 });1920 test('when no .version then helpInformation does not include version', () => {21 const program = new commander.Command();2223 const helpInformation = program.helpInformation();24Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 25–26why, one step back25 assert.equal(helpInformation.includes('Usage'), true);26 assert.equal(helpInformation.includes('version'), false);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 27–28why, one step back27 });28Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 29why, one step back29 test('when specify default short flag then display version', (t) => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 30why, one step back30 const myVersion = '1.2.3';Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 31why, one step back31 const writeMock = t.mock.fn();Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 32–37why, one step back32 const program = new commander.Command();33 program34 .exitOverride()35 .configureOutput({ writeOut: writeMock })36 .version(myVersion);37Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 38why, one step back38 assert.throws(() => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 39why, one step back39 program.parse(['node', 'test', '-V']);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 40–42why, one step back40 }, new RegExp(myVersion));41 const callArgs = writeMock.mock.calls[0].arguments;42 assert.equal(callArgs[0], `${myVersion}\n`);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 43–44why, one step back43 });44Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 45why, one step back45 test('when specify default long flag then display version', (t) => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 46why, one step back46 const myVersion = '1.2.3';Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 47why, one step back47 const writeMock = t.mock.fn();Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 48–53why, one step back48 const program = new commander.Command();49 program50 .exitOverride()51 .configureOutput({ writeOut: writeMock })52 .version(myVersion);53Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 54why, one step back54 assert.throws(() => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 55why, one step back55 program.parse(['node', 'test', '--version']);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 56–58why, one step back56 }, new RegExp(myVersion));57 const callArgs = writeMock.mock.calls[0].arguments;58 assert.equal(callArgs[0], `${myVersion}\n`);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 59–63why, one step back59 });6061 test('when default .version then helpInformation includes default version help', () => {62 const myVersion = '1.2.3';63 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 64why, one step back64 program.version(myVersion);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 65–67why, one step back6566 const helpInformation = program.helpInformation();67Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 68–69why, one step back68 assert.equal(helpInformation.includes('-V, --version'), true);69 assert.equal(helpInformation.includes('output the version number'), true);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 70–71why, one step back70 });71Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 72why, one step back72 test('when specify custom short flag then display version', (t) => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 73why, one step back73 const myVersion = '1.2.3';Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 74why, one step back74 const writeMock = t.mock.fn();Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 75–80why, one step back75 const program = new commander.Command();76 program77 .exitOverride()78 .configureOutput({ writeOut: writeMock })79 .version(myVersion, '-r, --revision');80Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 81why, one step back81 assert.throws(() => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 82why, one step back82 program.parse(['node', 'test', '-r']);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 83–85why, one step back83 }, new RegExp(myVersion));84 const callArgs = writeMock.mock.calls[0].arguments;85 assert.equal(callArgs[0], `${myVersion}\n`);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 86–87why, one step back86 });87Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 88why, one step back88 test('when specify just custom short flag then display version', (t) => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 89why, one step back89 const myVersion = '1.2.3';Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 90why, one step back90 const writeMock = t.mock.fn();Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 91–96why, one step back91 const program = new commander.Command();92 program93 .exitOverride()94 .configureOutput({ writeOut: writeMock })95 .version(myVersion, '-r');96Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 97why, one step back97 assert.throws(() => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 98why, one step back98 program.parse(['node', 'test', '-r']);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 99–101why, one step back99 }, new RegExp(myVersion));100 const callArgs = writeMock.mock.calls[0].arguments;101 assert.equal(callArgs[0], `${myVersion}\n`);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 102–103why, one step back102 });103Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 104why, one step back104 test('when specify custom long flag then display version', (t) => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 105why, one step back105 const myVersion = '1.2.3';Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 106why, one step back106 const writeMock = t.mock.fn();Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 107–112why, one step back107 const program = new commander.Command();108 program109 .exitOverride()110 .configureOutput({ writeOut: writeMock })111 .version(myVersion, '-r, --revision');112Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 113why, one step back113 assert.throws(() => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 114why, one step back114 program.parse(['node', 'test', '--revision']);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 115–117why, one step back115 }, new RegExp(myVersion));116 const callArgs = writeMock.mock.calls[0].arguments;117 assert.equal(callArgs[0], `${myVersion}\n`);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 118–119why, one step back118 });119Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 120why, one step back120 test('when specify just custom long flag then display version', (t) => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 121why, one step back121 const myVersion = '1.2.3';Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 122why, one step back122 const writeMock = t.mock.fn();Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 123–128why, one step back123 const program = new commander.Command();124 program125 .exitOverride()126 .configureOutput({ writeOut: writeMock })127 .version(myVersion, '--revision');128Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 129why, one step back129 assert.throws(() => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 130why, one step back130 program.parse(['node', 'test', '--revision']);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 131–133why, one step back131 }, new RegExp(myVersion));132 const callArgs = writeMock.mock.calls[0].arguments;133 assert.equal(callArgs[0], `${myVersion}\n`);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 134–140why, one step back134 });135136 test('when custom .version then helpInformation includes custom version help', () => {137 const myVersion = '1.2.3';138 const myVersionFlags = '-r, --revision';139 const myVersionDescription = 'custom description';140 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 141why, one step back141 program.version(myVersion, myVersionFlags, myVersionDescription);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 142–144why, one step back142143 const helpInformation = program.helpInformation();144Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 145–146why, one step back145 assert.equal(helpInformation.includes(myVersionFlags), true);146 assert.equal(helpInformation.includes(myVersionDescription), true);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 147–148why, one step back147 });148Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 149–150why, one step back149 test('when have .version+version and specify version then command called', (t) => {150 const actionMock = t.mock.fn();Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 151why, one step back151 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 152why, one step back152 program.version('1.2.3').command('version').action(actionMock);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 153–155why, one step back153154 program.parse(['node', 'test', 'version']);155Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 156why, one step back156 assert.equal(actionMock.mock.callCount(), 1);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 157–158why, one step back157 });158Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 159why, one step back159 test('when have .version+version and specify --version then version displayed', (t) => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 160why, one step back160 const myVersion = '1.2.3';Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 161why, one step back161 const writeMock = t.mock.fn();Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 162–169why, one step back162 const program = new commander.Command();163 program164 .exitOverride()165 .configureOutput({ writeOut: writeMock })166 .version(myVersion)167 .command('version')168 .action(() => {});169Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 170why, one step back170 assert.throws(() => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 171why, one step back171 program.parse(['node', 'test', '--version']);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 172–174why, one step back172 }, new RegExp(myVersion));173 const callArgs = writeMock.mock.calls[0].arguments;174 assert.equal(callArgs[0], `${myVersion}\n`);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 175–180why, one step back175 });176177 test('when specify version then can get version', () => {178 const myVersion = '1.2.3';179 const program = new commander.Command();180 program.version(myVersion);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 181why, one step back181 assert.equal(program.version(), myVersion);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 182–183why, one step back182 });183});