Skip to content
Myr

command.default.test.js

This file

Path

tests/command.default.test.js

91 lines · 3.2 KiB · JavaScript

Last changed by

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

History of this file

Take it

The walk stopped after 200 commits: lines older than 2911e0e point at it.

docs: update SECURITY.mdabetomobefore adoption2911e0e

lines 1–11why, one step back
1const childProcess = require('child_process');
2const commander = require('../');3const path = require('path');4const util = require('util');56const execFileAsync = util.promisify(childProcess.execFile);78describe('default executable command', () => {9 // Calling node explicitly so pm works without file suffix cross-platform.10 const pm = path.join(__dirname, './fixtures/pm');11

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

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

docs: update SECURITY.mdabetomobefore adoption2911e0e

lines 13–16why, one step back
13 const { stdout } = await execFileAsync('node', [pm]);
14 expect(stdout).toBe('default\n');15 });16

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

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

docs: update SECURITY.mdabetomobefore adoption2911e0e

lines 18–21why, one step back
18 const { stdout } = await execFileAsync('node', [pm, 'an-argument']);
19 expect(stdout).toBe("default\n[ 'an-argument' ]\n");20 });21

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

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

docs: update SECURITY.mdabetomobefore adoption2911e0e

lines 23–31why, one step back
23 const { stdout } = await execFileAsync('node', [pm, '--an-option']);
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();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

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

docs: update SECURITY.mdabetomobefore adoption2911e0e

lines 33–68why, one step back
33 program
34 .command('default', { isDefault: true })35 .allowUnknownOption()36 .allowExcessArguments()37 .action(actionMock);38 return { program, actionMock };39 }4041 test('when default subcommand and no command then call default', () => {42 const { program, actionMock } = makeProgram();43 program.parse('node test.js'.split(' '));44 expect(actionMock).toHaveBeenCalled();45 });4647 test('when default subcommand and unrecognised argument then call default', () => {48 const { program, actionMock } = makeProgram();49 program.parse('node test.js an-argument'.split(' '));50 expect(actionMock).toHaveBeenCalled();51 });5253 test('when default subcommand and unrecognised option then call default', () => {54 const { program, actionMock } = makeProgram();55 program.parse('node test.js --an-option'.split(' '));56 expect(actionMock).toHaveBeenCalled();57 });58});5960describe('default added command', () => {61 function makeProgram() {62 const actionMock = jest.fn();63 const defaultCmd = new commander.Command('default')64 .allowUnknownOption()65 .allowExcessArguments()66 .action(actionMock);6768 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 69–70why, one step back
69 program.command('other');
70 program.addCommand(defaultCmd, { isDefault: true });

docs: update SECURITY.mdabetomobefore adoption2911e0e

lines 71–91why, one step back
71 return { program, actionMock };
72 }7374 test('when default subcommand and no command then call default', () => {75 const { program, actionMock } = makeProgram();76 program.parse('node test.js'.split(' '));77 expect(actionMock).toHaveBeenCalled();78 });7980 test('when default subcommand and unrecognised argument then call default', () => {81 const { program, actionMock } = makeProgram();82 program.parse('node test.js an-argument'.split(' '));83 expect(actionMock).toHaveBeenCalled();84 });8586 test('when default subcommand and unrecognised option then call default', () => {87 const { program, actionMock } = makeProgram();88 program.parse('node test.js --an-option'.split(' '));89 expect(actionMock).toHaveBeenCalled();90 });91});