command.createOption.test.js
This file
Path
tests/command.createOption.test.js
46 lines · 1.5 KiB · JavaScript
Last changed by
Switching to esm-only (#2464)John Geebefore adoptionf4bd470
History of this fileTake it
The walk stopped after 200 commits: lines older than 471ec40 point at it.
Switching to esm-only (#2464)John Geebefore adoptionf4bd470
lines 1–3why, one step back1import * as commander from '../index.js';2import { test, describe } from 'node:test';3import assert from 'node:assert/strict';Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 4–17why, one step back45class MyOption extends commander.Option {6 constructor(flags, description) {7 super(flags, description);8 this.myProperty = 'MyOption';9 }10}1112class MyCommand extends commander.Command {13 createOption(flags, description) {14 return new MyOption(flags, description);15 }16}17Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 18–24why, one step back18describe('Command.createOption() override in subclass', () => {19 test('when override createOption then used for option()', () => {20 const program = new MyCommand();21 program.option('-a, --alpha');22 assert.equal(program.options.length, 1);23 assert.equal(program.options[0].myProperty, 'MyOption');24 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 25why, one step back25Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 26–31why, one step back26 test('when override createOption then used for requiredOption()', () => {27 const program = new MyCommand();28 program.requiredOption('-a, --alpha');29 assert.equal(program.options.length, 1);30 assert.equal(program.options[0].myProperty, 'MyOption');31 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 32why, one step back32Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 33–38why, one step back33 test('when override createOption then used for version()', () => {34 const program = new MyCommand();35 program.version('1.2.3');36 assert.equal(program.options.length, 1);37 assert.equal(program.options[0].myProperty, 'MyOption');38 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 39why, one step back39Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 40–45why, one step back40 test('when override createOption then used for help option in visibleOptions', () => {41 const program = new MyCommand();42 const visibleOptions = program.createHelp().visibleOptions(program);43 assert.equal(visibleOptions.length, 1);44 assert.equal(visibleOptions[0].myProperty, 'MyOption');45 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 46why, one step back46});