Skip to content
Myr

command.error.test.js

This file

Path

tests/command.error.test.js

59 lines · 1.7 KiB · JavaScript

Last changed by

Switching to esm-only (#2464)John Geebefore adoptionf4bd470

History of this file

Take 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 back
1import * as commander from '../index.js';
2import { test, describe } from 'node:test';3import assert from 'node:assert/strict';

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 4why, one step back
4

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 5–8why, one step back
5describe('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', () => {});

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 9why, one step back
9

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 10–12why, one step back
10 const program = new commander.Command();
11 const message = 'Goodbye';12 program.error(message);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 13why, one step back
13

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 14–15why, one step back
14 const callArgs = stderrSpy.mock.calls[0].arguments;
15 assert.equal(callArgs[0], `${message}\n`);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 16–17why, one step back
16 });
17

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 18–19why, one step back
18 test('when error called with no exitCode then process.exit(1)', (t) => {
19 const exitSpy = t.mock.method(process, 'exit', () => {});

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 20why, one step back
20

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 21–24why, one step back
21 const program = new commander.Command();
22 program.configureOutput({23 writeErr: () => {},24 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 25why, one step back
25

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

line 26why, one step back
26 program.error('Goodbye');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 27why, one step back
27

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 28–29why, one step back
28 const callArgs = exitSpy.mock.calls[0].arguments;
29 assert.equal(callArgs[0], 1);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 30–31why, one step back
30 });
31

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 32–33why, one step back
32 test('when error called with exitCode 2 then process.exit(2)', (t) => {
33 const exitSpy = t.mock.method(process, 'exit', () => {});

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 34why, one step back
34

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 35–42why, one step back
35 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 back
43 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 44why, one step back
44

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 45–58why, one step back
45 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 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 59why, one step back
59});