command.onCommand.test.js
This file
Path
tests/command.onCommand.test.js
37 lines · 1.5 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// The action handler used to be implemented using command events and listeners.6// Now, this is mostly just for backwards compatibility.7Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 8why, one step back8describe("Command.command('*')", () => {Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 9–10why, one step back9 test('when action handler for subcommand then emit command:subcommand', (t) => {10 const mockListener = t.mock.fn();Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 11why, one step back11 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 12why, one step back12 program.command('sub').action(() => {});Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 13–14why, one step back13 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 back15 assert.equal(mockListener.mock.callCount(), 1);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 16–17why, one step back16 });17Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 18–19why, one step back18 test('when no action handler for subcommand then still emit command:subcommand', (t) => {19 const mockListener = t.mock.fn();Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 20why, one step back20 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 21why, one step back21 program.command('sub');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 22–23why, one step back22 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 back24 assert.equal(mockListener.mock.callCount(), 1);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 25–26why, one step back25 });26Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 27–28why, one step back27 test('when subcommand has argument then emit command:subcommand with argument', (t) => {28 const mockListener = t.mock.fn();Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 29why, one step back29 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 30why, one step back30 program.command('sub <file>').action(() => {});Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 31–32why, one step back31 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 back33 assert.equal(mockListener.mock.callCount(), 1);34 const callArgs = mockListener.mock.calls[0].arguments;35 assert.deepEqual(callArgs, [['file'], []]);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 36–37why, one step back36 });37});