Skip to content
Merged
Show file tree
Hide file tree
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
44 changes: 44 additions & 0 deletions spec/logger.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,50 @@ describe("logger", () => {
});
});

it("should not detect duplicate object as circular", () => {
const obj: any = { a: "foo" };
const entry: logger.LogEntry = {
severity: "ERROR",
message: "testing circular",
a: obj,
b: obj,
};
logger.write(entry);
expectStderr({
severity: "ERROR",
message: "testing circular",
a: { a: "foo" },
b: { a: "foo" },
});
});

it("should not detect duplicate object in array as circular", () => {
const obj: any = { a: "foo" };
const arr: any = [
{ a: obj, b: obj },
{ a: obj, b: obj },
];
const entry: logger.LogEntry = {
severity: "ERROR",
message: "testing circular",
a: arr,
b: arr,
};
logger.write(entry);
expectStderr({
severity: "ERROR",
message: "testing circular",
a: [
{ a: { a: "foo" }, b: { a: "foo" } },
{ a: { a: "foo" }, b: { a: "foo" } },
],
b: [
{ a: { a: "foo" }, b: { a: "foo" } },
{ a: { a: "foo" }, b: { a: "foo" } },
],
});
});

it("should not break on objects that override toJSON", () => {
const obj: any = { a: new Date("August 26, 1994 12:24:00Z") };

Expand Down
1 change: 1 addition & 0 deletions src/logger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ function removeCircular(obj: any, refs: any[] = []): any {
returnObj[k] = removeCircular(obj[k], refs);
}
}
refs.pop();
return returnObj;
}

Expand Down
Loading