Skip to content

Commit

Permalink
Add test for process.exit finishing bunch of if-then-else cases (#1487)
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowspawn committed Mar 20, 2021
1 parent 82bf30b commit 0fa4b8d
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion tests/command.executableSubcommand.mock.test.js
Expand Up @@ -41,7 +41,7 @@ test('when subcommand executable not executable (EACCES) then throw custom messa
spawnSpy.mockRestore();
});

test('when subcommand executable fails with other error then return in custom wrapper', () => {
test('when subcommand executable fails with other error and exitOverride then return in custom wrapper', () => {
// The existing behaviour is to just silently fail for unexpected errors, as it is happening
// asynchronously in spawned process and client can not catch errors.
const mockProcess = new EventEmitter();
Expand All @@ -62,3 +62,18 @@ test('when subcommand executable fails with other error then return in custom wr
expect(caughtErr.nestedError.code).toEqual('OTHER');
spawnSpy.mockRestore();
});

test('when subcommand executable fails with other error then exit', () => {
// The existing behaviour is to just silently fail for unexpected errors, as it is happening
// asynchronously in spawned process and client can not catch errors.
const mockProcess = new EventEmitter();
const spawnSpy = jest.spyOn(childProcess, 'spawn').mockImplementation(() => { return mockProcess; });
const exitSpy = jest.spyOn(process, 'exit').mockImplementation(() => { });
const program = new commander.Command();
program.command('executable', 'executable description');
program.parse(['executable'], { from: 'user' });
mockProcess.emit('error', makeSystemError('OTHER'));
expect(exitSpy).toHaveBeenCalledWith(1);
exitSpy.mockRestore();
spawnSpy.mockRestore();
});

0 comments on commit 0fa4b8d

Please sign in to comment.