command.default.test.js
This file
Path
tests/command.default.test.js
93 lines · 3.3 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–6why, one step back1import * as childProcess from 'child_process';2import * as commander from '../index.js';3import * as path from 'path';4import * as util from 'util';5import { test, describe } from 'node:test';6import assert from 'node:assert/strict';Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 7–11why, one step back78const execFileAsync = util.promisify(childProcess.execFile);910describe('default executable command', () => {11 // Calling node explicitly so pm works without file suffix cross-platform.Switching to esm-only (#2464)John Geebefore adoptionf4bd470
line 12why, one step back12 const pm = path.join(import.meta.dirname, './fixtures/pm');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 13why, one step back13Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 14why, one step back14 test('when default subcommand and no command then call default', async () => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 15why, one step back15 const { stdout } = await execFileAsync('node', [pm]);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 16why, one step back16 assert.equal(stdout, 'default\n');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 17–18why, one step back17 });18Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 19why, one step back19 test('when default subcommand and unrecognised argument then call default with argument', async () => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 20why, one step back20 const { stdout } = await execFileAsync('node', [pm, 'an-argument']);Switching to esm-only (#2464)John Geebefore adoptionf4bd470
line 21why, one step back21 assert.equal(stdout, 'default\n["an-argument"]\n');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 22–23why, one step back22 });23Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 24why, one step back24 test('when default subcommand and unrecognised option then call default with option', async () => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 25why, one step back25 const { stdout } = await execFileAsync('node', [pm, '--an-option']);Switching to esm-only (#2464)John Geebefore adoptionf4bd470
line 26why, one step back26 assert.equal(stdout, 'default\n["--an-option"]\n');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 27–30why, one step back27 });28});2930describe('default action command', () => {Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 31why, one step back31 function makeProgram(t) {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 32why, one step back32 const program = new commander.Command();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 33why, one step back33 const actionMock = t.mock.fn();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 34why, one step back34 program.command('other');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 35–42why, one step back35 program36 .command('default', { isDefault: true })37 .allowUnknownOption()38 .allowExcessArguments()39 .action(actionMock);40 return { program, actionMock };41 }42Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 43–44why, one step back43 test('when default subcommand and no command then call default', (t) => {44 const { program, actionMock } = makeProgram(t);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 45why, one step back45 program.parse('node test.js'.split(' '));Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 46why, one step back46 assert.equal(actionMock.mock.callCount(), 1);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 47–48why, one step back47 });48Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 49–50why, one step back49 test('when default subcommand and unrecognised argument then call default', (t) => {50 const { program, actionMock } = makeProgram(t);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 51why, one step back51 program.parse('node test.js an-argument'.split(' '));Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 52why, one step back52 assert.equal(actionMock.mock.callCount(), 1);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 53–54why, one step back53 });54Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 55–56why, one step back55 test('when default subcommand and unrecognised option then call default', (t) => {56 const { program, actionMock } = makeProgram(t);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 57why, one step back57 program.parse('node test.js --an-option'.split(' '));Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 58why, one step back58 assert.equal(actionMock.mock.callCount(), 1);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 59–62why, one step back59 });60});6162describe('default added command', () => {Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 63–64why, one step back63 function makeProgram(t) {64 const actionMock = t.mock.fn();Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 65–70why, one step back65 const defaultCmd = new commander.Command('default')66 .allowUnknownOption()67 .allowExcessArguments()68 .action(actionMock);6970 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 71–72why, one step back71 program.command('other');72 program.addCommand(defaultCmd, { isDefault: true });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 73–75why, one step back73 return { program, actionMock };74 }75Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 76–77why, one step back76 test('when default subcommand and no command then call default', (t) => {77 const { program, actionMock } = makeProgram(t);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 78why, one step back78 program.parse('node test.js'.split(' '));Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 79why, one step back79 assert.equal(actionMock.mock.callCount(), 1);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 80–81why, one step back80 });81Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 82–83why, one step back82 test('when default subcommand and unrecognised argument then call default', (t) => {83 const { program, actionMock } = makeProgram(t);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 84why, one step back84 program.parse('node test.js an-argument'.split(' '));Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 85why, one step back85 assert.equal(actionMock.mock.callCount(), 1);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 86–87why, one step back86 });87Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 88–89why, one step back88 test('when default subcommand and unrecognised option then call default', (t) => {89 const { program, actionMock } = makeProgram(t);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 90why, one step back90 program.parse('node test.js --an-option'.split(' '));Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 91why, one step back91 assert.equal(actionMock.mock.callCount(), 1);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 92–93why, one step back92 });93});