diff --git a/lib/__tests__/cli.test.js b/lib/__tests__/cli.test.js index 7040994745..f41b88f9e2 100644 --- a/lib/__tests__/cli.test.js +++ b/lib/__tests__/cli.test.js @@ -159,7 +159,9 @@ describe('CLI', () => { beforeAll(() => { jest.spyOn(process, 'exit').mockImplementation(() => {}); jest.spyOn(process.stdout, 'write').mockImplementation(() => {}); + jest.spyOn(process.stderr, 'write').mockImplementation(() => {}); jest.spyOn(console, 'log').mockImplementation(() => {}); + jest.spyOn(console, 'error').mockImplementation(() => {}); }); afterAll(() => { @@ -259,9 +261,11 @@ describe('CLI', () => { replaceBackslashes(path.join(fixturesPath, 'empty-block-with-disables.css')), ]); - expect(process.exit).not.toHaveBeenCalledWith(0); + expect(process.exitCode).toEqual(1); - expect(console.log).toHaveBeenCalledTimes(1); - expect(console.log).toHaveBeenCalledWith(expect.stringContaining('Cannot find module')); + expect(process.stderr.write).toHaveBeenCalledTimes(1); + expect(process.stderr.write).toHaveBeenCalledWith( + expect.stringContaining('Cannot find module'), + ); }); }); diff --git a/lib/cli.js b/lib/cli.js index 0546555966..cf8179e083 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -534,10 +534,10 @@ module.exports = (argv) => { * @returns {void} */ function handleError(err) { - console.log(err.stack); // eslint-disable-line no-console + process.stderr.write(err.stack); const exitCode = typeof err.code === 'number' ? err.code : 1; - process.exit(exitCode); // eslint-disable-line no-process-exit + process.exitCode = exitCode; } /**