command.error.test.js
This file
Path
tests/command.error.test.js
59 lines · 1.7 KiB · JavaScript
Last changed by
Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
History of this fileTake it
The walk stopped after 200 commits: lines older than b2842dc point at it.
update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 1why, one step back1const commander = require('../');Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 2why, one step back2const { test, describe } = require('node:test');Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 3why, one step back3const assert = require('node:assert/strict');update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 4why, one step back4Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 5–8why, one step back5describe('Command.error()', () => {6 test('when error called with message then message displayed on stderr', (t) => {7 t.mock.method(process, 'exit', () => {});8 const stderrSpy = t.mock.method(process.stderr, 'write', () => {});update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 9why, one step back9Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 10–12why, one step back10 const program = new commander.Command();11 const message = 'Goodbye';12 program.error(message);update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 13why, one step back13Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 14–15why, one step back14 const callArgs = stderrSpy.mock.calls[0].arguments;15 assert.equal(callArgs[0], `${message}\n`);update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 16–17why, one step back16 });17Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 18–19why, one step back18 test('when error called with no exitCode then process.exit(1)', (t) => {19 const exitSpy = t.mock.method(process, 'exit', () => {});update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 20why, one step back20Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 21–24why, one step back21 const program = new commander.Command();22 program.configureOutput({23 writeErr: () => {},24 });update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 25why, one step back25Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 26why, one step back26 program.error('Goodbye');update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 27why, one step back27Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 28–29why, one step back28 const callArgs = exitSpy.mock.calls[0].arguments;29 assert.equal(callArgs[0], 1);update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 30–31why, one step back30 });31Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 32–33why, one step back32 test('when error called with exitCode 2 then process.exit(2)', (t) => {33 const exitSpy = t.mock.method(process, 'exit', () => {});update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 34why, one step back34Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 35–42why, one step back35 const program = new commander.Command();36 program.configureOutput({37 writeErr: () => {},38 });39 program.error('Goodbye', { exitCode: 2 });4041 const callArgs = exitSpy.mock.calls[0].arguments;42 assert.equal(callArgs[0], 2);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 43why, one step back43 });update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 44why, one step back44Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 45–58why, one step back45 test('when error called with code and exitOverride then throws with code', () => {46 const program = new commander.Command();47 program.exitOverride().configureOutput({48 writeErr: () => {},49 });5051 const code = 'commander.mytest';52 assert.throws(53 () => {54 program.error('Goodbye', { code });55 },56 { code },57 );58 });update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 59why, one step back59});