command.default.test.js
This file
Path
tests/command.default.test.js
93 lines · 3.3 KiB · JavaScript
Last changed by
Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
History of this fileTake it
The walk stopped after 200 commits: lines older than 3103c6b point at it.
Add more tests for implies (#1730)John Geebefore adoption3103c6b
lines 1–4why, one step back1const childProcess = require('child_process');2const commander = require('../');3const path = require('path');4const util = require('util');Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 5–6why, one step back5const { test, describe } = require('node:test');6const assert = require('node:assert/strict');Add more tests for implies (#1730)John Geebefore adoption3103c6b
lines 7–13why, one step back78const execFileAsync = util.promisify(childProcess.execFile);910describe('default executable command', () => {11 // Calling node explicitly so pm works without file suffix cross-platform.12 const pm = path.join(__dirname, './fixtures/pm');13Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 14why, one step back14 test('when default subcommand and no command then call default', async () => {Add more tests for implies (#1730)John Geebefore adoption3103c6b
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 more tests for implies (#1730)John Geebefore adoption3103c6b
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 more tests for implies (#1730)John Geebefore adoption3103c6b
line 20why, one step back20 const { stdout } = await execFileAsync('node', [pm, 'an-argument']);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 21why, one step back21 assert.equal(stdout, "default\n[ 'an-argument' ]\n");Add more tests for implies (#1730)John Geebefore adoption3103c6b
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 more tests for implies (#1730)John Geebefore adoption3103c6b
line 25why, one step back25 const { stdout } = await execFileAsync('node', [pm, '--an-option']);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 26why, one step back26 assert.equal(stdout, "default\n[ '--an-option' ]\n");Add more tests for implies (#1730)John Geebefore adoption3103c6b
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 more tests for implies (#1730)John Geebefore adoption3103c6b
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 more tests for implies (#1730)John Geebefore adoption3103c6b
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 more tests for implies (#1730)John Geebefore adoption3103c6b
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 more tests for implies (#1730)John Geebefore adoption3103c6b
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 more tests for implies (#1730)John Geebefore adoption3103c6b
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 more tests for implies (#1730)John Geebefore adoption3103c6b
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 more tests for implies (#1730)John Geebefore adoption3103c6b
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 more tests for implies (#1730)John Geebefore adoption3103c6b
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 more tests for implies (#1730)John Geebefore adoption3103c6b
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 more tests for implies (#1730)John Geebefore adoption3103c6b
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 more tests for implies (#1730)John Geebefore adoption3103c6b
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 more tests for implies (#1730)John Geebefore adoption3103c6b
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 more tests for implies (#1730)John Geebefore adoption3103c6b
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 more tests for implies (#1730)John Geebefore adoption3103c6b
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 more tests for implies (#1730)John Geebefore adoption3103c6b
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 more tests for implies (#1730)John Geebefore adoption3103c6b
lines 92–93why, one step back92 });93});