command.showSuggestionAfterError.test.js
This file
Path
tests/command.showSuggestionAfterError.test.js
54 lines · 1.7 KiB · JavaScript
Last changed by
Switching to esm-only (#2464)John Geebefore adoptionf4bd470
History of this fileTake 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 back1import { Command } from '../index.js';2import { test, describe } from 'node:test';3import assert from 'node:assert/strict';Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 4–6why, one step back45function getSuggestion(program, arg) {6 let message = '';Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 7–11why, one step back7 program.exitOverride().configureOutput({8 writeErr: (str) => {9 message = str;10 },11 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 12–14why, one step back1213 try {14 program.parse([arg], { from: 'user' });Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 15–17why, one step back15 } catch (err) {16 /* empty */17 }Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 18–21why, one step back1819 const match = message.match(/Did you mean (one of )?(.*)\?/);20 return match ? match[2] : null;21}Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 22–29why, one step back22describe('Command.showSuggestionAfterError()', () => {23 test('when unknown command and showSuggestionAfterError() then show suggestion', () => {24 const program = new Command();25 program.showSuggestionAfterError();26 program.command('example');27 const suggestion = getSuggestion(program, 'exampel');28 assert.equal(suggestion, 'example');29 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 30why, one step back30Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 31–37why, one step back31 test('when unknown command and showSuggestionAfterError(false) then do not show suggestion', () => {32 const program = new Command();33 program.showSuggestionAfterError(false);34 program.command('example');35 const suggestion = getSuggestion(program, 'exampel');36 assert.equal(suggestion, null);37 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 38why, one step back38Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 39–45why, one step back39 test('when unknown option and showSuggestionAfterError() then show suggestion', () => {40 const program = new Command();41 program.showSuggestionAfterError();42 program.option('--example');43 const suggestion = getSuggestion(program, '--exampel');44 assert.equal(suggestion, '--example');45 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 46why, one step back46Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 47–53why, one step back47 test('when unknown option and showSuggestionAfterError(false) then do not show suggestion', () => {48 const program = new Command();49 program.showSuggestionAfterError(false);50 program.option('--example');51 const suggestion = getSuggestion(program, '--exampel');52 assert.equal(suggestion, null);53 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 54why, one step back54});