Skip to content

Commit

Permalink
Merge pull request #458 from Zack921/master
Browse files Browse the repository at this point in the history
test(logger): add test unit for CleanLog
  • Loading branch information
Zack921 authored Jun 6, 2021
2 parents 724b897 + 7ea6d6f commit d4c1de2
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion lib/core/logger/__test__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ import currentContext from "../../context";
jest.mock("../../context");

(currentContext as jest.Mock).mockReturnValue({
log: {},
log: {
showLineNumber: false,
arr: [],
ERROR: 0,
WARN: 0,
INFO: 0,
DEBUG: 0
},
SN: 0
});

Expand All @@ -16,13 +23,35 @@ describe("logger test", () => {
expect(logger.logLevel).toBe(10);
});

test("log could be set by setCleanLog", async () => {
logger.setCleanLog(true);
expect(logger.getCleanLog()).toBe(true);

logger.setCleanLog(false);
});

test("debug and info could be hided by cleanLog", async () => {
logger.setCleanLog(true);

logger.debug("TEST DEBUG LOG IN CLEANLOG");
expect(log.DEBUG).toBe(0);

logger.info("TEST INFO LOG IN CLEANLOG");
expect(log.INFO).toBe(0);

logger.setCleanLog(false);
});

test("log could be classified by level", async () => {
logger.debug("TEST DEBUG LOG");
expect(log.DEBUG).toBe(1);

logger.info("TEST INFO LOG");
expect(log.INFO).toBe(1);

logger.warn("TEST INFO LOG");
expect(log.WARN).toBe(1);

logger.error("TEST ERROR LOG");
expect(log.ERROR).toBe(1);
});
Expand All @@ -34,6 +63,7 @@ describe("logger test", () => {

test("log could be log with color", async () => {
process.env.NODE_OPTIONS = "--inspect=true";

logger.error("LOG IS COLORFUL");
logger.warn("LOG IS COLORFUL");
logger.info("LOG IS COLORFUL");
Expand Down

0 comments on commit d4c1de2

Please sign in to comment.