Skip to content
Myr

command.alias.test.js

This file

Path

tests/command.alias.test.js

110 lines · 4.1 KiB · JavaScript

Last changed by

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

History of this file

Take it

The walk stopped after 200 commits: lines older than b2842dc point at it.

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 1why, one step back
1const commander = require('../');

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

lines 2–3why, one step back
2const { test, describe } = require('node:test');
3const assert = require('node:assert/strict');

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 4–7why, one step back
4
5// Running alias commands is tested in command.executableSubcommand.lookup.test.js6// Test various other behaviours for .alias7

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

lines 8–14why, one step back
8describe('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 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 15why, one step back
15

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

lines 16–21why, one step back
16 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 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 22why, one step back
22

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

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

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 29why, one step back
29

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

lines 30–38why, one step back
30 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 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 39why, one step back
39

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

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

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 47why, one step back
47

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

lines 48–54why, one step back
48 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 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 55why, one step back
55

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

lines 56–62why, one step back
56 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 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 63why, one step back
63

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

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

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 70why, one step back
70

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

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

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 77why, one step back
77

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

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

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 84–85why, one step back
84});
85

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

lines 86–87why, one step back
86describe('Command.aliases() parameter is treated as readonly, per TypeScript declaration', () => {
87 test('when .aliases() called then parameter does not change', () => {

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 88–91why, one step back
88 // 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 back
92 assert.deepEqual(param, original);

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 93–94why, one step back
93 });
94

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

line 95why, one step back
95 test('when .aliases() called and aliases later changed then parameter does not change', () => {

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 96–99why, one step back
96 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 back
100 assert.deepEqual(param, original);

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 101–102why, one step back
101 });
102

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

line 103why, one step back
103 test('when .aliases() called and parameter later changed then aliases does not change', () => {

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 104–107why, one step back
104 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 back
108 assert.deepEqual(cmd.aliases(), original);

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 109–110why, one step back
109 });
110});