| @@ -1,86 +1,86 | |||
|
|
1 | 1 | import { TraceSource, DebugLevel } from "@implab/core/log/TraceSource"; |
|
|
2 | 2 | import * as tape from "tape"; |
|
|
3 | 3 | import { TapeWriter, test } from "./TestTraits"; |
|
|
4 | 4 | import { MockConsole } from "./mock/MockConsole"; |
|
|
5 | import { ConsoleLog } from "@implab/core/log/writers/ConsoleLog"; | |
|
|
5 | import { ConsoleLogger } from "@implab/core/log/writers/ConsoleLogger"; | |
|
|
6 | 6 | import { ConsoleWriter } from "@implab/core/log/ConsoleWriter"; |
|
|
7 | 7 | |
|
|
8 | 8 | const sourceId = "test/TraceSourceTests"; |
|
|
9 | 9 | |
|
|
10 | 10 | tape("trace message", t => { |
|
|
11 | 11 | const trace = TraceSource.get(sourceId); |
|
|
12 | 12 | |
|
|
13 | 13 | trace.level = DebugLevel; |
|
|
14 | 14 | |
|
|
15 | 15 | const h = trace.events.on(ev => { |
|
|
16 | 16 | t.equal(ev.source, trace, "sender should be the current trace source"); |
|
|
17 | 17 | t.equal(ev.level, DebugLevel, "level should be debug level"); |
|
|
18 | 18 | t.equal(ev.toString(), "Hello, World!", "The message should be a formatted message"); |
|
|
19 | 19 | |
|
|
20 | 20 | t.end(); |
|
|
21 | 21 | }); |
|
|
22 | 22 | |
|
|
23 | 23 | trace.debug("Hello, {0}!", "World"); |
|
|
24 | 24 | |
|
|
25 | 25 | h.destroy(); |
|
|
26 | 26 | }); |
|
|
27 | 27 | |
|
|
28 | 28 | tape("trace event", t => { |
|
|
29 | 29 | const trace = TraceSource.get(sourceId); |
|
|
30 | 30 | |
|
|
31 | 31 | trace.level = DebugLevel; |
|
|
32 | 32 | |
|
|
33 | 33 | const event = { |
|
|
34 | 34 | name: "custom event" |
|
|
35 | 35 | }; |
|
|
36 | 36 | |
|
|
37 | 37 | const h = trace.events.on(ev => { |
|
|
38 | 38 | t.equal(ev.source, trace, "sender should be the current trace source"); |
|
|
39 | 39 | t.equal(ev.level, DebugLevel, "level should be debug level"); |
|
|
40 | 40 | t.equal(ev.message, event, "The message should be the specified object"); |
|
|
41 | 41 | |
|
|
42 | 42 | t.end(); |
|
|
43 | 43 | }); |
|
|
44 | 44 | |
|
|
45 | 45 | trace.traceEvent(DebugLevel, event); |
|
|
46 | 46 | |
|
|
47 | 47 | h.destroy(); |
|
|
48 | 48 | }); |
|
|
49 | 49 | |
|
|
50 | 50 | tape("tape comment writer", async t => { |
|
|
51 | 51 | const writer = new TapeWriter(t); |
|
|
52 | 52 | |
|
|
53 | 53 | TraceSource.on(ts => { |
|
|
54 | 54 | writer.writeEvents(ts.events); |
|
|
55 | 55 | }); |
|
|
56 | 56 | |
|
|
57 | 57 | const trace = TraceSource.get(sourceId); |
|
|
58 | 58 | trace.level = DebugLevel; |
|
|
59 | 59 | |
|
|
60 | 60 | trace.log("Hello, {0}!", "World"); |
|
|
61 | 61 | trace.log("Multi\n line"); |
|
|
62 | 62 | trace.warn("Look at me!"); |
|
|
63 | 63 | trace.error("DIE!"); |
|
|
64 | 64 | |
|
|
65 | 65 | writer.destroy(); |
|
|
66 | 66 | |
|
|
67 | 67 | trace.log("You shouldn't see it!"); |
|
|
68 | 68 | |
|
|
69 | 69 | t.comment("DONE"); |
|
|
70 | 70 | |
|
|
71 | 71 | t.end(); |
|
|
72 | 72 | }); |
|
|
73 | 73 | |
|
|
74 | 74 | test("console writer", (t, trace) => { |
|
|
75 | 75 | |
|
|
76 | 76 | const mockConsole = new MockConsole(); |
|
|
77 | 77 | const writer = new ConsoleWriter(mockConsole); |
|
|
78 | const consoleLog = new ConsoleLog(writer); | |
|
|
78 | const consoleLog = new ConsoleLogger(writer); | |
|
|
79 | 79 | consoleLog.writeEvents(trace.events); |
|
|
80 | 80 | |
|
|
81 | 81 | trace.log("Hello, world!"); |
|
|
82 | 82 | t.deepEqual(mockConsole.getLine(0), ["console writer: Hello, world!"], "Log one string"); |
|
|
83 | 83 | |
|
|
84 | 84 | trace.log({ foo: "bar" }); |
|
|
85 | 85 | t.deepEqual(mockConsole.getLine(1), ["console writer: ", { foo: "bar" }], "Log an object"); |
|
|
86 | 86 | }); |
General Comments 0
You need to be logged in to leave comments.
Login now
