Skip to content

Commit 06e21fe

Browse files
committed
Add tests for bug fixes
1 parent 287edb9 commit 06e21fe

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

tests/child.test.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,57 @@ describe("Logger: Child", () => {
100100
grandchild1.debug("test child1 message");
101101
expect(stdOut.length).toBe(attachedLogMessages.length);
102102
});
103+
104+
test("Don't overwrite parents' name", (): void => {
105+
const parent = new Logger({ name: "parent" });
106+
expect(parent.settings.name).toBe("parent");
107+
108+
const child = parent.getChildLogger({ requestId: "foo" });
109+
expect(child.settings.name).toBe("parent");
110+
});
111+
112+
test("Don't overwrite transports of parents and siblings", (): void => {
113+
const loggerParent = new Logger({
114+
name: "parent",
115+
stdOut: {
116+
write: (print: string) => {
117+
stdOut.push(print);
118+
},
119+
},
120+
stdErr: {
121+
write: (print: string) => {
122+
stdErr.push(print);
123+
},
124+
},
125+
});
126+
const loggerChild1 = loggerParent.getChildLogger({ name: "child1" });
127+
const loggerChild2 = loggerParent.getChildLogger({ name: "child2" });
128+
129+
const loggerTransportArray: unknown[][] = [];
130+
const logX = (logObject: ILogObject) => {
131+
loggerTransportArray.push(logObject.argumentsArray);
132+
};
133+
loggerChild1.attachTransport(
134+
{
135+
silly: logX,
136+
debug: logX,
137+
trace: logX,
138+
info: logX,
139+
warn: logX,
140+
error: logX,
141+
fatal: logX,
142+
},
143+
"debug"
144+
);
145+
146+
loggerParent.info("parent");
147+
loggerChild1.info("child1");
148+
loggerChild2.info("child2");
149+
150+
const loggerChild12 = loggerChild1.getChildLogger({ name: "child1-2" });
151+
loggerChild12.info("child1-2");
152+
153+
expect(loggerTransportArray[0][0]).toBe("child1");
154+
expect(loggerTransportArray[1][0]).toBe("child1-2");
155+
});
103156
});

0 commit comments

Comments
 (0)