2020-05-20 10:27:01 -04:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2020-06-12 09:27:41 -04:00
|
|
|
import { assert, assertEquals } from "../testing/asserts.ts";
|
|
|
|
import { getLogger, debug, info, warning, error, critical } from "./mod.ts";
|
2020-05-20 10:27:01 -04:00
|
|
|
import { Logger } from "./logger.ts";
|
|
|
|
|
|
|
|
let logger: Logger | null = null;
|
|
|
|
try {
|
|
|
|
// Need to initialize it here
|
|
|
|
// otherwise it will be already initialized on Deno.test
|
|
|
|
logger = getLogger();
|
2020-06-12 09:19:29 -04:00
|
|
|
} catch {
|
|
|
|
// Pass
|
|
|
|
}
|
2020-05-20 10:27:01 -04:00
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test("logger is initialized", function (): void {
|
2020-05-20 10:27:01 -04:00
|
|
|
assert(logger instanceof Logger);
|
|
|
|
});
|
2020-06-12 09:27:41 -04:00
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test("default loggers work as expected", function (): void {
|
2020-06-12 09:27:41 -04:00
|
|
|
const sym = Symbol("a");
|
|
|
|
const debugData: string = debug("foo");
|
|
|
|
const debugResolver: string | undefined = debug(() => "foo");
|
|
|
|
const infoData: number = info(456, 1, 2, 3);
|
|
|
|
const infoResolver: boolean | undefined = info(() => true);
|
|
|
|
const warningData: symbol = warning(sym);
|
|
|
|
const warningResolver: null | undefined = warning(() => null);
|
|
|
|
const errorData: undefined = error(undefined, 1, 2, 3);
|
|
|
|
const errorResolver: bigint | undefined = error(() => 5n);
|
|
|
|
const criticalData: string = critical("foo");
|
|
|
|
const criticalResolver: string | undefined = critical(() => "bar");
|
|
|
|
assertEquals(debugData, "foo");
|
|
|
|
assertEquals(debugResolver, undefined);
|
|
|
|
assertEquals(infoData, 456);
|
|
|
|
assertEquals(infoResolver, true);
|
|
|
|
assertEquals(warningData, sym);
|
|
|
|
assertEquals(warningResolver, null);
|
|
|
|
assertEquals(errorData, undefined);
|
|
|
|
assertEquals(errorResolver, 5n);
|
|
|
|
assertEquals(criticalData, "foo");
|
|
|
|
assertEquals(criticalResolver, "bar");
|
|
|
|
});
|