2022-06-14 17:10:53 +02:00
|
|
|
import { ConsoleLogService } from "@bitwarden/node/cli/services/consoleLog.service";
|
2020-12-11 17:44:57 +01:00
|
|
|
|
2022-09-08 00:02:53 +02:00
|
|
|
import { interceptConsole, restoreConsole } from "../../../common/spec/shared/interceptConsole";
|
|
|
|
|
2020-12-11 17:44:57 +01:00
|
|
|
let caughtMessage: any = {};
|
|
|
|
|
2021-12-16 13:36:21 +01:00
|
|
|
describe("CLI Console log service", () => {
|
|
|
|
let logService: ConsoleLogService;
|
|
|
|
beforeEach(() => {
|
|
|
|
caughtMessage = {};
|
|
|
|
interceptConsole(caughtMessage);
|
|
|
|
logService = new ConsoleLogService(true);
|
|
|
|
});
|
2020-12-11 17:44:57 +01:00
|
|
|
|
2021-12-16 13:36:21 +01:00
|
|
|
afterAll(() => {
|
|
|
|
restoreConsole();
|
|
|
|
});
|
2020-12-11 17:44:57 +01:00
|
|
|
|
2021-12-16 13:36:21 +01:00
|
|
|
it("should redirect all console to error if BW_RESPONSE env is true", () => {
|
|
|
|
process.env.BW_RESPONSE = "true";
|
2020-12-11 17:44:57 +01:00
|
|
|
|
2021-12-16 13:36:21 +01:00
|
|
|
logService.debug("this is a debug message");
|
2022-03-28 16:00:42 +02:00
|
|
|
expect(caughtMessage).toMatchObject({
|
|
|
|
error: { 0: "this is a debug message" },
|
2020-12-11 17:44:57 +01:00
|
|
|
});
|
2021-12-16 13:36:21 +01:00
|
|
|
});
|
2020-12-11 17:44:57 +01:00
|
|
|
|
2021-12-16 13:36:21 +01:00
|
|
|
it("should not redirect console to error if BW_RESPONSE != true", () => {
|
|
|
|
process.env.BW_RESPONSE = "false";
|
2020-12-11 17:44:57 +01:00
|
|
|
|
2021-12-16 13:36:21 +01:00
|
|
|
logService.debug("debug");
|
|
|
|
logService.info("info");
|
|
|
|
logService.warning("warning");
|
|
|
|
logService.error("error");
|
2020-12-11 17:44:57 +01:00
|
|
|
|
2022-03-28 16:00:42 +02:00
|
|
|
expect(caughtMessage).toMatchObject({
|
|
|
|
log: { 0: "info" },
|
|
|
|
warn: { 0: "warning" },
|
|
|
|
error: { 0: "error" },
|
2020-12-11 17:44:57 +01:00
|
|
|
});
|
2021-12-16 13:36:21 +01:00
|
|
|
});
|
2020-12-11 17:44:57 +01:00
|
|
|
});
|