help.visibleArguments.test.js
This file
Path
tests/help.visibleArguments.test.js
79 lines · 2.8 KiB · JavaScript
Last changed by
Switching to esm-only (#2464)John Geebefore adoptionf4bd470
History of this fileTake it
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980import { test, describe } from 'node:test';import assert from 'node:assert/strict';import * as commander from '../index.js';
// 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.visibleArguments()', () => { test('when no arguments then empty array', () => { const program = new commander.Command(); const helper = new commander.Help(); assert.deepEqual(helper.visibleArguments(program), []); });
test('when argument but no argument description then empty array', () => { const program = new commander.Command(); program.argument('<file>'); const helper = new commander.Help(); assert.deepEqual(helper.visibleArguments(program), []); });
test('when argument and argument description then returned', () => { const program = new commander.Command(); program.argument('<file>', 'file description'); const helper = new commander.Help(); const visibleArguments = helper.visibleArguments(program); assert.equal(visibleArguments.length, 1); assert.deepEqual( visibleArguments[0], new commander.Argument('<file>', 'file description'), ); });
test('when argument and legacy argument description then returned', () => { const program = new commander.Command(); program.argument('<file>'); program.description('', { file: 'file description', }); const helper = new commander.Help(); const visibleArguments = helper.visibleArguments(program); assert.equal(visibleArguments.length, 1); assert.deepEqual( visibleArguments[0], new commander.Argument('<file>', 'file description'), ); });
test('when arguments and some described then all returned', () => { const program = new commander.Command(); program.argument('<file1>', 'file1 description'); program.argument('<file2>'); const helper = new commander.Help(); const visibleArguments = helper.visibleArguments(program); assert.equal(visibleArguments.length, 2); assert.deepEqual( visibleArguments[0], new commander.Argument('<file1>', 'file1 description'), ); assert.deepEqual(visibleArguments[1], new commander.Argument('<file2>')); });
test('when arguments and some legacy described then all returned', () => { const program = new commander.Command(); program.argument('<file1>'); program.argument('<file2>'); program.description('', { file1: 'file1 description', }); const helper = new commander.Help(); const visibleArguments = helper.visibleArguments(program); assert.equal(visibleArguments.length, 2); assert.deepEqual( visibleArguments[0], new commander.Argument('<file1>', 'file1 description'), ); assert.deepEqual(visibleArguments[1], new commander.Argument('<file2>')); });});