options.twice.test.js
This file
Path
tests/options.twice.test.js
50 lines · 2.0 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 { Command, Option } 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 that when option specified twice, second use wins.6// Seems pretty obvious for boolean options, but there was a bug before Commander v9.7Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 8–14why, one step back8describe('last repeated option wins', () => {9 test('when boolean option used twice then value is true', () => {10 const program = new Command();11 program.option('-d, --debug');12 program.parse(['-d', '-d'], { from: 'user' });13 assert.equal(program.opts().debug, true);14 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 15why, one step back15Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 16–21why, one step back16 test('when boolean option with default used twice then value is true', () => {17 const program = new Command();18 program.option('-d, --debug', 'description', 'foo');19 program.parse(['-d', '-d'], { from: 'user' });20 assert.equal(program.opts().debug, true);21 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 22why, one step back22Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 23–28why, one step back23 test('when boolean option with preset used twice then value is preset', () => {24 const program = new Command();25 program.addOption(new Option('-d, --debug').preset('foo'));26 program.parse(['-d', '-d'], { from: 'user' });27 assert.equal(program.opts().debug, 'foo');28 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 29why, one step back29Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 30–35why, one step back30 test('when option with required argument used twice then value is from second use', () => {31 const program = new Command();32 program.option('-p, --port <port-number>');33 program.parse(['-p', '1', '-p', '2'], { from: 'user' });34 assert.equal(program.opts().port, '2');35 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 36why, one step back36Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 37–42why, one step back37 test('when option with optional argument used second time without value then value is true', () => {38 const program = new Command();39 program.option('--donate [amount]');40 program.parse(['--donate', '123', '--donate'], { from: 'user' });41 assert.equal(program.opts().donate, true);42 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 43why, one step back43Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 44–49why, one step back44 test('when option with optional argument used second time with value then value is from second use', () => {45 const program = new Command();46 program.option('--donate [amount]');47 program.parse(['--donate', '--donate', '123'], { from: 'user' });48 assert.equal(program.opts().donate, '123');49 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 50why, one step back50});