Skip to content
Myr

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 file

Take 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 back
1const 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 back
5const { 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 back
7
8const 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');13

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 14why, one step back
14 test('when default subcommand and no command then call default', async () => {

Add more tests for implies (#1730)John Geebefore adoption3103c6b

line 15why, one step back
15 const { stdout } = await execFileAsync('node', [pm]);

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

line 16why, one step back
16 assert.equal(stdout, 'default\n');

Add more tests for implies (#1730)John Geebefore adoption3103c6b

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

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 19why, one step back
19 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 back
20 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 back
21 assert.equal(stdout, "default\n[ 'an-argument' ]\n");

Add more tests for implies (#1730)John Geebefore adoption3103c6b

lines 22–23why, one step back
22 });
23

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 24why, one step back
24 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 back
25 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 back
26 assert.equal(stdout, "default\n[ '--an-option' ]\n");

Add more tests for implies (#1730)John Geebefore adoption3103c6b

lines 27–30why, one step back
27 });
28});2930describe('default action command', () => {

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

line 31why, one step back
31 function makeProgram(t) {

Add more tests for implies (#1730)John Geebefore adoption3103c6b

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

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

line 33why, one step back
33 const actionMock = t.mock.fn();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 34why, one step back
34 program.command('other');

Add more tests for implies (#1730)John Geebefore adoption3103c6b

lines 35–42why, one step back
35 program
36 .command('default', { isDefault: true })37 .allowUnknownOption()38 .allowExcessArguments()39 .action(actionMock);40 return { program, actionMock };41 }42

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

lines 43–44why, one step back
43 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 back
45 program.parse('node test.js'.split(' '));

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

line 46why, one step back
46 assert.equal(actionMock.mock.callCount(), 1);

Add more tests for implies (#1730)John Geebefore adoption3103c6b

lines 47–48why, one step back
47 });
48

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

lines 49–50why, one step back
49 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 back
51 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 back
52 assert.equal(actionMock.mock.callCount(), 1);

Add more tests for implies (#1730)John Geebefore adoption3103c6b

lines 53–54why, one step back
53 });
54

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

lines 55–56why, one step back
55 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 back
57 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 back
58 assert.equal(actionMock.mock.callCount(), 1);

Add more tests for implies (#1730)John Geebefore adoption3103c6b

lines 59–62why, one step back
59 });
60});6162describe('default added command', () => {

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

lines 63–64why, one step back
63 function makeProgram(t) {
64 const actionMock = t.mock.fn();

Add more tests for implies (#1730)John Geebefore adoption3103c6b

lines 65–70why, one step back
65 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 back
71 program.command('other');
72 program.addCommand(defaultCmd, { isDefault: true });

Add more tests for implies (#1730)John Geebefore adoption3103c6b

lines 73–75why, one step back
73 return { program, actionMock };
74 }75

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

lines 76–77why, one step back
76 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 back
78 program.parse('node test.js'.split(' '));

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

line 79why, one step back
79 assert.equal(actionMock.mock.callCount(), 1);

Add more tests for implies (#1730)John Geebefore adoption3103c6b

lines 80–81why, one step back
80 });
81

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

lines 82–83why, one step back
82 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 back
84 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 back
85 assert.equal(actionMock.mock.callCount(), 1);

Add more tests for implies (#1730)John Geebefore adoption3103c6b

lines 86–87why, one step back
86 });
87

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

lines 88–89why, one step back
88 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 back
90 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 back
91 assert.equal(actionMock.mock.callCount(), 1);

Add more tests for implies (#1730)John Geebefore adoption3103c6b

lines 92–93why, one step back
92 });
93});