Skip to content
Myr

command.onCommand.test.js

This file

Path

tests/command.onCommand.test.js

37 lines · 1.5 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// The action handler used to be implemented using command events and listeners.6// Now, this is mostly just for backwards compatibility.7

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

line 8why, one step back
8describe("Command.command('*')", () => {

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

lines 9–10why, one step back
9 test('when action handler for subcommand then emit command:subcommand', (t) => {
10 const mockListener = t.mock.fn();

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 11why, one step back
11 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 12why, one step back
12 program.command('sub').action(() => {});

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 13–14why, one step back
13 program.on('command:sub', mockListener);
14 program.parse(['sub'], { from: 'user' });

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

line 15why, one step back
15 assert.equal(mockListener.mock.callCount(), 1);

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 16–17why, one step back
16 });
17

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

lines 18–19why, one step back
18 test('when no action handler for subcommand then still emit command:subcommand', (t) => {
19 const mockListener = t.mock.fn();

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 20why, one step back
20 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 21why, one step back
21 program.command('sub');

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 22–23why, one step back
22 program.on('command:sub', mockListener);
23 program.parse(['sub'], { from: 'user' });

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

line 24why, one step back
24 assert.equal(mockListener.mock.callCount(), 1);

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 25–26why, one step back
25 });
26

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

lines 27–28why, one step back
27 test('when subcommand has argument then emit command:subcommand with argument', (t) => {
28 const mockListener = t.mock.fn();

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 29why, one step back
29 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 30why, one step back
30 program.command('sub <file>').action(() => {});

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 31–32why, one step back
31 program.on('command:sub', mockListener);
32 program.parse(['sub', 'file'], { from: 'user' });

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

lines 33–35why, one step back
33 assert.equal(mockListener.mock.callCount(), 1);
34 const callArgs = mockListener.mock.calls[0].arguments;35 assert.deepEqual(callArgs, [['file'], []]);

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 36–37why, one step back
36 });
37});