Skip to content
Myr

command.alias.test.js

This file

Path

tests/command.alias.test.js

103 lines · 3.7 KiB · JavaScript

Last changed by

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

History of this file

Take it

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

Change .action() JSDoc/TSDoc example (#1614)John Geebefore adoption36c2f68

lines 1–7why, one step back
1const commander = require('../');
23// Running alias commands is tested in command.executableSubcommand.lookup.test.js4// Test various other behaviours for .alias56test('when command has alias then appears in help', () => {7 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 8why, one step back
8 program.command('info [thing]').alias('i');

Change .action() JSDoc/TSDoc example (#1614)John Geebefore adoption36c2f68

lines 9–14why, one step back
9 const helpInformation = program.helpInformation();
10 expect(helpInformation).toMatch('info|i');11});1213test('when command has aliases added separately then only first appears in help', () => {14 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 15why, one step back
15 program.command('list [thing]').alias('ls').alias('dir');

Change .action() JSDoc/TSDoc example (#1614)John Geebefore adoption36c2f68

lines 16–21why, one step back
16 const helpInformation = program.helpInformation();
17 expect(helpInformation).toMatch('list|ls ');18});1920test('when command has aliases then only first appears in help', () => {21 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 22why, one step back
22 program.command('list [thing]').aliases(['ls', 'dir']);

Change .action() JSDoc/TSDoc example (#1614)John Geebefore adoption36c2f68

lines 23–29why, one step back
23 const helpInformation = program.helpInformation();
24 expect(helpInformation).toMatch('list|ls ');25});2627test('when command name = alias then error', () => {28 const program = new commander.Command();29 expect(() => {

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 30why, one step back
30 program.command('fail').alias('fail');

Change .action() JSDoc/TSDoc example (#1614)John Geebefore adoption36c2f68

lines 31–36why, one step back
31 }).toThrow("Command alias can't be the same as its name");
32});3334test('when use alias then action handler called', () => {35 const program = new commander.Command();36 const actionMock = jest.fn();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 37why, one step back
37 program.command('list').alias('ls').action(actionMock);

Change .action() JSDoc/TSDoc example (#1614)John Geebefore adoption36c2f68

lines 38–44why, one step back
38 program.parse(['ls'], { from: 'user' });
39 expect(actionMock).toHaveBeenCalled();40});4142test('when use second alias added separately then action handler called', () => {43 const program = new commander.Command();44 const actionMock = jest.fn();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 45why, one step back
45 program.command('list').alias('ls').alias('dir').action(actionMock);

Change .action() JSDoc/TSDoc example (#1614)John Geebefore adoption36c2f68

lines 46–52why, one step back
46 program.parse(['dir'], { from: 'user' });
47 expect(actionMock).toHaveBeenCalled();48});4950test('when use second of aliases then action handler called', () => {51 const program = new commander.Command();52 const actionMock = jest.fn();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 53why, one step back
53 program.command('list').aliases(['ls', 'dir']).action(actionMock);

Change .action() JSDoc/TSDoc example (#1614)John Geebefore adoption36c2f68

lines 54–74why, one step back
54 program.parse(['dir'], { from: 'user' });
55 expect(actionMock).toHaveBeenCalled();56});5758test('when set alias then can get alias', () => {59 const program = new commander.Command();60 const alias = 'abcde';61 program.alias(alias);62 expect(program.alias()).toEqual(alias);63});6465test('when set aliases then can get aliases', () => {66 const program = new commander.Command();67 const aliases = ['a', 'b'];68 program.aliases(aliases);69 expect(program.aliases()).toEqual(aliases);70});7172test('when set alias on executable then can get alias', () => {73 const program = new commander.Command();74 const alias = 'abcde';

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 75why, one step back
75 program.command('external', 'external command').alias(alias);

Change .action() JSDoc/TSDoc example (#1614)John Geebefore adoption36c2f68

lines 76–77why, one step back
76 expect(program.commands[0].alias()).toEqual(alias);
77});

Merge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c

lines 78–103why, one step back
78
79describe('aliases parameter is treated as readonly, per TypeScript declaration', () => {80 test('when aliases called then parameter does not change', () => {81 // Unlikely this could break, but check the API we are declaring in TypeScript.82 const original = ['b', 'bld'];83 const param = original.slice();84 new commander.Command('build').aliases(param);85 expect(param).toEqual(original);86 });8788 test('when aliases called and aliases later changed then parameter does not change', () => {89 const original = ['b', 'bld'];90 const param = original.slice();91 const cmd = new commander.Command('build').aliases(param);92 cmd.alias('BBB');93 expect(param).toEqual(original);94 });9596 test('when aliases called and parameter later changed then aliases does not change', () => {97 const original = ['b', 'bld'];98 const param = original.slice();99 const cmd = new commander.Command('build').aliases(param);100 param.length = 0;101 expect(cmd.aliases()).toEqual(original);102 });103});