command.alias.test.js
This file
Path
tests/command.alias.test.js
110 lines · 4.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
lines 4–7why, one step back45// Running alias commands is tested in command.executableSubcommand.lookup.test.js6// Test various other behaviours for .alias7Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 8–14why, one step back8describe('Command aliases using .alias() and .aliases()', () => {9 test('when command has alias then appears in help', () => {10 const program = new commander.Command();11 program.command('info [thing]').alias('i');12 const helpInformation = program.helpInformation();13 assert.match(helpInformation, /info\|i/);14 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 15why, one step back15Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 16–21why, one step back16 test('when command has aliases added separately then only first appears in help', () => {17 const program = new commander.Command();18 program.command('list [thing]').alias('ls').alias('dir');19 const helpInformation = program.helpInformation();20 assert.match(helpInformation, /list\|ls /);21 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 22why, one step back22Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 23–28why, one step back23 test('when command has aliases then only first appears in help', () => {24 const program = new commander.Command();25 program.command('list [thing]').aliases(['ls', 'dir']);26 const helpInformation = program.helpInformation();27 assert.match(helpInformation, /list\|ls /);28 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 29why, one step back29Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 30–38why, one step back30 test('when command name = alias then error', () => {31 const program = new commander.Command();32 assert.throws(33 () => {34 program.command('fail').alias('fail');35 },36 { message: "Command alias can't be the same as its name" },37 );38 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 39why, one step back39Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 40–46why, one step back40 test('when use alias then action handler called', (t) => {41 const program = new commander.Command();42 const actionMock = t.mock.fn();43 program.command('list').alias('ls').action(actionMock);44 program.parse(['ls'], { from: 'user' });45 assert.equal(actionMock.mock.callCount(), 1);46 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 47why, one step back47Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 48–54why, one step back48 test('when use second alias added separately then action handler called', (t) => {49 const program = new commander.Command();50 const actionMock = t.mock.fn();51 program.command('list').alias('ls').alias('dir').action(actionMock);52 program.parse(['dir'], { from: 'user' });53 assert.equal(actionMock.mock.callCount(), 1);54 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 55why, one step back55Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 56–62why, one step back56 test('when use second of aliases then action handler called', (t) => {57 const program = new commander.Command();58 const actionMock = t.mock.fn();59 program.command('list').aliases(['ls', 'dir']).action(actionMock);60 program.parse(['dir'], { from: 'user' });61 assert.equal(actionMock.mock.callCount(), 1);62 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 63why, one step back63Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 64–69why, one step back64 test('when set alias then can get alias', () => {65 const program = new commander.Command();66 const alias = 'abcde';67 program.alias(alias);68 assert.equal(program.alias(), alias);69 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 70why, one step back70Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 71–76why, one step back71 test('when set aliases then can get aliases', () => {72 const program = new commander.Command();73 const aliases = ['a', 'b'];74 program.aliases(aliases);75 assert.deepEqual(program.aliases(), aliases);76 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 77why, one step back77Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 78–83why, one step back78 test('when set alias on executable then can get alias', () => {79 const program = new commander.Command();80 const alias = 'abcde';81 program.command('external', 'external command').alias(alias);82 assert.equal(program.commands[0].alias(), alias);83 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 84–85why, one step back84});85Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 86–87why, one step back86describe('Command.aliases() parameter is treated as readonly, per TypeScript declaration', () => {87 test('when .aliases() called then parameter does not change', () => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 88–91why, one step back88 // Unlikely this could break, but check the API we are declaring in TypeScript.89 const original = ['b', 'bld'];90 const param = original.slice();91 new commander.Command('build').aliases(param);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 92why, one step back92 assert.deepEqual(param, original);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 93–94why, one step back93 });94Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 95why, one step back95 test('when .aliases() called and aliases later changed then parameter does not change', () => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 96–99why, one step back96 const original = ['b', 'bld'];97 const param = original.slice();98 const cmd = new commander.Command('build').aliases(param);99 cmd.alias('BBB');Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 100why, one step back100 assert.deepEqual(param, original);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 101–102why, one step back101 });102Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 103why, one step back103 test('when .aliases() called and parameter later changed then aliases does not change', () => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 104–107why, one step back104 const original = ['b', 'bld'];105 const param = original.slice();106 const cmd = new commander.Command('build').aliases(param);107 param.length = 0;Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 108why, one step back108 assert.deepEqual(cmd.aliases(), original);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 109–110why, one step back109 });110});