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

The walk stopped after 200 commits: lines older than 08ec04e point at it.

Type commands property (#1184)Dmitrii Maganovbefore adoption08ec04e

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

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

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

Type commands property (#1184)Dmitrii Maganovbefore adoption08ec04e

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

Type commands property (#1184)Dmitrii Maganovbefore adoption08ec04e

lines 14–17why, one step back
14 expect(stdout).toBe('default\n');
15 });1617 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']);

Type commands property (#1184)Dmitrii Maganovbefore adoption08ec04e

lines 19–22why, one step back
19 expect(stdout).toBe("default\n[ 'an-argument' ]\n");
20 });2122 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']);

Type commands property (#1184)Dmitrii Maganovbefore adoption08ec04e

lines 24–36why, one step back
24 expect(stdout).toBe("default\n[ '--an-option' ]\n");
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()

Type commands property (#1184)Dmitrii Maganovbefore adoption08ec04e

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', () => {

Type commands property (#1184)Dmitrii Maganovbefore adoption08ec04e

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', () => {

Type commands property (#1184)Dmitrii Maganovbefore adoption08ec04e

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});