command.showHelpAfterError.test.js
This file
Path
tests/command.showHelpAfterError.test.js
139 lines · 4.2 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 3103c6b point at it.
Add more tests for implies (#1730)John Geebefore adoption3103c6b
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, mock } = require('node:test');3const assert = require('node:assert/strict');Add more tests for implies (#1730)John Geebefore adoption3103c6b
line 4why, one step back4Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 5why, one step back5describe('Command.showHelpAfterError(message)', () => {Add more tests for implies (#1730)John Geebefore adoption3103c6b
lines 6–7why, one step back6 const customHelpMessage = 'See --help';7Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 8–9why, one step back8 function makeProgram(t) {9 const writeMock = t.mock.fn();Add more tests for implies (#1730)John Geebefore adoption3103c6b
lines 10–18why, one step back10 const program = new commander.Command();11 program12 .exitOverride()13 .showHelpAfterError(customHelpMessage)14 .configureOutput({ writeErr: writeMock });1516 return { program, writeMock };17 }18Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 19–20why, one step back19 test('when missing command-argument then shows help', (t) => {20 const { program, writeMock } = makeProgram(t);Add more tests for implies (#1730)John Geebefore adoption3103c6b
line 21why, one step back21 program.argument('<file>');Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 22–31why, one step back22 assert.throws(23 () => {24 program.parse([], { from: 'user' });25 },26 {27 code: 'commander.missingArgument',28 },29 );30 const lastCall = writeMock.mock.calls[writeMock.mock.calls.length - 1];31 assert.equal(lastCall.arguments[0], `${customHelpMessage}\n`);Add more tests for implies (#1730)John Geebefore adoption3103c6b
lines 32–33why, one step back32 });33Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 34–35why, one step back34 test('when missing option-argument then shows help', (t) => {35 const { program, writeMock } = makeProgram(t);Add more tests for implies (#1730)John Geebefore adoption3103c6b
line 36why, one step back36 program.option('--output <file>');Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 37–46why, one step back37 assert.throws(38 () => {39 program.parse(['--output'], { from: 'user' });40 },41 {42 code: 'commander.optionMissingArgument',43 },44 );45 const lastCall = writeMock.mock.calls[writeMock.mock.calls.length - 1];46 assert.equal(lastCall.arguments[0], `${customHelpMessage}\n`);Add more tests for implies (#1730)John Geebefore adoption3103c6b
lines 47–48why, one step back47 });48Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 49–50why, one step back49 test('when missing mandatory option then shows help', (t) => {50 const { program, writeMock } = makeProgram(t);Add more tests for implies (#1730)John Geebefore adoption3103c6b
line 51why, one step back51 program.requiredOption('--password <cipher>');Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 52–61why, one step back52 assert.throws(53 () => {54 program.parse([], { from: 'user' });55 },56 {57 code: 'commander.missingMandatoryOptionValue',58 },59 );60 const lastCall = writeMock.mock.calls[writeMock.mock.calls.length - 1];61 assert.equal(lastCall.arguments[0], `${customHelpMessage}\n`);Add more tests for implies (#1730)John Geebefore adoption3103c6b
lines 62–63why, one step back62 });63Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 64–75why, one step back64 test('when unknown option then shows help', (t) => {65 const { program, writeMock } = makeProgram(t);66 assert.throws(67 () => {68 program.parse(['--unknown-option'], { from: 'user' });69 },70 {71 code: 'commander.unknownOption',72 },73 );74 const lastCall = writeMock.mock.calls[writeMock.mock.calls.length - 1];75 assert.equal(lastCall.arguments[0], `${customHelpMessage}\n`);Add more tests for implies (#1730)John Geebefore adoption3103c6b
lines 76–77why, one step back76 });77Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 78–79why, one step back78 test('when too many command-arguments then shows help', (t) => {79 const { program, writeMock } = makeProgram(t);Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 80why, one step back80 program.allowExcessArguments(false);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 81–90why, one step back81 assert.throws(82 () => {83 program.parse(['surprise'], { from: 'user' });84 },85 {86 code: 'commander.excessArguments',87 },88 );89 const lastCall = writeMock.mock.calls[writeMock.mock.calls.length - 1];90 assert.equal(lastCall.arguments[0], `${customHelpMessage}\n`);Add more tests for implies (#1730)John Geebefore adoption3103c6b
lines 91–92why, one step back91 });92Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 93–94why, one step back93 test('when unknown command then shows help', (t) => {94 const { program, writeMock } = makeProgram(t);Add more tests for implies (#1730)John Geebefore adoption3103c6b
line 95why, one step back95 program.command('sub1');Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 96–105why, one step back96 assert.throws(97 () => {98 program.parse(['sub2'], { from: 'user' });99 },100 {101 code: 'commander.unknownCommand',102 },103 );104 const lastCall = writeMock.mock.calls[writeMock.mock.calls.length - 1];105 assert.equal(lastCall.arguments[0], `${customHelpMessage}\n`);Add more tests for implies (#1730)John Geebefore adoption3103c6b
lines 106–107why, one step back106 });107Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 108–109why, one step back108 test('when invalid option choice then shows help', (t) => {109 const { program, writeMock } = makeProgram(t);Add more tests for implies (#1730)John Geebefore adoption3103c6b
line 110why, one step back110 program.addOption(new commander.Option('--color').choices(['red', 'blue']));Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 111–120why, one step back111 assert.throws(112 () => {113 program.parse(['--color', 'pink'], { from: 'user' });114 },115 {116 code: 'commander.invalidArgument',117 },118 );119 const lastCall = writeMock.mock.calls[writeMock.mock.calls.length - 1];120 assert.equal(lastCall.arguments[0], `${customHelpMessage}\n`);Add more tests for implies (#1730)John Geebefore adoption3103c6b
lines 121–123why, one step back121 });122});123Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 124why, one step back124test('when Command.showHelpAfterError() and error and then shows full help', () => {Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 125why, one step back125 const writeMock = mock.fn();Add more tests for implies (#1730)John Geebefore adoption3103c6b
lines 126–133why, one step back126 const program = new commander.Command();127 program128 .exitOverride()129 .showHelpAfterError()130 .configureOutput({ writeErr: writeMock });131132 try {133 program.parse(['--unknown-option'], { from: 'user' });Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 134–136why, one step back134 } catch (err) {135 /* empty */136 }Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 137–138why, one step back137 const lastCall = writeMock.mock.calls[writeMock.mock.calls.length - 1];138 assert.equal(lastCall.arguments[0], program.helpInformation());Add more tests for implies (#1730)John Geebefore adoption3103c6b
line 139why, one step back139});