Skip to content

Commit 0fa4b8d

Browse files
authored
Add test for process.exit finishing bunch of if-then-else cases (#1487)
1 parent 82bf30b commit 0fa4b8d

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

tests/command.executableSubcommand.mock.test.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ test('when subcommand executable not executable (EACCES) then throw custom messa
4141
spawnSpy.mockRestore();
4242
});
4343

44-
test('when subcommand executable fails with other error then return in custom wrapper', () => {
44+
test('when subcommand executable fails with other error and exitOverride then return in custom wrapper', () => {
4545
// The existing behaviour is to just silently fail for unexpected errors, as it is happening
4646
// asynchronously in spawned process and client can not catch errors.
4747
const mockProcess = new EventEmitter();
@@ -62,3 +62,18 @@ test('when subcommand executable fails with other error then return in custom wr
6262
expect(caughtErr.nestedError.code).toEqual('OTHER');
6363
spawnSpy.mockRestore();
6464
});
65+
66+
test('when subcommand executable fails with other error then exit', () => {
67+
// The existing behaviour is to just silently fail for unexpected errors, as it is happening
68+
// asynchronously in spawned process and client can not catch errors.
69+
const mockProcess = new EventEmitter();
70+
const spawnSpy = jest.spyOn(childProcess, 'spawn').mockImplementation(() => { return mockProcess; });
71+
const exitSpy = jest.spyOn(process, 'exit').mockImplementation(() => { });
72+
const program = new commander.Command();
73+
program.command('executable', 'executable description');
74+
program.parse(['executable'], { from: 'user' });
75+
mockProcess.emit('error', makeSystemError('OTHER'));
76+
expect(exitSpy).toHaveBeenCalledWith(1);
77+
exitSpy.mockRestore();
78+
spawnSpy.mockRestore();
79+
});

0 commit comments

Comments
 (0)