command.name.test.js
This file
Path
tests/command.name.test.js
52 lines · 1.8 KiB · JavaScript
Last changed by
Merge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c
History of this fileTake it
The walk stopped after 200 commits: lines older than f47bdf5 point at it.
Merge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c
line 1why, one step back1const path = require('path');Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 2–3why, one step back2const commander = require('../');3Merge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c
lines 4–8why, one step back4test('when construct with name then name is set', () => {5 const program = new commander.Command('foo');6 expect(program.name()).toBe('foo');7});8Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 9–15why, one step back9test('when set program name and parse then name is as assigned', () => {10 const program = new commander.Command();11 program.name('custom');12 program.parse(['node', 'test']);13 expect(program.name()).toBe('custom');14});15Merge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c
line 16why, one step back16test('when program name not set and parse with script argument then plain name is found from script name', () => {Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
line 17why, one step back17 const program = new commander.Command();Merge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c
lines 18–19why, one step back18 program.parse(['node', path.resolve(process.cwd(), 'script.js')], { from: 'node' });19 expect(program.name()).toBe('script');Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 20–21why, one step back20});21Merge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c
lines 22–27why, one step back22test('when command name not set and no script argument in parse then name is program', () => {23 const program = new commander.Command();24 program.parse([], { from: 'user' });25 expect(program.name()).toBe('program');26});27Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 28–39why, one step back28test('when add command then command is named', () => {29 const program = new commander.Command();30 const subcommand = program31 .command('mycommand <file>');32 expect(subcommand.name()).toBe('mycommand');33});3435test('when set program name then name appears in help', () => {36 const program = new commander.Command();37 program.name('custom-name');38 const helpInformation = program.helpInformation();39 expect(helpInformation).toMatch(/^Usage: custom-name/);Merge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c
lines 40–51why, one step back40});4142test('when pass path to nameFromFilename then name is plain name', () => {43 const program = new commander.Command();44 program.nameFromFilename(path.resolve(process.cwd(), 'foo.js'));45 expect(program.name()).toBe('foo');46});4748test('when pass __filename to nameFromFilename then name is plain name of this file', () => {49 const program = new commander.Command();50 program.nameFromFilename(__filename);51 expect(program.name()).toBe('command.name.test');Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
line 52why, one step back52});