Skip to content
Myr

options.preset.test.js

This file

Path

tests/options.preset.test.js

63 lines · 2.5 KiB · JavaScript

Last changed by

Switching to esm-only (#2464)John Geebefore adoptionf4bd470

History of this file

Take 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 back
1import { 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

line 4why, one step back
4

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 5–11why, one step back
5describe('Option.preset()', () => {
6 test('when boolean option with string preset used then value is preset', () => {7 const program = new Command();8 program.addOption(new Option('-d, --debug').preset('foo'));9 program.parse(['-d'], { from: 'user' });10 assert.equal(program.opts().debug, 'foo');11 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 12why, one step back
12

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 13–18why, one step back
13 test('when boolean option with number preset used then value is preset', () => {
14 const program = new Command();15 program.addOption(new Option('-d, --debug').preset(80));16 program.parse(['-d'], { from: 'user' });17 assert.equal(program.opts().debug, 80);18 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 19why, one step back
19

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 20–25why, one step back
20 test('when optional with string preset used then value is preset', () => {
21 const program = new Command();22 program.addOption(new Option('-p, --port [port]').preset('foo'));23 program.parse(['-p'], { from: 'user' });24 assert.equal(program.opts().port, 'foo');25 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 26why, one step back
26

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 27–32why, one step back
27 test('when optional with number preset used then value is preset', () => {
28 const program = new Command();29 program.addOption(new Option('-p, --port [port]').preset(80));30 program.parse(['-p'], { from: 'user' });31 assert.equal(program.opts().port, 80);32 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 33why, one step back
33

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 34–39why, one step back
34 test('when optional with string preset used with option-argument then value is as specified', () => {
35 const program = new Command();36 program.addOption(new Option('-p, --port [port]').preset('foo'));37 program.parse(['-p', '1234'], { from: 'user' });38 assert.equal(program.opts().port, '1234');39 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 40why, one step back
40

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 41–48why, one step back
41 test('when optional with preset and coerce used then preset is coerced', () => {
42 const program = new Command();43 program.addOption(44 new Option('-p, --port [port]').preset('4').argParser(parseFloat),45 );46 program.parse(['-p'], { from: 'user' });47 assert.equal(program.opts().port, 4);48 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 49why, one step back
49

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 50–55why, one step back
50 test('when optional with preset and variadic used then preset is concatenated', () => {
51 const program = new Command();52 program.addOption(new Option('-n, --name [name...]').preset('two'));53 program.parse(['-n', 'one', '-n', '-n', 'three'], { from: 'user' });54 assert.deepEqual(program.opts().name, ['one', 'two', 'three']);55 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 56why, one step back
56

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 57–62why, one step back
57 test('when negated with string preset used then value is preset', () => {
58 const program = new Command();59 program.addOption(new Option('--no-colour').preset('foo'));60 program.parse(['--no-colour'], { from: 'user' });61 assert.equal(program.opts().colour, 'foo');62 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 63why, one step back
63});