help.longestOptionTermLength.test.js
This file
Path
tests/help.longestOptionTermLength.test.js
38 lines · 1.3 KiB · JavaScript
Last changed by
Switching to esm-only (#2464)John Geebefore adoptionf4bd470
History of this fileTake it
123456789101112131415161718192021222324252627282930313233343536373839import * as commander from '../index.js';import { test, describe } from 'node:test';import assert from 'node:assert/strict';
// These are tests of the Help class, not of the Command help.// There is some overlap with the higher level Command tests (which predate Help).
describe('Help.longestOptionTermLength()', () => { test('when no option then returns zero', () => { const program = new commander.Command(); program.helpOption(false); const helper = new commander.Help(); assert.equal(helper.longestOptionTermLength(program, helper), 0); });
test('when just implicit help option returns length of help flags', () => { const program = new commander.Command(); const helper = new commander.Help(); assert.equal( helper.longestOptionTermLength(program, helper), '-h, --help'.length, ); });
test('when multiple option then returns longest length', () => { const longestOptionFlags = '-l, --longest <value>'; const program = new commander.Command(); program .option('--before', 'optional description of flags') .option(longestOptionFlags) .option('--after'); const helper = new commander.Help(); assert.equal( helper.longestOptionTermLength(program, helper), longestOptionFlags.length, ); });});