-
-
Notifications
You must be signed in to change notification settings - Fork 520
/
Copy pathConsoleLoggerTest.js
76 lines (67 loc) · 1.58 KB
/
ConsoleLoggerTest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import test from "ava";
import ConsoleLogger from "../src/Util/ConsoleLogger.js";
test("Disable chalk", (t) => {
let cl = new ConsoleLogger();
cl.isChalkEnabled = false;
t.is(cl.isChalkEnabled, false);
});
test("Re-enable chalk", (t) => {
let cl = new ConsoleLogger();
cl.isChalkEnabled = false;
cl.isChalkEnabled = true;
t.is(cl.isChalkEnabled, true);
});
test("Message styles", (t) => {
let cl = new ConsoleLogger();
let logged;
cl.message = (msg, type, color, forceToConsole) =>
(logged = { msg, type, color, forceToConsole });
cl.log("test");
t.deepEqual(logged, {
msg: "test",
type: undefined,
color: undefined,
forceToConsole: undefined,
});
cl.forceLog("test");
t.deepEqual(logged, {
msg: "test",
type: undefined,
color: undefined,
forceToConsole: true,
});
cl.info("test");
t.deepEqual(logged, {
msg: "test",
type: "warn",
color: "blue",
forceToConsole: undefined,
});
cl.warn("test");
t.deepEqual(logged, {
msg: "test",
type: "warn",
color: "yellow",
forceToConsole: undefined,
});
cl.error("test");
t.deepEqual(logged, {
msg: "test",
type: "error",
color: "red",
forceToConsole: undefined,
});
});
test("Close Stream", (t) => {
return new Promise((resolve, reject) => {
let cl = new ConsoleLogger();
cl.outputStream.on("close", () => {
t.pass();
resolve();
});
cl.outputStream.on("error", reject);
// We need to listen for data, so a pushed null closes the stream
cl.outputStream.on("data", reject);
cl.closeStream();
});
});