options.getset.test.js
This file
Path
tests/options.getset.test.js
72 lines · 3.1 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
line 4why, one step back4Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 5–17why, one step back5describe('Command.getOptionValue() and .setOptionValue()', () => {6 describe('storeOptionsAsProperties', () => {7 const storeOptionsAsPropertiesList = [true, false];8 for (const storeOptionsAsProperties of storeOptionsAsPropertiesList) {9 test(`when storeOptionsAsProperties is ${storeOptionsAsProperties} and option specified on CLI then value returned by getOptionValue`, () => {10 const program = new commander.Command();11 program12 .storeOptionsAsProperties(storeOptionsAsProperties)13 .option('--cheese [type]', 'cheese type');14 const cheeseType = 'blue';15 program.parse(['node', 'test', '--cheese', cheeseType]);16 assert.equal(program.getOptionValue('cheese'), cheeseType);17 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 18why, one step back18Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 19–30why, one step back19 test(`when storeOptionsAsProperties is ${storeOptionsAsProperties} and setOptionValue then value returned by opts`, () => {20 const program = new commander.Command();21 const cheeseType = 'blue';22 // Note: opts() only returns declared options when options stored as properties23 program24 .storeOptionsAsProperties(storeOptionsAsProperties)25 .option('--cheese [type]', 'cheese type')26 .setOptionValue('cheese', cheeseType);27 assert.equal(program.opts().cheese, cheeseType);28 });29 }30 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 31why, one step back31Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 32–39why, one step back32 test('when setOptionValueWithSource then value returned by opts', () => {33 const program = new commander.Command();34 const cheeseValue = 'blue';35 program36 .option('--cheese [type]', 'cheese type')37 .setOptionValueWithSource('cheese', cheeseValue, 'cli');38 assert.equal(program.opts().cheese, cheeseValue);39 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 40why, one step back40Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 41–47why, one step back41 test('when setOptionValueWithSource then source returned by getOptionValueSource', () => {42 const program = new commander.Command();43 program44 .option('--cheese [type]', 'cheese type')45 .setOptionValueWithSource('cheese', 'blue', 'config');46 assert.equal(program.getOptionValueSource('cheese'), 'config');47 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 48why, one step back48Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 49–56why, one step back49 test('when option value parsed from env then option source is env', () => {50 const program = new commander.Command();51 process.env.BAR = 'env';52 program.addOption(new commander.Option('-f, --foo').env('BAR'));53 program.parse([], { from: 'user' });54 assert.equal(program.getOptionValueSource('foo'), 'env');55 delete process.env.BAR;56 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 57why, one step back57Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 58–63why, one step back58 test('when option value parsed from cli then option source is cli', () => {59 const program = new commander.Command();60 program.addOption(new commander.Option('-f, --foo').env('BAR'));61 program.parse(['--foo'], { from: 'user' });62 assert.equal(program.getOptionValueSource('foo'), 'cli');63 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 64why, one step back64Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 65–71why, one step back65 test('when setOptionValue then clears previous source', () => {66 const program = new commander.Command();67 program.option('--foo', 'description', 'default value');68 assert.equal(program.getOptionValueSource('foo'), 'default');69 program.setOptionValue('foo', 'bar');70 assert.equal(program.getOptionValueSource('foo'), undefined);71 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 72why, one step back72});