command.addCommand.test.js
This file
Path
tests/command.addCommand.test.js
61 lines · 2.1 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
line 4why, one step back4Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 5–12why, one step back5describe('Command.addCommand()', () => {6 // simple sanity check subcommand works7 test('when addCommand and specify subcommand then called', (t) => {8 const program = new commander.Command();9 const leafAction = t.mock.fn();10 const sub = new commander.Command();11 sub.name('sub').action(leafAction);12 program.addCommand(sub);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 13why, one step back13Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 14–16why, one step back14 program.parse('node test.js sub'.split(' '));15 assert.equal(leafAction.mock.callCount(), 1);16 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 17why, one step back17Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 18–22why, one step back18 test('when commands added using .addCommand and .command then internals similar', () => {19 const program1 = new commander.Command();20 program1.command('sub');21 const program2 = new commander.Command();22 program2.addCommand(new commander.Command('sub'));Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 23why, one step back23Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 24–25why, one step back24 // This is a bit of a cheat to check using .addCommand() produces similar result to .command(),25 // since .command() is well tested and understood.Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 26why, one step back26Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 27–30why, one step back27 const cmd1 = program1.commands[0];28 const cmd2 = program2.commands[0];29 assert.equal(cmd1.parent, program1);30 assert.equal(cmd2.parent, program2);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 31why, one step back31Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 32–41why, one step back32 for (const key of Object.keys(cmd1)) {33 switch (typeof cmd1[key]) {34 case 'string':35 case 'boolean':36 case 'number':37 case 'undefined':38 // Compare values in a way that will be readable in test failure message.39 assert.equal(`${key}:${cmd1[key]}`, `${key}:${cmd2[key]}`);40 break;41 }Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 42why, one step back42 }Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 43why, one step back43 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 44why, one step back44Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 45–50why, one step back45 test('when command without name passed to .addCommand then throw', () => {46 const program = new commander.Command();47 const cmd = new commander.Command();48 assert.throws(() => {49 program.addCommand(cmd);50 });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 51why, one step back51 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 52why, one step back52Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 53–59why, one step back53 test('when executable command with custom executableFile passed to .addCommand then ok', () => {54 const program = new commander.Command();55 const cmd = new commander.Command('sub');56 cmd.command('exec', 'exec description', { executableFile: 'custom' });57 assert.doesNotThrow(() => {58 program.addCommand(cmd);59 });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 60why, one step back60 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 61why, one step back61});