Skip to content
Myr

option.bad-flags.test.js

This file

Path

tests/option.bad-flags.test.js

51 lines · 1.7 KiB · JavaScript

Last changed by

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

History of this file

Take it

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

lines 1–3why, one step back
1import { Option } from '../index.js';
2import { test, describe } from 'node:test';3import assert from 'node:assert/strict';

Throw for unsupported option flag setup (#2270)John Geebefore adoption966720a

lines 4–5why, one step back
4
5// Check that unsupported flags throw.

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

lines 6–28why, one step back
6describe('when construct Option with unsupported flags then throw', () => {
7 const flagsList = [8 { flags: '-a, -b' }, // too many short flags9 { flags: '-a, -b <value>' },10 { flags: '-a, -b, --long' },11 { flags: '--one, --two, --three' }, // too many long flags12 { flags: '-ws' }, // short flag with more than one character13 { flags: '---triple' }, // double dash not followed by a non-dash14 { flags: 'sdkjhskjh' }, // oops, no flags15 { flags: '-a,-b' }, // try all the separators16 { flags: '-a|-b' },17 { flags: '-a -b' },18 ];19 for (const { flags } of flagsList) {20 test(`when construct Option with flags ${flags} then throw`, () => {21 assert.throws(22 () => {23 new Option(flags);24 },25 { message: /^option creation failed/ },26 );27 });28 }

Throw for unsupported option flag setup (#2270)John Geebefore adoption966720a

lines 29–31why, one step back
29});
3031// Check that supported flags do not throw.

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

lines 32–50why, one step back
32describe('when construct Option with supported flags then do not throw', () => {
33 const flagsList = [34 { flags: '-s' }, // single short35 { flags: '--long' }, // single long36 { flags: '-b, --both' }, // short and long37 { flags: '--both, -b' }, // long and short38 { flags: '--ws, --workspace' }, // two long (morally shortish and long)39 { flags: '-b,--both <comma>' },40 { flags: '-b|--both <bar>' },41 { flags: '-b --both [space]' },42 { flags: '-v, --variadic <files...>' },43 ];44 for (const { flags } of flagsList) {45 test(`when construct Option with flags ${flags} then do not throw`, () => {46 assert.doesNotThrow(() => {47 new Option(flags);48 });49 });50 }

Throw for unsupported option flag setup (#2270)John Geebefore adoption966720a

line 51why, one step back
51});