fix(log): ensure consistent behavior with @std/log (#5974)

* fix(log): ensure consistent behavior with `@std/log`

* update

* fixes
This commit is contained in:
Asher Gomez 2024-09-27 11:57:14 +10:00 committed by GitHub
parent d902c24651
commit 2774a070d6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 41 additions and 1 deletions

View File

@ -3,6 +3,7 @@
import { getLogger } from "./get_logger.ts";
import type { GenericFunction } from "./logger.ts";
import "./setup.ts";
/** Log with critical level, using default logger. */
export function critical<T>(msg: () => T, ...args: unknown[]): T | undefined;

View File

@ -1,10 +1,19 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { assertEquals } from "@std/assert";
import { assertSpyCall, spy } from "@std/testing/mock";
import { bold, red } from "@std/fmt/colors";
import { critical } from "./critical.ts";
Deno.test("critical()", () => {
using consoleInfoSpy = spy(console, "log");
const criticalData: string = critical("foo");
const criticalResolver: string | undefined = critical(() => "bar");
assertEquals(criticalData, "foo");
assertEquals(criticalResolver, "bar");
assertSpyCall(consoleInfoSpy, 0, {
args: [bold(red("CRITICAL foo"))],
});
assertSpyCall(consoleInfoSpy, 1, {
args: [bold(red("CRITICAL bar"))],
});
});

View File

@ -3,6 +3,7 @@
import { getLogger } from "./get_logger.ts";
import type { GenericFunction } from "./logger.ts";
import "./setup.ts";
/** Log with debug level, using default logger. */
export function debug<T>(msg: () => T, ...args: unknown[]): T | undefined;

View File

@ -1,6 +1,5 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { assertEquals } from "@std/assert";
import "./setup.ts";
import { debug } from "./debug.ts";
Deno.test("debug()", () => {

View File

@ -3,6 +3,7 @@
import { getLogger } from "./get_logger.ts";
import type { GenericFunction } from "./logger.ts";
import "./setup.ts";
/** Log with error level, using default logger. */
export function error<T>(msg: () => T, ...args: unknown[]): T | undefined;

View File

@ -1,10 +1,19 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { assertEquals } from "@std/assert";
import { assertSpyCall, spy } from "@std/testing/mock";
import { red } from "@std/fmt/colors";
import { error } from "./error.ts";
Deno.test("error()", () => {
using consoleInfoSpy = spy(console, "log");
const errorData: undefined = error(undefined, 1, 2, 3);
const errorResolver: bigint | undefined = error(() => 5n);
assertEquals(errorData, undefined);
assertEquals(errorResolver, 5n);
assertSpyCall(consoleInfoSpy, 0, {
args: [red("ERROR undefined")],
});
assertSpyCall(consoleInfoSpy, 1, {
args: [red("ERROR 5")],
});
});

View File

@ -3,6 +3,7 @@
import { getLogger } from "./get_logger.ts";
import type { GenericFunction } from "./logger.ts";
import "./setup.ts";
/** Log with info level, using default logger. */
export function info<T>(msg: () => T, ...args: unknown[]): T | undefined;

View File

@ -1,10 +1,19 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { assertEquals } from "@std/assert";
import { assertSpyCall, spy } from "@std/testing/mock";
import { blue } from "@std/fmt/colors";
import { info } from "./info.ts";
Deno.test("info()", () => {
using consoleInfoSpy = spy(console, "log");
const infoData: number = info(456, 1, 2, 3);
const infoResolver: boolean | undefined = info(() => true);
assertEquals(infoData, 456);
assertEquals(infoResolver, true);
assertSpyCall(consoleInfoSpy, 0, {
args: [blue("INFO 456")],
});
assertSpyCall(consoleInfoSpy, 1, {
args: [blue("INFO true")],
});
});

View File

@ -3,6 +3,7 @@
import { getLogger } from "./get_logger.ts";
import type { GenericFunction } from "./logger.ts";
import "./setup.ts";
export type { GenericFunction };

View File

@ -1,11 +1,20 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { assertEquals } from "@std/assert";
import { assertSpyCall, spy } from "@std/testing/mock";
import { yellow } from "@std/fmt/colors";
import { warn } from "./warn.ts";
Deno.test("warn()", () => {
using consoleInfoSpy = spy(console, "log");
const sym = Symbol("a");
const warnData: symbol = warn(sym);
const warnResolver: null | undefined = warn(() => null);
assertEquals(warnData, sym);
assertEquals(warnResolver, null);
assertSpyCall(consoleInfoSpy, 0, {
args: [yellow("WARN Symbol(a)")],
});
assertSpyCall(consoleInfoSpy, 1, {
args: [yellow("WARN null")],
});
});