help.minWidthToWrap.test.js
This file
Path
tests/help.minWidthToWrap.test.js
49 lines · 1.6 KiB · JavaScript
Last changed by
Switching to esm-only (#2464)John Geebefore adoptionf4bd470
History of this fileTake it
Switching to esm-only (#2464)John Geebefore adoptionf4bd470
lines 1–3why, one step back1import * as commander from '../index.js';2import { test, describe } from 'node:test';3import assert from 'node:assert/strict';Support color ansi code sequences in custom help (#2251)John Geebefore adoption5629947
line 4why, one step back4Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 5why, one step back5describe('Help.minWidthToWrap()', () => {Support color ansi code sequences in custom help (#2251)John Geebefore adoption5629947
lines 6–18why, one step back6 test('when enough width then wrap', () => {7 const program = new commander.Command('program');8 program.description('x '.repeat(110));9 program.configureOutput({10 getOutHelpWidth: () => 100, // lots of room to wrap11 });12 const helpText = program.helpInformation();13 const wrappedescription =14 'x '.repeat(50).trim() +15 '\n' +16 'x '.repeat(50).trim() +17 '\n' +18 'x '.repeat(10).trim();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 19why, one step back19 assert.match(helpText, new RegExp(wrappedescription));Support color ansi code sequences in custom help (#2251)John Geebefore adoption5629947
lines 20–29why, one step back20 });2122 test('when not enough width then no wrap', () => {23 const program = new commander.Command('program');24 program.description('x '.repeat(50));25 program.configureOutput({26 getOutHelpWidth: () => 30, // too narrow to wrap27 });28 const helpText = program.helpInformation();29 const wrappedescription = 'x '.repeat(50);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 30why, one step back30 assert.match(helpText, new RegExp(wrappedescription));Support color ansi code sequences in custom help (#2251)John Geebefore adoption5629947
lines 31–46why, one step back31 });3233 test('when make minWidthToWrap small then wrap', () => {34 const program = new commander.Command('program');35 program.description('x '.repeat(40));36 program.configureOutput({37 getOutHelpWidth: () => 30,38 });39 program.configureHelp({ minWidthToWrap: 20 });40 const helpText = program.helpInformation();41 const wrappedescription =42 'x '.repeat(15).trimEnd() +43 '\n' +44 'x '.repeat(15).trimEnd() +45 '\n' +46 'x '.repeat(10).trimEnd();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 47why, one step back47 assert.match(helpText, new RegExp(wrappedescription));Support color ansi code sequences in custom help (#2251)John Geebefore adoption5629947
lines 48–49why, one step back48 });49});