options.opts.test.js
This file
Path
tests/options.opts.test.js
74 lines · 3.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–7why, one step back45// Test the `.opts()` way of accessing option values.6// Basic coverage of the main option types (leaving out negatable flags and options with optional values).7Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 8–15why, one step back8describe('Command.opts()', () => {9 test('when .version used with storeOptionsAsProperties() then version in opts', () => {10 const program = new commander.Command();11 const version = '0.0.1';12 program.storeOptionsAsProperties().version(version);13 program.parse(['node', 'test']);14 assert.deepEqual(program.opts(), { version });15 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 16why, one step back16Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 17–24why, one step back17 test('when .version used with storeOptionsAsProperties(false) then version not in opts', () => {18 // New behaviour, stop storing version as an option value.19 const program = new commander.Command();20 const version = '0.0.1';21 program.storeOptionsAsProperties(false).version(version);22 program.parse(['node', 'test']);23 assert.deepEqual(program.opts(), {});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–36why, one step back26 describe('storeOptionsAsProperties', () => {27 const storeOptionsAsPropertiesList = [true, false];28 for (const storeOptionsAsProperties of storeOptionsAsPropertiesList) {29 test(`when storeOptionsAsProperties is ${storeOptionsAsProperties} and boolean flag not specified then not in opts`, () => {30 const program = new commander.Command();31 program.storeOptionsAsProperties(storeOptionsAsProperties);32 program.option('--pepper', 'add pepper');33 program.parse(['node', 'test']);34 const expected = storeOptionsAsProperties ? { pepper: undefined } : {};35 assert.deepEqual(program.opts(), expected);36 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 37why, one step back37Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 38–44why, one step back38 test(`when storeOptionsAsProperties is ${storeOptionsAsProperties} and boolean flag specified then value true`, () => {39 const program = new commander.Command();40 program.storeOptionsAsProperties(storeOptionsAsProperties);41 program.option('--pepper', 'add pepper');42 program.parse(['node', 'test', '--pepper']);43 assert.deepEqual(program.opts(), { pepper: true });44 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 45why, one step back45Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 46–53why, one step back46 test(`when storeOptionsAsProperties is ${storeOptionsAsProperties} and option with required value not specified then not in opts`, () => {47 const program = new commander.Command();48 program.storeOptionsAsProperties(storeOptionsAsProperties);49 program.option('--pepper <flavour>', 'add pepper');50 program.parse(['node', 'test']);51 const expected = storeOptionsAsProperties ? { pepper: undefined } : {};52 assert.deepEqual(program.opts(), expected);53 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 54why, one step back54Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 55–62why, one step back55 test(`when storeOptionsAsProperties is ${storeOptionsAsProperties} and option with required value specified then value as specified`, () => {56 const pepperValue = 'red';57 const program = new commander.Command();58 program.storeOptionsAsProperties(storeOptionsAsProperties);59 program.option('--pepper <flavour>', 'add pepper');60 program.parse(['node', 'test', '--pepper', pepperValue]);61 assert.deepEqual(program.opts(), { pepper: pepperValue });62 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 63why, one step back63Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 64–73why, one step back64 test(`when storeOptionsAsProperties is ${storeOptionsAsProperties} and option with default value not specified then default value in opts`, () => {65 const pepperDefault = 'red';66 const program = new commander.Command();67 program.storeOptionsAsProperties(storeOptionsAsProperties);68 program.option('--pepper <flavour>', 'add pepper', pepperDefault);69 program.parse(['node', 'test']);70 assert.deepEqual(program.opts(), { pepper: pepperDefault });71 });72 }73 });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 74why, one step back74});