Skip to content
Myr

command.error.test.js

This file

Path

tests/command.error.test.js

62 lines · 1.6 KiB · JavaScript

Last changed by

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

History of this file

Take it

The walk stopped after 200 commits: lines older than cc2db5b point at it.

Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b

lines 1–3why, one step back
1const commander = require('../');
23test('when error called with message then message displayed on stderr', () => {

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 4–7why, one step back
4 const exitSpy = jest.spyOn(process, 'exit').mockImplementation(() => {});
5 const stderrSpy = jest6 .spyOn(process.stderr, 'write')7 .mockImplementation(() => {});

Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b

lines 8–18why, one step back
8
9 const program = new commander.Command();10 const message = 'Goodbye';11 program.error(message);1213 expect(stderrSpy).toHaveBeenCalledWith(`${message}\n`);14 stderrSpy.mockRestore();15 exitSpy.mockRestore();16});1718test('when error called with no exitCode then process.exit(1)', () => {

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 19why, one step back
19 const exitSpy = jest.spyOn(process, 'exit').mockImplementation(() => {});

Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b

lines 20–22why, one step back
20
21 const program = new commander.Command();22 program.configureOutput({

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 23why, one step back
23 writeErr: () => {},

Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b

lines 24–32why, one step back
24 });
2526 program.error('Goodbye');2728 expect(exitSpy).toHaveBeenCalledWith(1);29 exitSpy.mockRestore();30});3132test('when error called with exitCode 2 then process.exit(2)', () => {

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 33why, one step back
33 const exitSpy = jest.spyOn(process, 'exit').mockImplementation(() => {});

Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b

lines 34–36why, one step back
34
35 const program = new commander.Command();36 program.configureOutput({

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 37why, one step back
37 writeErr: () => {},

Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b

lines 38–48why, one step back
38 });
39 program.error('Goodbye', { exitCode: 2 });4041 expect(exitSpy).toHaveBeenCalledWith(2);42 exitSpy.mockRestore();43});4445test('when error called with code and exitOverride then throws with code', () => {46 const program = new commander.Command();47 let errorThrown;48 program

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 49–52why, one step back
49 .exitOverride((err) => {
50 errorThrown = err;51 throw err;52 })

Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b

line 53why, one step back
53 .configureOutput({

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 54why, one step back
54 writeErr: () => {},

Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b

lines 55–62why, one step back
55 });
5657 const code = 'commander.test';58 expect(() => {59 program.error('Goodbye', { code });60 }).toThrow();61 expect(errorThrown.code).toEqual(code);62});