Skip to content

Commit 9948893

Browse files
committed
Fixing util inspect browser polyfill
1 parent cf6fc77 commit 9948893

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/runtime/browser/util.inspect.polyfil.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function isBoolean(arg: unknown) {
6060
}
6161

6262
function isUndefined(arg: unknown) {
63-
return arg === void 0;
63+
return arg == null;
6464
}
6565

6666
function stylizeNoColor(str: string) {
@@ -70,7 +70,7 @@ function stylizeNoColor(str: string) {
7070
function stylizeWithColor(str: string, styleType: string) {
7171
const style = inspect.styles[styleType];
7272

73-
if (style) {
73+
if (style != null && inspect?.colors?.[style]?.[0] != null && inspect?.colors?.[style]?.[1] != null) {
7474
return "\u001b[" + inspect.colors[style][0] + "m" + str + "\u001b[" + inspect.colors[style][1] + "m";
7575
} else {
7676
return str;

tests/Browser/1_json.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,14 @@ describe("Browser: JSON: Log level", () => {
5555

5656
expect(consoleOutput).toContain("Test");
5757
});
58+
59+
it("pretty no styles undefined", async () => {
60+
await page.evaluate(() => {
61+
// @ts-ignore
62+
const logger = new tslog.Logger({ type: "pretty", stylePrettyLogs: false });
63+
logger.fatal("Test undefined", { test: undefined });
64+
});
65+
66+
expect(consoleOutput).toContain("Test undefined");
67+
});
5868
});

0 commit comments

Comments
 (0)