Skip to content
Myr

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 file

Take 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 back
1import * 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 back
4
5// Test .version. Using exitOverride to check behaviour (instead of mocking process.exit).6

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

line 7why, one step back
7describe('Command.version()', () => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 8–9why, one step back
8 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 back
10 program.exitOverride().configureOutput({ writeErr: () => {} });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 11why, one step back
11

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

lines 12–17why, one step back
12 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 back
18 });
1920 test('when no .version then helpInformation does not include version', () => {21 const program = new commander.Command();2223 const helpInformation = program.helpInformation();24

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

lines 25–26why, one step back
25 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 back
27 });
28

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 29why, one step back
29 test('when specify default short flag then display version', (t) => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 30why, one step back
30 const myVersion = '1.2.3';

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 31why, one step back
31 const writeMock = t.mock.fn();

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 32–37why, one step back
32 const program = new commander.Command();
33 program34 .exitOverride()35 .configureOutput({ writeOut: writeMock })36 .version(myVersion);37

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 38why, one step back
38 assert.throws(() => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 39why, one step back
39 program.parse(['node', 'test', '-V']);

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

lines 40–42why, one step back
40 }, 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 back
43 });
44

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 45why, one step back
45 test('when specify default long flag then display version', (t) => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 46why, one step back
46 const myVersion = '1.2.3';

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 47why, one step back
47 const writeMock = t.mock.fn();

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 48–53why, one step back
48 const program = new commander.Command();
49 program50 .exitOverride()51 .configureOutput({ writeOut: writeMock })52 .version(myVersion);53

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 54why, one step back
54 assert.throws(() => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 55why, one step back
55 program.parse(['node', 'test', '--version']);

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

lines 56–58why, one step back
56 }, 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 back
59 });
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 back
64 program.version(myVersion);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 65–67why, one step back
65
66 const helpInformation = program.helpInformation();67

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

lines 68–69why, one step back
68 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 back
70 });
71

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 72why, one step back
72 test('when specify custom short flag then display version', (t) => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 73why, one step back
73 const myVersion = '1.2.3';

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 74why, one step back
74 const writeMock = t.mock.fn();

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 75–80why, one step back
75 const program = new commander.Command();
76 program77 .exitOverride()78 .configureOutput({ writeOut: writeMock })79 .version(myVersion, '-r, --revision');80

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 81why, one step back
81 assert.throws(() => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 82why, one step back
82 program.parse(['node', 'test', '-r']);

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

lines 83–85why, one step back
83 }, 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 back
86 });
87

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 88why, one step back
88 test('when specify just custom short flag then display version', (t) => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 89why, one step back
89 const myVersion = '1.2.3';

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 90why, one step back
90 const writeMock = t.mock.fn();

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 91–96why, one step back
91 const program = new commander.Command();
92 program93 .exitOverride()94 .configureOutput({ writeOut: writeMock })95 .version(myVersion, '-r');96

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 97why, one step back
97 assert.throws(() => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 98why, one step back
98 program.parse(['node', 'test', '-r']);

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

lines 99–101why, one step back
99 }, 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 back
102 });
103

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 104why, one step back
104 test('when specify custom long flag then display version', (t) => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 105why, one step back
105 const myVersion = '1.2.3';

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 106why, one step back
106 const writeMock = t.mock.fn();

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 107–112why, one step back
107 const program = new commander.Command();
108 program109 .exitOverride()110 .configureOutput({ writeOut: writeMock })111 .version(myVersion, '-r, --revision');112

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 113why, one step back
113 assert.throws(() => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 114why, one step back
114 program.parse(['node', 'test', '--revision']);

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

lines 115–117why, one step back
115 }, 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 back
118 });
119

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 120why, one step back
120 test('when specify just custom long flag then display version', (t) => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 121why, one step back
121 const myVersion = '1.2.3';

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 122why, one step back
122 const writeMock = t.mock.fn();

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 123–128why, one step back
123 const program = new commander.Command();
124 program125 .exitOverride()126 .configureOutput({ writeOut: writeMock })127 .version(myVersion, '--revision');128

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 129why, one step back
129 assert.throws(() => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 130why, one step back
130 program.parse(['node', 'test', '--revision']);

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

lines 131–133why, one step back
131 }, 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 back
134 });
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 back
141 program.version(myVersion, myVersionFlags, myVersionDescription);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 142–144why, one step back
142
143 const helpInformation = program.helpInformation();144

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

lines 145–146why, one step back
145 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 back
147 });
148

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

lines 149–150why, one step back
149 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 back
151 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 152why, one step back
152 program.version('1.2.3').command('version').action(actionMock);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 153–155why, one step back
153
154 program.parse(['node', 'test', 'version']);155

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 156why, one step back
156 assert.equal(actionMock.mock.callCount(), 1);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 157–158why, one step back
157 });
158

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 159why, one step back
159 test('when have .version+version and specify --version then version displayed', (t) => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 160why, one step back
160 const myVersion = '1.2.3';

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 161why, one step back
161 const writeMock = t.mock.fn();

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 162–169why, one step back
162 const program = new commander.Command();
163 program164 .exitOverride()165 .configureOutput({ writeOut: writeMock })166 .version(myVersion)167 .command('version')168 .action(() => {});169

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 170why, one step back
170 assert.throws(() => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 171why, one step back
171 program.parse(['node', 'test', '--version']);

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

lines 172–174why, one step back
172 }, 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 back
175 });
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 back
181 assert.equal(program.version(), myVersion);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 182–183why, one step back
182 });
183});