-
-
Notifications
You must be signed in to change notification settings - Fork 616
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use logger for error with proper exit code (#2076)
- Loading branch information
Showing
3 changed files
with
36 additions
and
1 deletion.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
packages/webpack-cli/lib/utils/__tests__/resolve-command.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
jest.setMock('../prompt-installation', jest.fn()); | ||
|
||
const resolveCommand = require('../resolve-command'); | ||
const promptInstallation = require('../prompt-installation'); | ||
|
||
describe('resolve-command util', () => { | ||
const processExitSpy = jest.spyOn(process, 'exit').mockImplementation(() => {}); | ||
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); | ||
|
||
beforeEach(() => { | ||
processExitSpy.mockClear(); | ||
consoleErrorSpy.mockClear(); | ||
}); | ||
|
||
it('should not throw error', async () => { | ||
promptInstallation.mockImplementation(() => {}); | ||
|
||
await expect(resolveCommand('info')).resolves.not.toThrow(); | ||
expect(processExitSpy.mock.calls.length).toBe(0); | ||
expect(consoleErrorSpy.mock.calls.length).toBe(0); | ||
}); | ||
|
||
it('should throw error and exit with invalid command', async () => { | ||
promptInstallation.mockImplementation(() => { | ||
throw new Error(); | ||
}); | ||
|
||
await resolveCommand('invalid'); | ||
expect(processExitSpy).toBeCalledWith(2); | ||
expect(consoleErrorSpy.mock.calls.length).toBe(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters