Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(logger): add test unit for CleanLog #458

Merged
merged 2 commits into from
Jun 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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