Skip to content
Myr

command.default.test.js

This file

Path

tests/command.default.test.js

94 lines · 3.2 KiB · JavaScript

Last changed by

Merge branch 'master' into release/7.xJohn Geebefore adoption5fd6e88

History of this file

Take it

Parse rework for nested commands (#1149)John Geebefore adoption1345f98

lines 1–2why, one step back
1const childProcess = require('child_process');
2const commander = require('../');

Update dependencies and rewrite tests (#1167)John Geebefore adoptiond736ff7

lines 3–4why, one step back
3const path = require('path');
4const util = require('util');

Parse rework for nested commands (#1149)John Geebefore adoption1345f98

line 5why, one step back
5

Merge branch 'master' into release/7.xJohn Geebefore adoption5fd6e88

line 6why, one step back
6const execFileAsync = util.promisify(childProcess.execFile);

Update dependencies and rewrite tests (#1167)John Geebefore adoptiond736ff7

line 7why, one step back
7

Parse rework for nested commands (#1149)John Geebefore adoption1345f98

lines 8–11why, one step back
8describe('default executable command', () => {
9 // Calling node explicitly so pm works without file suffix cross-platform.10 const pm = path.join(__dirname, './fixtures/pm');11

Update dependencies and rewrite tests (#1167)John Geebefore adoptiond736ff7

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

Merge branch 'master' into release/7.xJohn Geebefore adoption5fd6e88

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

Update dependencies and rewrite tests (#1167)John Geebefore adoptiond736ff7

line 14why, one step back
14 expect(stdout).toBe('default\n');

Parse rework for nested commands (#1149)John Geebefore adoption1345f98

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

Update dependencies and rewrite tests (#1167)John Geebefore adoptiond736ff7

line 17why, one step back
17 test('when default subcommand and unrecognised argument then call default with argument', async() => {

Merge branch 'master' into release/7.xJohn Geebefore adoption5fd6e88

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

Update dependencies and rewrite tests (#1167)John Geebefore adoptiond736ff7

line 19why, one step back
19 expect(stdout).toBe("default\n[ 'an-argument' ]\n");

Parse rework for nested commands (#1149)John Geebefore adoption1345f98

lines 20–21why, one step back
20 });
21

Update dependencies and rewrite tests (#1167)John Geebefore adoptiond736ff7

line 22why, one step back
22 test('when default subcommand and unrecognised option then call default with option', async() => {

Merge branch 'master' into release/7.xJohn Geebefore adoption5fd6e88

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

Update dependencies and rewrite tests (#1167)John Geebefore adoptiond736ff7

line 24why, one step back
24 expect(stdout).toBe("default\n[ '--an-option' ]\n");

Parse rework for nested commands (#1149)John Geebefore adoption1345f98

lines 25–36why, one step back
25 });
26});2728describe('default action command', () => {29 function makeProgram() {30 const program = new commander.Command();31 const actionMock = jest.fn();32 program33 .command('other');34 program35 .command('default', { isDefault: true })36 .allowUnknownOption()

Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71

line 37why, one step back
37 .allowExcessArguments()

Parse rework for nested commands (#1149)John Geebefore adoption1345f98

lines 38–47why, one step back
38 .action(actionMock);
39 return { program, actionMock };40 }4142 test('when default subcommand and no command then call default', () => {43 const { program, actionMock } = makeProgram();44 program.parse('node test.js'.split(' '));45 expect(actionMock).toHaveBeenCalled();46 });47

Add opts to addCommand, and rename noHelp to hidden (#1232)John Geebefore adoptionb5d95ee

line 48why, one step back
48 test('when default subcommand and unrecognised argument then call default', () => {

Parse rework for nested commands (#1149)John Geebefore adoption1345f98

lines 49–53why, one step back
49 const { program, actionMock } = makeProgram();
50 program.parse('node test.js an-argument'.split(' '));51 expect(actionMock).toHaveBeenCalled();52 });53

Add opts to addCommand, and rename noHelp to hidden (#1232)John Geebefore adoptionb5d95ee

lines 54–65why, one step back
54 test('when default subcommand and unrecognised option then call default', () => {
55 const { program, actionMock } = makeProgram();56 program.parse('node test.js --an-option'.split(' '));57 expect(actionMock).toHaveBeenCalled();58 });59});6061describe('default added command', () => {62 function makeProgram() {63 const actionMock = jest.fn();64 const defaultCmd = new commander.Command('default')65 .allowUnknownOption()

Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71

line 66why, one step back
66 .allowExcessArguments()

Add opts to addCommand, and rename noHelp to hidden (#1232)John Geebefore adoptionb5d95ee

lines 67–89why, one step back
67 .action(actionMock);
6869 const program = new commander.Command();70 program71 .command('other');72 program73 .addCommand(defaultCmd, { isDefault: true });74 return { program, actionMock };75 }7677 test('when default subcommand and no command then call default', () => {78 const { program, actionMock } = makeProgram();79 program.parse('node test.js'.split(' '));80 expect(actionMock).toHaveBeenCalled();81 });8283 test('when default subcommand and unrecognised argument then call default', () => {84 const { program, actionMock } = makeProgram();85 program.parse('node test.js an-argument'.split(' '));86 expect(actionMock).toHaveBeenCalled();87 });8889 test('when default subcommand and unrecognised option then call default', () => {

Parse rework for nested commands (#1149)John Geebefore adoption1345f98

lines 90–94why, one step back
90 const { program, actionMock } = makeProgram();
91 program.parse('node test.js --an-option'.split(' '));92 expect(actionMock).toHaveBeenCalled();93 });94});