-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser_test.ts
52 lines (47 loc) · 1.11 KB
/
parser_test.ts
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
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
import { parseLogEntry } from "./parser.ts";
import { LogLevel } from "./types.ts";
Deno.test("parseLogEntry outputFormat", () => {
const NativeDate = globalThis.Date;
class FakeDate {
toISOString() {
return "0000-00-00T-00:00:00.0000Z";
}
}
//
// Date is now mocked
//
globalThis.Date = FakeDate as DateConstructor;
const log = parseLogEntry(
LogLevel.INFO,
"foo",
"[{timestamp} {level}] {message} {params}",
);
//
// Date is now restored
//
globalThis.Date = NativeDate;
assertEquals(log, {
format: "foo",
formattedMessage: "[0000-00-00T-00:00:00.0000Z INFO] foo {}",
level: LogLevel.INFO,
message: "foo",
variables: {},
});
});
Deno.test("parseLogEntry format", () => {
const log = parseLogEntry(
LogLevel.INFO,
"{foo} {bar}",
"{message}",
"bar",
"foo",
);
assertEquals(log, {
format: "{foo} {bar}",
formattedMessage: "bar foo",
level: LogLevel.INFO,
message: "bar foo",
variables: { "bar": "foo", "foo": "bar" },
});
});