command.addHelpText.test.js
This file
Path
tests/command.addHelpText.test.js
239 lines · 7.6 KiB · JavaScript
Last changed by
Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
History of this fileTake it
The walk stopped after 200 commits: lines older than b2842dc point at it.
update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 1why, one step back1const commander = require('../');Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 2–3why, one step back2const { test, describe, beforeEach } = require('node:test');3const assert = require('node:assert/strict');update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 4–6why, one step back45// Using outputHelp to simplify testing.6Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 7why, one step back7describe('Command.addHelpText(): program calls to addHelpText', () => {update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 8–9why, one step back8 let writeSpy;9Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 10–11why, one step back10 beforeEach((t) => {11 writeSpy = t.mock.method(process.stdout, 'write', () => {});update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 12–17why, one step back12 });1314 test('when "before" string then string before built-in help', () => {15 const program = new commander.Command();16 program.addHelpText('before', 'text');17 program.outputHelp();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 18–22why, one step back18 assert.equal(writeSpy.mock.calls[0].arguments[0], 'text\n');19 assert.equal(20 writeSpy.mock.calls[1].arguments[0],21 program.helpInformation(),22 );update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 23–28why, one step back23 });2425 test('when "before" function then function result before built-in help', () => {26 const program = new commander.Command();27 program.addHelpText('before', () => 'text');28 program.outputHelp();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 29–33why, one step back29 assert.equal(writeSpy.mock.calls[0].arguments[0], 'text\n');30 assert.equal(31 writeSpy.mock.calls[1].arguments[0],32 program.helpInformation(),33 );update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 34–37why, one step back34 });3536 test('when "before" function returns nothing then no effect', () => {37 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 38why, one step back38 program.addHelpText('before', () => {});update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 39why, one step back39 program.outputHelp();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 40–43why, one step back40 assert.equal(41 writeSpy.mock.calls[0].arguments[0],42 program.helpInformation(),43 );update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 44–49why, one step back44 });4546 test('when "beforeAll" string then string before built-in help', () => {47 const program = new commander.Command();48 program.addHelpText('beforeAll', 'text');49 program.outputHelp();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 50–54why, one step back50 assert.equal(writeSpy.mock.calls[0].arguments[0], 'text\n');51 assert.equal(52 writeSpy.mock.calls[1].arguments[0],53 program.helpInformation(),54 );update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 55–60why, one step back55 });5657 test('when "after" string then string after built-in help', () => {58 const program = new commander.Command();59 program.addHelpText('after', 'text');60 program.outputHelp();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 61–65why, one step back61 assert.equal(62 writeSpy.mock.calls[0].arguments[0],63 program.helpInformation(),64 );65 assert.equal(writeSpy.mock.calls[1].arguments[0], 'text\n');update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 66–71why, one step back66 });6768 test('when "afterAll" string then string after built-in help', () => {69 const program = new commander.Command();70 program.addHelpText('afterAll', 'text');71 program.outputHelp();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 72–76why, one step back72 assert.equal(73 writeSpy.mock.calls[0].arguments[0],74 program.helpInformation(),75 );76 assert.equal(writeSpy.mock.calls[1].arguments[0], 'text\n');update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 77–85why, one step back77 });7879 test('when all the simple positions then strings in order', () => {80 const program = new commander.Command();81 program.addHelpText('before', 'before');82 program.addHelpText('after', 'after');83 program.addHelpText('beforeAll', 'beforeAll');84 program.addHelpText('afterAll', 'afterAll');85 program.outputHelp();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 86–93why, one step back86 assert.equal(writeSpy.mock.calls[0].arguments[0], 'beforeAll\n');87 assert.equal(writeSpy.mock.calls[1].arguments[0], 'before\n');88 assert.equal(89 writeSpy.mock.calls[2].arguments[0],90 program.helpInformation(),91 );92 assert.equal(writeSpy.mock.calls[3].arguments[0], 'after\n');93 assert.equal(writeSpy.mock.calls[4].arguments[0], 'afterAll\n');update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 94–97why, one step back94 });9596 test('when "silly" position then throw', () => {97 const program = new commander.Command();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 98why, one step back98 assert.throws(() => {update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 99why, one step back99 program.addHelpText('silly', 'text');Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 100why, one step back100 });update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 101–103why, one step back101 });102});103Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 104why, one step back104describe('Command.addHelpText(): program and subcommand calls to addHelpText', () => {update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 105–106why, one step back105 let writeSpy;106Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 107–108why, one step back107 beforeEach((t) => {108 writeSpy = t.mock.method(process.stdout, 'write', () => {});update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 109–110why, one step back109 });110Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 111why, one step back111 test('when "before" on program then not called on subcommand', (t) => {update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 112–113why, one step back112 const program = new commander.Command();113 const sub = program.command('sub');Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 114why, one step back114 const testMock = t.mock.fn();update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 115–116why, one step back115 program.addHelpText('before', testMock);116 sub.outputHelp();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 117why, one step back117 assert.equal(testMock.mock.callCount(), 0);update chinese readme (#1727)wenjiebefore adoptionb2842dc
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 "beforeAll" on program then is called on subcommand', (t) => {update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 121–122why, one step back121 const program = new commander.Command();122 const sub = program.command('sub');Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 123why, one step back123 const testMock = t.mock.fn();update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 124–125why, one step back124 program.addHelpText('beforeAll', testMock);125 sub.outputHelp();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 126why, one step back126 assert.equal(testMock.mock.callCount(), 1);update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 127–128why, one step back127 });128Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 129why, one step back129 test('when "after" on program then not called on subcommand', (t) => {update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 130–131why, one step back130 const program = new commander.Command();131 const sub = program.command('sub');Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 132why, one step back132 const testMock = t.mock.fn();update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 133–134why, one step back133 program.addHelpText('after', testMock);134 sub.outputHelp();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 135why, one step back135 assert.equal(testMock.mock.callCount(), 0);update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 136–137why, one step back136 });137Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 138why, one step back138 test('when "afterAll" on program then is called on subcommand', (t) => {update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 139–140why, one step back139 const program = new commander.Command();140 const sub = program.command('sub');Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 141why, one step back141 const testMock = t.mock.fn();update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 142–143why, one step back142 program.addHelpText('afterAll', testMock);143 sub.outputHelp();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 144why, one step back144 assert.equal(testMock.mock.callCount(), 1);update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 145–147why, one step back145 });146});147Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 148why, one step back148describe('Command.addHelpText(): context checks with full parse', () => {update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 149–151why, one step back149 let stdoutSpy;150 let stderrSpy;151Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 152–154why, one step back152 beforeEach((t) => {153 stdoutSpy = t.mock.method(process.stdout, 'write', () => {});154 stderrSpy = t.mock.method(process.stderr, 'write', () => {});update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 155–158why, one step back155 });156157 test('when help requested then text is on stdout', () => {158 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 159why, one step back159 program.exitOverride().addHelpText('before', 'text');Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 160why, one step back160 assert.throws(() => {update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 161why, one step back161 program.parse(['--help'], { from: 'user' });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 162–163why, one step back162 });163 assert.equal(stdoutSpy.mock.calls[0].arguments[0], 'text\n');update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 164–167why, one step back164 });165166 test('when help for error then text is on stderr', () => {167 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 168why, one step back168 program.exitOverride().addHelpText('before', 'text').command('sub');Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 169why, one step back169 assert.throws(() => {update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 170why, one step back170 program.parse([], { from: 'user' });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 171–172why, one step back171 });172 assert.equal(stderrSpy.mock.calls[0].arguments[0], 'text\n');update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 173–175why, one step back173 });174175 test('when help requested then context.error is false', () => {Change initial variable values in test for better error messagesWee Bitbefore adoption401b0d6
line 176why, one step back176 let context;update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 177why, one step back177 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 178–180why, one step back178 program.exitOverride().addHelpText('before', (contextParam) => {179 context = contextParam;180 });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 181why, one step back181 assert.throws(() => {update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 182why, one step back182 program.parse(['--help'], { from: 'user' });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 183–184why, one step back183 });184 assert.equal(context.error, false);update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 185–187why, one step back185 });186187 test('when help for error then context.error is true', () => {Change initial variable values in test for better error messagesWee Bitbefore adoption401b0d6
line 188why, one step back188 let context;update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 189–191why, one step back189 const program = new commander.Command();190 program191 .exitOverride()Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 192–194why, one step back192 .addHelpText('before', (contextParam) => {193 context = contextParam;194 })update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 195why, one step back195 .command('sub');Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 196why, one step back196 assert.throws(() => {update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 197why, one step back197 program.parse([], { from: 'user' });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 198–199why, one step back198 });199 assert.equal(context.error, true);update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 200–202why, one step back200 });201202 test('when help on program then context.command is program', () => {Change initial variable values in test for better error messagesWee Bitbefore adoption401b0d6
line 203why, one step back203 let context;update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 204why, one step back204 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 205–207why, one step back205 program.exitOverride().addHelpText('before', (contextParam) => {206 context = contextParam;207 });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 208why, one step back208 assert.throws(() => {update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 209why, one step back209 program.parse(['--help'], { from: 'user' });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 210–211why, one step back210 });211 assert.equal(context.command, program);update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 212–214why, one step back212 });213214 test('when help on subcommand and "before" subcommand then context.command is subcommand', () => {Change initial variable values in test for better error messagesWee Bitbefore adoption401b0d6
line 215why, one step back215 let context;update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 216why, one step back216 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 217–220why, one step back217 program.exitOverride();218 const sub = program.command('sub').addHelpText('before', (contextParam) => {219 context = contextParam;220 });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 221why, one step back221 assert.throws(() => {update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 222why, one step back222 program.parse(['sub', '--help'], { from: 'user' });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 223–224why, one step back223 });224 assert.equal(context.command, sub);update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 225–227why, one step back225 });226227 test('when help on subcommand and "beforeAll" on program then context.command is subcommand', () => {Change initial variable values in test for better error messagesWee Bitbefore adoption401b0d6
line 228why, one step back228 let context;update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 229why, one step back229 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 230–232why, one step back230 program.exitOverride().addHelpText('beforeAll', (contextParam) => {231 context = contextParam;232 });update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 233why, one step back233 const sub = program.command('sub');Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 234why, one step back234 assert.throws(() => {update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 235why, one step back235 program.parse(['sub', '--help'], { from: 'user' });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 236–237why, one step back236 });237 assert.equal(context.command, sub);update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 238–239why, one step back238 });239});