1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-27 12:36:14 +01:00
bitwarden-browser/spec/node/cli/consoleLog.service.spec.ts
Matt Gibson 2c414ce27a
Use log service for console messages (#221)
* Use logService for console messages

* Implement a base ConsoleLog service

Use this class as a default for other services that would like to output
to console. This service is overriden in CLI and Desktop to use CLI's
consoleLogService and electronLogService, respectively.

* Use browser-process-hrtime for timing

* test LogService implementations

* Ignore default import of hrtime

* Clean up imports. Require ConsoleLog injection

Co-authored-by: Matt Gibson <mdgibson@Matts-MBP.lan>
2020-12-11 10:44:57 -06:00

42 lines
1.3 KiB
TypeScript

import { ConsoleLogService } from '../../../src/cli/services/consoleLog.service';
import { interceptConsole, restoreConsole } from '../../common/services/consoleLog.service.spec';
const originalConsole = console;
let caughtMessage: any = {};
describe('CLI Console log service', () => {
let logService: ConsoleLogService;
beforeEach(() => {
caughtMessage = {};
interceptConsole(caughtMessage);
logService = new ConsoleLogService(true);
});
afterAll(() => {
restoreConsole();
});
it('should redirect all console to error if BW_RESPONSE env is true', () => {
process.env.BW_RESPONSE = 'true';
logService.debug('this is a debug message');
expect(caughtMessage).toEqual({ error: jasmine.arrayWithExactContents(['this is a debug message']) });
});
it('should not redirect console to error if BW_RESPONSE != true', () => {
process.env.BW_RESPONSE = 'false';
logService.debug('debug');
logService.info('info');
logService.warning('warning');
logService.error('error');
expect(caughtMessage).toEqual({
log: jasmine.arrayWithExactContents(['info']),
warn: jasmine.arrayWithExactContents(['warning']),
error: jasmine.arrayWithExactContents(['error']),
});
});
});