From 9cc2c2cdc2c6a7de9d943d3abff55b1d3b75ccda Mon Sep 17 00:00:00 2001 From: Tim Date: Fri, 5 Jan 2024 11:55:50 +0100 Subject: [PATCH 01/12] initial commit --- log/logger.ts | 10 ++++++++++ log/logger_test.ts | 12 ++++++------ log/mod.ts | 34 ++++++++++++++++++++++++++++------ log/mod_test.ts | 10 +++++----- log/test.ts | 2 +- 5 files changed, 50 insertions(+), 18 deletions(-) diff --git a/log/logger.ts b/log/logger.ts index 9b60f78f3b1f..77726e023270 100644 --- a/log/logger.ts +++ b/log/logger.ts @@ -179,11 +179,21 @@ export class Logger { return this.#_log(LogLevels.INFO, msg, ...args); } + /** @deprecated (will be removed after 0.214.0) Use {@linkcode warn} instead. */ warning(msg: () => T, ...args: unknown[]): T | undefined; warning(msg: T extends GenericFunction ? never : T, ...args: unknown[]): T; warning( msg: (T extends GenericFunction ? never : T) | (() => T), ...args: unknown[] + ): T | undefined { + return this.warn(msg as () => T, ...args); + } + + warn(msg: () => T, ...args: unknown[]): T | undefined; + warn(msg: T extends GenericFunction ? never : T, ...args: unknown[]): T; + warn( + msg: (T extends GenericFunction ? never : T) | (() => T), + ...args: unknown[] ): T | undefined { return this.#_log(LogLevels.WARNING, msg, ...args); } diff --git a/log/logger_test.ts b/log/logger_test.ts index 11418767dd2a..8027f48d879d 100644 --- a/log/logger_test.ts +++ b/log/logger_test.ts @@ -70,12 +70,12 @@ Deno.test("logFunctions", function () { const logger = new Logger("default", level, { handlers: [handler] }); const debugData = logger.debug("foo"); const infoData = logger.info("bar"); - const warningData = logger.warning("baz"); + const warnData = logger.warn("baz"); const errorData = logger.error("boo"); const criticalData = logger.critical("doo"); assertEquals(debugData, "foo"); assertEquals(infoData, "bar"); - assertEquals(warningData, "baz"); + assertEquals(warnData, "baz"); assertEquals(errorData, "boo"); assertEquals(criticalData, "doo"); return handler; @@ -177,9 +177,9 @@ Deno.test( assertEquals(handler.messages[3], "INFO null"); // number - const data5: number = logger.warning(3); + const data5: number = logger.warn(3); assertEquals(data5, 3); - const data6: number = logger.warning(3, 1); + const data6: number = logger.warn(3, 1); assertEquals(data6, 3); assertEquals(handler.messages[4], "WARNING 3"); assertEquals(handler.messages[5], "WARNING 3"); @@ -217,9 +217,9 @@ Deno.test( assertEquals(handler.messages[13], "INFO Symbol(a)"); // function - const data15: string | undefined = logger.warning(fn); + const data15: string | undefined = logger.warn(fn); assertEquals(data15, "abc"); - const data16: string | undefined = logger.warning(fn, 1); + const data16: string | undefined = logger.warn(fn, 1); assertEquals(data16, "abc"); assertEquals(handler.messages[14], "WARNING abc"); assertEquals(handler.messages[15], "WARNING abc"); diff --git a/log/mod.ts b/log/mod.ts index 6f08f617337c..d5832129041e 100644 --- a/log/mod.ts +++ b/log/mod.ts @@ -139,7 +139,7 @@ * // additional logger configurations. You can log any data type. * log.debug("Hello world"); * log.info(123456); - * log.warning(true); + * log.warn(true); * log.error({ foo: "bar", fizz: "bazz" }); * log.critical("500 Internal server error"); * @@ -174,7 +174,7 @@ * // get default logger. * logger = log.getLogger(); * logger.debug("fizz"); // logs to `console`, because `file` handler requires "WARNING" level. - * logger.warning(41256); // logs to both `console` and `file` handlers. + * logger.warn(41256); // logs to both `console` and `file` handlers. * * // get custom logger * logger = log.getLogger("tasks"); @@ -498,7 +498,11 @@ export function info( return getLogger("default").info(msg, ...args); } -/** Log with warning level, using default logger. */ +/** + * @deprecated (will be removed after 0.214.0) Use {@linkcode warn} instead. + * + * Log with warning level, using default logger. + */ export function warning(msg: () => T, ...args: unknown[]): T | undefined; export function warning( msg: T extends GenericFunction ? never : T, @@ -510,12 +514,30 @@ export function warning( ): T | undefined { // Assist TS compiler with pass-through generic type if (msg instanceof Function) { - return getLogger("default").warning(msg, ...args); + return warn(msg, ...args); + } + return warn(msg, ...args); +} + +/** Log with warning level, using default logger. */ +export function warn(msg: () => T, ...args: unknown[]): T | undefined; +export function warn( + msg: T extends GenericFunction ? never : T, + ...args: unknown[] +): T; +export function warn( + msg: (T extends GenericFunction ? never : T) | (() => T), + ...args: unknown[] +): T | undefined { + // Assist TS compiler with pass-through generic type + if (msg instanceof Function) { + return getLogger("default").warn(msg, ...args); } - return getLogger("default").warning(msg, ...args); + return getLogger("default").warn(msg, ...args); } -/** Log with error level, using default logger. */ +/** Log with e + * rror level, using default logger. */ export function error(msg: () => T, ...args: unknown[]): T | undefined; export function error( msg: T extends GenericFunction ? never : T, diff --git a/log/mod_test.ts b/log/mod_test.ts index 072fd5d46e6d..b0e36ef7a96d 100644 --- a/log/mod_test.ts +++ b/log/mod_test.ts @@ -10,7 +10,7 @@ import { Logger, LogLevels, setup, - warning, + warn, } from "./mod.ts"; import { BaseHandler } from "./handlers.ts"; @@ -41,8 +41,8 @@ Deno.test("default loggers work as expected", function () { 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 warnData: symbol = warn(sym); + const warnResolver: null | undefined = warn(() => null); const errorData: undefined = error(undefined, 1, 2, 3); const errorResolver: bigint | undefined = error(() => 5n); const criticalData: string = critical("foo"); @@ -51,8 +51,8 @@ Deno.test("default loggers work as expected", function () { assertEquals(debugResolver, undefined); assertEquals(infoData, 456); assertEquals(infoResolver, true); - assertEquals(warningData, sym); - assertEquals(warningResolver, null); + assertEquals(warnData, sym); + assertEquals(warnResolver, null); assertEquals(errorData, undefined); assertEquals(errorResolver, 5n); assertEquals(criticalData, "foo"); diff --git a/log/test.ts b/log/test.ts index 51c9a9fc5e89..9e6d2bdcc740 100644 --- a/log/test.ts +++ b/log/test.ts @@ -23,7 +23,7 @@ Deno.test("defaultHandlers", async function () { } = { DEBUG: log.debug, INFO: log.info, - WARNING: log.warning, + WARNING: log.warn, ERROR: log.error, CRITICAL: log.critical, }; From 681962111173b9db988b61fcf86156a1c5dd8281 Mon Sep 17 00:00:00 2001 From: Tim Reichen Date: Sat, 6 Jan 2024 11:55:00 +0100 Subject: [PATCH 02/12] Update log/logger.ts Co-authored-by: Asher Gomez --- log/logger.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/log/logger.ts b/log/logger.ts index 77726e023270..b01b8ffd1ea7 100644 --- a/log/logger.ts +++ b/log/logger.ts @@ -181,6 +181,7 @@ export class Logger { /** @deprecated (will be removed after 0.214.0) Use {@linkcode warn} instead. */ warning(msg: () => T, ...args: unknown[]): T | undefined; + /** @deprecated (will be removed after 0.214.0) Use {@linkcode warn} instead. */ warning(msg: T extends GenericFunction ? never : T, ...args: unknown[]): T; warning( msg: (T extends GenericFunction ? never : T) | (() => T), From 208735009bdf998c6e28060d3f5ffaca6c9ae943 Mon Sep 17 00:00:00 2001 From: Tim Date: Sun, 7 Jan 2024 07:45:43 +0100 Subject: [PATCH 03/12] replace WARNING with WARN --- log/handlers.ts | 2 +- log/handlers_test.ts | 40 ++++++++++---------- log/levels.ts | 4 +- log/logger.ts | 2 +- log/logger_test.ts | 16 ++++---- log/mod.ts | 12 ++++-- log/mod_test.ts | 6 +-- log/test.ts | 2 +- semver/format_range_test.ts | 73 +++++++++++++++++++++++++++++++++++++ 9 files changed, 117 insertions(+), 40 deletions(-) create mode 100644 semver/format_range_test.ts diff --git a/log/handlers.ts b/log/handlers.ts index 955d438629c5..2ec4b8b1095e 100644 --- a/log/handlers.ts +++ b/log/handlers.ts @@ -88,7 +88,7 @@ export class ConsoleHandler extends BaseHandler { case LogLevels.INFO: msg = blue(msg); break; - case LogLevels.WARNING: + case LogLevels.WARN: msg = yellow(msg); break; case LogLevels.ERROR: diff --git a/log/handlers_test.ts b/log/handlers_test.ts index 1f6745121ecf..0245d87f9ead 100644 --- a/log/handlers_test.ts +++ b/log/handlers_test.ts @@ -33,7 +33,7 @@ Deno.test("simpleHandler", function () { [ "DEBUG debug-test", "INFO info-test", - "WARNING warning-test", + "WARN warn-test", "ERROR error-test", "CRITICAL critical-test", ], @@ -42,14 +42,14 @@ Deno.test("simpleHandler", function () { LogLevels.INFO, [ "INFO info-test", - "WARNING warning-test", + "WARN warn-test", "ERROR error-test", "CRITICAL critical-test", ], ], [ - LogLevels.WARNING, - ["WARNING warning-test", "ERROR error-test", "CRITICAL critical-test"], + LogLevels.WARN, + ["WARN warn-test", "ERROR error-test", "CRITICAL critical-test"], ], [LogLevels.ERROR, ["ERROR error-test", "CRITICAL critical-test"]], [LogLevels.CRITICAL, ["CRITICAL critical-test"]], @@ -164,7 +164,7 @@ Deno.test({ } } - const testFileHandler = new TestFileHandler("WARNING", { + const testFileHandler = new TestFileHandler("WARN", { filename: LOG_FILE, mode: "w", }); @@ -175,7 +175,7 @@ Deno.test({ new LogRecord({ msg: "The starry heavens above me and the moral law within me.", args: [], - level: LogLevels.WARNING, + level: LogLevels.WARN, loggerName: "default", }), ); @@ -188,7 +188,7 @@ Deno.test({ Deno.test({ name: "FileHandler with mode 'w' will wipe clean existing log file", async fn() { - const fileHandler = new FileHandler("WARNING", { + const fileHandler = new FileHandler("WARN", { filename: LOG_FILE, mode: "w", }); @@ -198,7 +198,7 @@ Deno.test({ new LogRecord({ msg: "Hello World", args: [], - level: LogLevels.WARNING, + level: LogLevels.WARN, loggerName: "default", }), ); @@ -210,7 +210,7 @@ Deno.test({ new LogRecord({ msg: "Hello World", args: [], - level: LogLevels.WARNING, + level: LogLevels.WARN, loggerName: "default", }), ); @@ -225,7 +225,7 @@ Deno.test({ Deno.test({ name: "FileHandler with mode 'x' will throw if log file already exists", fn() { - const fileHandler = new FileHandler("WARNING", { + const fileHandler = new FileHandler("WARN", { filename: LOG_FILE, mode: "x", }); @@ -259,7 +259,7 @@ Deno.test({ new TextEncoder().encode("hello world"), ); - const fileHandler = new RotatingFileHandler("WARNING", { + const fileHandler = new RotatingFileHandler("WARN", { filename: LOG_FILE, maxBytes: 50, maxBackupCount: 3, @@ -285,7 +285,7 @@ Deno.test({ LOG_FILE + ".3", new TextEncoder().encode("hello world"), ); - const fileHandler = new RotatingFileHandler("WARNING", { + const fileHandler = new RotatingFileHandler("WARN", { filename: LOG_FILE, maxBytes: 50, maxBackupCount: 3, @@ -308,7 +308,7 @@ Deno.test({ Deno.test({ name: "RotatingFileHandler with first rollover, monitor step by step", async fn() { - const fileHandler = new RotatingFileHandler("WARNING", { + const fileHandler = new RotatingFileHandler("WARN", { filename: LOG_FILE, maxBytes: 25, maxBackupCount: 3, @@ -358,7 +358,7 @@ Deno.test({ Deno.test({ name: "RotatingFileHandler with first rollover, check all at once", async fn() { - const fileHandler = new RotatingFileHandler("WARNING", { + const fileHandler = new RotatingFileHandler("WARN", { filename: LOG_FILE, maxBytes: 25, maxBackupCount: 3, @@ -418,7 +418,7 @@ Deno.test({ new TextEncoder().encode("original log.3 file"), ); - const fileHandler = new RotatingFileHandler("WARNING", { + const fileHandler = new RotatingFileHandler("WARN", { filename: LOG_FILE, maxBytes: 2, maxBackupCount: 3, @@ -463,7 +463,7 @@ Deno.test({ fn() { assertThrows( () => { - const fileHandler = new RotatingFileHandler("WARNING", { + const fileHandler = new RotatingFileHandler("WARN", { filename: LOG_FILE, maxBytes: 0, maxBackupCount: 3, @@ -482,7 +482,7 @@ Deno.test({ fn() { assertThrows( () => { - const fileHandler = new RotatingFileHandler("WARNING", { + const fileHandler = new RotatingFileHandler("WARN", { filename: LOG_FILE, maxBytes: 50, maxBackupCount: 0, @@ -499,7 +499,7 @@ Deno.test({ Deno.test({ name: "Window unload flushes buffer", async fn() { - const fileHandler = new FileHandler("WARNING", { + const fileHandler = new FileHandler("WARN", { filename: LOG_FILE, mode: "w", }); @@ -525,7 +525,7 @@ Deno.test({ Deno.test({ name: "RotatingFileHandler: rotate on byte length, not msg length", async fn() { - const fileHandler = new RotatingFileHandler("WARNING", { + const fileHandler = new RotatingFileHandler("WARN", { filename: LOG_FILE, maxBytes: 7, maxBackupCount: 1, @@ -559,7 +559,7 @@ Deno.test({ Deno.test({ name: "FileHandler: Critical logs trigger immediate flush", async fn() { - const fileHandler = new FileHandler("WARNING", { + const fileHandler = new FileHandler("WARN", { filename: LOG_FILE, mode: "w", }); diff --git a/log/levels.ts b/log/levels.ts index a62644f04d23..963b2c79c2c5 100644 --- a/log/levels.ts +++ b/log/levels.ts @@ -9,7 +9,7 @@ export const LogLevels = { NOTSET: 0, DEBUG: 10, INFO: 20, - WARNING: 30, + WARN: 30, ERROR: 40, CRITICAL: 50, /* @deprecated (will be removed after 0.211.0) Use {@linkcode getLevelName} instead */ @@ -41,7 +41,7 @@ const byLevel: Record = { [LogLevels.NOTSET]: "NOTSET", [LogLevels.DEBUG]: "DEBUG", [LogLevels.INFO]: "INFO", - [LogLevels.WARNING]: "WARNING", + [LogLevels.WARN]: "WARN", [LogLevels.ERROR]: "ERROR", [LogLevels.CRITICAL]: "CRITICAL", }; diff --git a/log/logger.ts b/log/logger.ts index 77726e023270..bb7d9db6260c 100644 --- a/log/logger.ts +++ b/log/logger.ts @@ -195,7 +195,7 @@ export class Logger { msg: (T extends GenericFunction ? never : T) | (() => T), ...args: unknown[] ): T | undefined { - return this.#_log(LogLevels.WARNING, msg, ...args); + return this.#_log(LogLevels.WARN, msg, ...args); } error(msg: () => T, ...args: unknown[]): T | undefined; diff --git a/log/logger_test.ts b/log/logger_test.ts index 8027f48d879d..67acacc74db9 100644 --- a/log/logger_test.ts +++ b/log/logger_test.ts @@ -87,7 +87,7 @@ Deno.test("logFunctions", function () { assertEquals(handler.messages, [ "DEBUG foo", "INFO bar", - "WARNING baz", + "WARN baz", "ERROR boo", "CRITICAL doo", ]); @@ -96,14 +96,14 @@ Deno.test("logFunctions", function () { assertEquals(handler.messages, [ "INFO bar", - "WARNING baz", + "WARN baz", "ERROR boo", "CRITICAL doo", ]); - handler = doLog("WARNING"); + handler = doLog("WARN"); - assertEquals(handler.messages, ["WARNING baz", "ERROR boo", "CRITICAL doo"]); + assertEquals(handler.messages, ["WARN baz", "ERROR boo", "CRITICAL doo"]); handler = doLog("ERROR"); @@ -181,8 +181,8 @@ Deno.test( assertEquals(data5, 3); const data6: number = logger.warn(3, 1); assertEquals(data6, 3); - assertEquals(handler.messages[4], "WARNING 3"); - assertEquals(handler.messages[5], "WARNING 3"); + assertEquals(handler.messages[4], "WARN 3"); + assertEquals(handler.messages[5], "WARN 3"); // bigint const data7: bigint = logger.error(5n); @@ -221,8 +221,8 @@ Deno.test( assertEquals(data15, "abc"); const data16: string | undefined = logger.warn(fn, 1); assertEquals(data16, "abc"); - assertEquals(handler.messages[14], "WARNING abc"); - assertEquals(handler.messages[15], "WARNING abc"); + assertEquals(handler.messages[14], "WARN abc"); + assertEquals(handler.messages[15], "WARN abc"); // object const data17: { payload: string; other: number } = logger.error({ diff --git a/log/mod.ts b/log/mod.ts index d5832129041e..6042cb40671b 100644 --- a/log/mod.ts +++ b/log/mod.ts @@ -148,7 +148,7 @@ * handlers: { * console: new log.handlers.ConsoleHandler("DEBUG"), * - * file: new log.handlers.FileHandler("WARNING", { + * file: new log.handlers.FileHandler("WARN", { * filename: "./log.txt", * // you can change format of output message using any keys in `LogRecord`. * formatter: (record) => `${record.levelName} ${record.msg}`, @@ -173,7 +173,7 @@ * * // get default logger. * logger = log.getLogger(); - * logger.debug("fizz"); // logs to `console`, because `file` handler requires "WARNING" level. + * logger.debug("fizz"); // logs to `console`, because `file` handler requires "WARN" level. * logger.warn(41256); // logs to both `console` and `file` handlers. * * // get custom logger @@ -504,6 +504,11 @@ export function info( * Log with warning level, using default logger. */ export function warning(msg: () => T, ...args: unknown[]): T | undefined; +/** + * @deprecated (will be removed after 0.214.0) Use {@linkcode warn} instead. + * + * Log with warning level, using default logger. + */ export function warning( msg: T extends GenericFunction ? never : T, ...args: unknown[] @@ -536,8 +541,7 @@ export function warn( return getLogger("default").warn(msg, ...args); } -/** Log with e - * rror level, using default logger. */ +/** Log with error level, using default logger. */ export function error(msg: () => T, ...args: unknown[]): T | undefined; export function error( msg: T extends GenericFunction ? never : T, diff --git a/log/mod_test.ts b/log/mod_test.ts index b0e36ef7a96d..8f35ab7f64fc 100644 --- a/log/mod_test.ts +++ b/log/mod_test.ts @@ -122,9 +122,9 @@ Deno.test({ assertEquals(testHandler.messages[2], "CRITICAL critical"); testHandler.messages = []; - logger.level = LogLevels.WARNING; - assertEquals(logger.levelName, "WARNING"); - assertEquals(logger.level, LogLevels.WARNING); + logger.level = LogLevels.WARN; + assertEquals(logger.levelName, "WARN"); + assertEquals(logger.level, LogLevels.WARN); logger.debug("debug2"); logger.error("error2"); diff --git a/log/test.ts b/log/test.ts index 9e6d2bdcc740..516959d610f7 100644 --- a/log/test.ts +++ b/log/test.ts @@ -23,7 +23,7 @@ Deno.test("defaultHandlers", async function () { } = { DEBUG: log.debug, INFO: log.info, - WARNING: log.warn, + WARN: log.warn, ERROR: log.error, CRITICAL: log.critical, }; diff --git a/semver/format_range_test.ts b/semver/format_range_test.ts new file mode 100644 index 000000000000..e9cbd0f5a65c --- /dev/null +++ b/semver/format_range_test.ts @@ -0,0 +1,73 @@ +// Copyright Isaac Z. Schlueter and Contributors. All rights reserved. ISC license. +// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +import { assertEquals } from "../assert/mod.ts"; +import { formatRange } from "./format_range.ts"; +import { parseRange } from "./parse_range.ts"; + +Deno.test({ + name: "formatRange() handles valid range", + fn: async (t) => { + const versions: [string, string][] = [ + ["1.0.0 - 2.0.0", ">=1.0.0 <=2.0.0"], + ["1.0.0", "1.0.0"], + [">=*", "*"], + ["", "*"], + ["*", "*"], + [">=1.0.0", ">=1.0.0"], + [">1.0.0", ">1.0.0"], + ["<=2.0.0", "<=2.0.0"], + ["1", ">=1.0.0 <2.0.0"], + ["<=2.0.0", "<=2.0.0"], + ["<=2.0.0", "<=2.0.0"], + ["<2.0.0", "<2.0.0"], + ["<2.0.0", "<2.0.0"], + [">=0.1.97", ">=0.1.97"], + [">=0.1.97", ">=0.1.97"], + ["0.1.20 || 1.2.4", "0.1.20||1.2.4"], + [">=0.2.3 || <0.0.1", ">=0.2.3||<0.0.1"], + [">=0.2.3 || <0.0.1", ">=0.2.3||<0.0.1"], + [">=0.2.3 || <0.0.1", ">=0.2.3||<0.0.1"], + ["||", "*||*"], + ["2.x.x", ">=2.0.0 <3.0.0"], + ["1.2.x", ">=1.2.0 <1.3.0"], + ["1.2.x || 2.x", ">=1.2.0 <1.3.0||>=2.0.0 <3.0.0"], + ["1.2.x || 2.x", ">=1.2.0 <1.3.0||>=2.0.0 <3.0.0"], + ["x", "*"], + ["2.*.*", ">=2.0.0 <3.0.0"], + ["1.2.*", ">=1.2.0 <1.3.0"], + ["1.2.* || 2.*", ">=1.2.0 <1.3.0||>=2.0.0 <3.0.0"], + ["2", ">=2.0.0 <3.0.0"], + ["2.3", ">=2.3.0 <2.4.0"], + ["~2.4", ">=2.4.0 <2.5.0"], + ["~2.4", ">=2.4.0 <2.5.0"], + ["~>3.2.1", ">=3.2.1 <3.3.0"], + ["~1", ">=1.0.0 <2.0.0"], + ["~>1", ">=1.0.0 <2.0.0"], + ["~1.0", ">=1.0.0 <1.1.0"], + ["^0", ">=0.0.0 <1.0.0"], + ["^0.1", ">=0.1.0 <0.2.0"], + ["^1.0", ">=1.0.0 <2.0.0"], + ["^1.2", ">=1.2.0 <2.0.0"], + ["^0.0.1", ">=0.0.1 <0.0.2"], + ["^0.0.1-beta", ">=0.0.1-beta <0.0.2"], + ["^0.1.2", ">=0.1.2 <0.2.0"], + ["^1.2.3", ">=1.2.3 <2.0.0"], + ["^1.2.3-beta.4", ">=1.2.3-beta.4 <2.0.0"], + ["<1", "<1.0.0"], + [">=1", ">=1.0.0"], + ["<1.2", "<1.2.0"], + ["1", ">=1.0.0 <2.0.0"], + ]; + + for (const [r, expected] of versions) { + await t.step({ + name: `${r} -> ${expected}`, + fn: () => { + const range = parseRange(r); + const actual = formatRange(range); + assertEquals(actual, expected); + }, + }); + } + }, +}); From 2794f68c892a563a80afdb08de65325e301e3969 Mon Sep 17 00:00:00 2001 From: Tim Reichen Date: Sun, 7 Jan 2024 07:48:19 +0100 Subject: [PATCH 04/12] update --- semver/format_range_test.ts | 73 ------------------------------------- 1 file changed, 73 deletions(-) delete mode 100644 semver/format_range_test.ts diff --git a/semver/format_range_test.ts b/semver/format_range_test.ts deleted file mode 100644 index e9cbd0f5a65c..000000000000 --- a/semver/format_range_test.ts +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright Isaac Z. Schlueter and Contributors. All rights reserved. ISC license. -// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../assert/mod.ts"; -import { formatRange } from "./format_range.ts"; -import { parseRange } from "./parse_range.ts"; - -Deno.test({ - name: "formatRange() handles valid range", - fn: async (t) => { - const versions: [string, string][] = [ - ["1.0.0 - 2.0.0", ">=1.0.0 <=2.0.0"], - ["1.0.0", "1.0.0"], - [">=*", "*"], - ["", "*"], - ["*", "*"], - [">=1.0.0", ">=1.0.0"], - [">1.0.0", ">1.0.0"], - ["<=2.0.0", "<=2.0.0"], - ["1", ">=1.0.0 <2.0.0"], - ["<=2.0.0", "<=2.0.0"], - ["<=2.0.0", "<=2.0.0"], - ["<2.0.0", "<2.0.0"], - ["<2.0.0", "<2.0.0"], - [">=0.1.97", ">=0.1.97"], - [">=0.1.97", ">=0.1.97"], - ["0.1.20 || 1.2.4", "0.1.20||1.2.4"], - [">=0.2.3 || <0.0.1", ">=0.2.3||<0.0.1"], - [">=0.2.3 || <0.0.1", ">=0.2.3||<0.0.1"], - [">=0.2.3 || <0.0.1", ">=0.2.3||<0.0.1"], - ["||", "*||*"], - ["2.x.x", ">=2.0.0 <3.0.0"], - ["1.2.x", ">=1.2.0 <1.3.0"], - ["1.2.x || 2.x", ">=1.2.0 <1.3.0||>=2.0.0 <3.0.0"], - ["1.2.x || 2.x", ">=1.2.0 <1.3.0||>=2.0.0 <3.0.0"], - ["x", "*"], - ["2.*.*", ">=2.0.0 <3.0.0"], - ["1.2.*", ">=1.2.0 <1.3.0"], - ["1.2.* || 2.*", ">=1.2.0 <1.3.0||>=2.0.0 <3.0.0"], - ["2", ">=2.0.0 <3.0.0"], - ["2.3", ">=2.3.0 <2.4.0"], - ["~2.4", ">=2.4.0 <2.5.0"], - ["~2.4", ">=2.4.0 <2.5.0"], - ["~>3.2.1", ">=3.2.1 <3.3.0"], - ["~1", ">=1.0.0 <2.0.0"], - ["~>1", ">=1.0.0 <2.0.0"], - ["~1.0", ">=1.0.0 <1.1.0"], - ["^0", ">=0.0.0 <1.0.0"], - ["^0.1", ">=0.1.0 <0.2.0"], - ["^1.0", ">=1.0.0 <2.0.0"], - ["^1.2", ">=1.2.0 <2.0.0"], - ["^0.0.1", ">=0.0.1 <0.0.2"], - ["^0.0.1-beta", ">=0.0.1-beta <0.0.2"], - ["^0.1.2", ">=0.1.2 <0.2.0"], - ["^1.2.3", ">=1.2.3 <2.0.0"], - ["^1.2.3-beta.4", ">=1.2.3-beta.4 <2.0.0"], - ["<1", "<1.0.0"], - [">=1", ">=1.0.0"], - ["<1.2", "<1.2.0"], - ["1", ">=1.0.0 <2.0.0"], - ]; - - for (const [r, expected] of versions) { - await t.step({ - name: `${r} -> ${expected}`, - fn: () => { - const range = parseRange(r); - const actual = formatRange(range); - assertEquals(actual, expected); - }, - }); - } - }, -}); From 2e482673f88afc4ea8ee4cde1d491676ee3a4ab4 Mon Sep 17 00:00:00 2001 From: Tim Reichen Date: Mon, 8 Jan 2024 00:37:45 +0100 Subject: [PATCH 05/12] refactor(cli): make `Spinner` constructor options more readable (#4091) * initial commit * update --- cli/spinner.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/cli/spinner.ts b/cli/spinner.ts index 014b3defa0ae..8d1450fc5759 100644 --- a/cli/spinner.ts +++ b/cli/spinner.ts @@ -85,11 +85,18 @@ export class Spinner { * const spinner = new Spinner({ message: "Loading..." }); * ``` */ - constructor(options?: SpinnerOptions) { - this.#spinner = options?.spinner ?? DEFAULT_SPINNER; - this.message = options?.message ?? ""; - this.#interval = options?.interval ?? DEFAULT_INTERVAL; - this.color = options?.color; + constructor( + { + spinner = DEFAULT_SPINNER, + message = "", + interval = DEFAULT_INTERVAL, + color, + }: SpinnerOptions = {}, + ) { + this.#spinner = spinner; + this.message = message; + this.#interval = interval; + this.color = color; } set color(value: Color | undefined) { From 515bfa76be8ee9ccad605703468425d313b32626 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Mon, 8 Jan 2024 13:17:03 +1100 Subject: [PATCH 06/12] docs(testing): fix assertion deprecation notices (#4122) --- testing/asserts.ts | 1007 ++++++++++++++++++++++++++++++-------------- 1 file changed, 683 insertions(+), 324 deletions(-) diff --git a/testing/asserts.ts b/testing/asserts.ts index 55fbed6326d7..f9a6a6b08769 100644 --- a/testing/asserts.ts +++ b/testing/asserts.ts @@ -1,8 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. /** - * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/mod.ts} instead. - * * A library of assertion functions. * If the assertion is false an `AssertionError` will be thrown which will * result in pretty-printed diff of failing assertion. @@ -10,328 +8,689 @@ * This module is browser compatible, but do not rely on good formatting of * values for AssertionError messages in browsers. * + * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/mod.ts} instead. + * * @module */ +import * as asserts from "../assert/mod.ts"; + +/** + * Make an assertion that `actual` and `expected` are almost equal numbers + * through a given tolerance. It can be used to take into account IEEE-754 + * double-precision floating-point representation limitations. If the values + * are not almost equal then throw. + * + * @example + * ```ts + * import { assertAlmostEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * + * assertAlmostEquals(0.01, 0.02, 0.1); // Doesn't throw + * assertAlmostEquals(0.01, 0.02); // Throws + * assertAlmostEquals(0.1 + 0.2, 0.3, 1e-16); // Doesn't throw + * assertAlmostEquals(0.1 + 0.2, 0.3, 1e-17); // Throws + * ``` + * + * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_almost_equals.ts} instead. + */ +export function assertAlmostEquals( + actual: number, + expected: number, + tolerance = 1e-7, + msg?: string, +) { + asserts.assertAlmostEquals(actual, expected, tolerance, msg); +} + +/** + * An array-like object (`Array`, `Uint8Array`, `NodeList`, etc.) that is not a string. + * + * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_array_includes.ts} instead. + */ +export type ArrayLikeArg = ArrayLike & object; + +/** + * Make an assertion that `actual` includes the `expected` values. If not then + * an error will be thrown. + * + * Type parameter can be specified to ensure values under comparison have the + * same type. + * + * @example + * ```ts + * import { assertArrayIncludes } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * + * assertArrayIncludes([1, 2], [2]); // Doesn't throw + * assertArrayIncludes([1, 2], [3]); // Throws + * ``` + * + * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_array_includes.ts} instead. + */ +export function assertArrayIncludes( + actual: ArrayLikeArg, + expected: ArrayLikeArg, + msg?: string, +) { + asserts.assertArrayIncludes(actual, expected, msg); +} + +/** + * Make an assertion that `actual` and `expected` are equal, deeply. If not + * deeply equal, then throw. + * + * Type parameter can be specified to ensure values under comparison have the + * same type. + * + * @example + * ```ts + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * + * assertEquals("world", "world"); // Doesn't throw + * assertEquals("hello", "world"); // Throws + * ``` + * + * Note: formatter option is experimental and may be removed in the future. + * + * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_equals.ts} instead. + */ +export function assertEquals( + actual: T, + expected: T, + msg?: string, + options: { formatter?: (value: unknown) => string } = {}, +) { + asserts.assertEquals(actual, expected, msg, options); +} + +/** + * Make an assertion that actual is not null or undefined. + * If not then throw. + * + * @example + * ```ts + * import { assertExists } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * + * assertExists("something"); // Doesn't throw + * assertExists(undefined); // Throws + * ``` + * + * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_exists.ts} instead. + */ +export function assertExists( + actual: T, + msg?: string, +): asserts actual is NonNullable { + asserts.assertExists(actual, msg); +} + +/** + * Assertion condition for {@linkcode assertFalse}. + * + * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_false.ts} instead. + */ +export type Falsy = false | 0 | 0n | "" | null | undefined; + +/** + * Make an assertion, error will be thrown if `expr` have truthy value. + * + * @example + * ```ts + * import { assertFalse } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * + * assertFalse(false); // Doesn't throw + * assertFalse(true); // Throws + * ``` + * + * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_false.ts} instead. + */ +export function assertFalse(expr: unknown, msg = ""): asserts expr is Falsy { + asserts.assertFalse(expr, msg); +} + +/** + * Make an assertion that `actual` is greater than or equal to `expected`. + * If not then throw. + * + * @example + * ```ts + * import { assertGreaterOrEqual } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * + * assertGreaterOrEqual(2, 1); // Doesn't throw + * assertGreaterOrEqual(1, 1); // Doesn't throw + * assertGreaterOrEqual(0, 1); // Throws + * ``` + * + * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_greater_or_equal.ts} instead. + */ +export function assertGreaterOrEqual( + actual: T, + expected: T, + msg?: string, +) { + asserts.assertGreaterOrEqual(actual, expected, msg); +} + +/** + * Make an assertion that `actual` is greater than `expected`. + * If not then throw. + * + * @example + * ```ts + * import { assertGreater } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * + * assertGreater(2, 1); // Doesn't throw + * assertGreater(1, 1); // Throws + * assertGreater(0, 1); // Throws + * ``` + * + * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_greater.ts} instead. + */ +export function assertGreater(actual: T, expected: T, msg?: string) { + asserts.assertGreater(actual, expected, msg); +} + +/** + * Any constructor + * + * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_instance_of.ts} instead. + */ +// deno-lint-ignore no-explicit-any +export type AnyConstructor = new (...args: any[]) => any; +/** Gets constructor type + * + * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_instance_of.ts} instead. + */ +export type GetConstructorType = T extends // deno-lint-ignore no-explicit-any +new (...args: any) => infer C ? C + : never; + +/** + * Make an assertion that `obj` is an instance of `type`. + * If not then throw. + * + * @example + * ```ts + * import { assertInstanceOf } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * + * assertInstanceOf(new Date(), Date); // Doesn't throw + * assertInstanceOf(new Date(), Number); // Throws + * ``` + * + * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_instance_of.ts} instead. + */ +export function assertInstanceOf( + actual: unknown, + expectedType: T, + msg = "", +): asserts actual is GetConstructorType { + asserts.assertInstanceOf(actual, expectedType, msg); +} + +/** + * Make an assertion that `error` is an `Error`. + * If not then an error will be thrown. + * An error class and a string that should be included in the + * error message can also be asserted. + * + * @example + * ```ts + * import { assertIsError } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * + * assertIsError(null); // Throws + * assertIsError(new RangeError("Out of range")); // Doesn't throw + * assertIsError(new RangeError("Out of range"), SyntaxError); // Throws + * assertIsError(new RangeError("Out of range"), SyntaxError, "Out of range"); // Doesn't throw + * assertIsError(new RangeError("Out of range"), SyntaxError, "Within range"); // Throws + * ``` + * + * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_is_error.ts} instead. + */ +export function assertIsError( + error: unknown, + // deno-lint-ignore no-explicit-any + ErrorClass?: new (...args: any[]) => E, + msgMatches?: string | RegExp, + msg?: string, +): asserts error is E { + asserts.assertIsError(error, ErrorClass, msgMatches, msg); +} + +/** + * Make an assertion that `actual` is less than or equal to `expected`. + * If not then throw. + * + * @example + * ```ts + * import { assertLessOrEqual } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * + * assertLessOrEqual(1, 2); // Doesn't throw + * assertLessOrEqual(1, 1); // Doesn't throw + * assertLessOrEqual(1, 0); // Throws + * ``` + * + * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_less_or_equal.ts} instead. + */ +export function assertLessOrEqual( + actual: T, + expected: T, + msg?: string, +) { + asserts.assertLessOrEqual(actual, expected, msg); +} + +/** + * Make an assertion that `actual` is less than `expected`. + * If not then throw. + * + * @example + * ```ts + * import { assertLess } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * + * assertLess(1, 2); // Doesn't throw + * assertLess(2, 1); // Throws + * ``` + * + * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_less.ts} instead. + */ +export function assertLess(actual: T, expected: T, msg?: string) { + asserts.assertLess(actual, expected, msg); +} + +/** + * Make an assertion that `actual` match RegExp `expected`. If not + * then throw. + * + * @example + * ```ts + * import { assertMatch } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * + * assertMatch("Raptor", RegExp(/Raptor/)); // Doesn't throw + * assertMatch("Denosaurus", RegExp(/Raptor/)); // Throws + * ``` + * + * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_match.ts} instead. + */ +export function assertMatch( + actual: string, + expected: RegExp, + msg?: string, +) { + asserts.assertMatch(actual, expected, msg); +} + +/** + * Make an assertion that `actual` and `expected` are not equal, deeply. + * If not then throw. + * + * Type parameter can be specified to ensure values under comparison have the same type. + * + * @example + * ```ts + * import { assertNotEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * + * assertNotEquals(1, 2); // Doesn't throw + * assertNotEquals(1, 1); // Throws + * ``` + * + * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_not_equals.ts} instead. + */ +export function assertNotEquals(actual: T, expected: T, msg?: string) { + asserts.assertNotEquals(actual, expected, msg); +} -export { - /** - * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert.ts} instead. - * - * Make an assertion, error will be thrown if `expr` does not have truthy value. - */ - assert, - /** - * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_equals.ts} instead. - * - * Make an assertion that `actual` and `expected` are almost equal numbers through - * a given tolerance. It can be used to take into account IEEE-754 double-precision - * floating-point representation limitations. - * If the values are not almost equal then throw. - * - * @example - * ```ts - * import { assertAlmostEquals, assertThrows } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; - * - * assertAlmostEquals(0.1, 0.2); - * - * // Using a custom tolerance value - * assertAlmostEquals(0.1 + 0.2, 0.3, 1e-16); - * assertThrows(() => assertAlmostEquals(0.1 + 0.2, 0.3, 1e-17)); - * ``` - */ - assertAlmostEquals, - /** - * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_array_includes.ts} instead. - * - * Make an assertion that `actual` includes the `expected` values. - * If not then an error will be thrown. - * - * Type parameter can be specified to ensure values under comparison have the same type. - * - * @example - * ```ts - * import { assertArrayIncludes } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; - * - * assertArrayIncludes([1, 2], [2]) - * ``` - */ - assertArrayIncludes, - /** - * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_equals.ts} instead. - * - * Make an assertion that `actual` and `expected` are equal, deeply. If not - * deeply equal, then throw. - * - * Type parameter can be specified to ensure values under comparison have the same type. - * - * @example - * ```ts - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; - * - * Deno.test("example", function (): void { - * assertEquals("world", "world"); - * assertEquals({ hello: "world" }, { hello: "world" }); - * }); - * ``` - */ - assertEquals, - /** - * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_exists.ts} instead. - * - * Make an assertion that actual is not null or undefined. - * If not then throw. - */ - assertExists, - /** - * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_false.ts} instead. - * - * Make an assertion, error will be thrown if `expr` have truthy value. - */ - assertFalse, - /** - * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_instance_of.ts} instead. - * - * Make an assertion that `obj` is an instance of `type`. - * If not then throw. - */ - assertInstanceOf, - /** @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assertion_error.ts} instead. */ - AssertionError, - /** - * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_is_error.ts} instead. - * - * Make an assertion that `error` is an `Error`. - * If not then an error will be thrown. - * An error class and a string that should be included in the - * error message can also be asserted. - */ - assertIsError, - /** - * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_match.ts} instead. - * - * Make an assertion that `actual` match RegExp `expected`. If not - * then throw. - */ - assertMatch, - /** - * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_not_equals.ts} instead. - * - * Make an assertion that `actual` and `expected` are not equal, deeply. - * If not then throw. - * - * Type parameter can be specified to ensure values under comparison have the same type. - * - * @example - * ```ts - * import { assertNotEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; - * - * assertNotEquals(1, 2) - * ``` - */ - assertNotEquals, - /** - * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_not_instance_of.ts} instead. - * - * Make an assertion that `obj` is not an instance of `type`. - * If so, then throw. - */ - assertNotInstanceOf, - /** - * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_not_match.ts} instead. - * - * Make an assertion that `actual` object is a subset of `expected` object, deeply. - * If not, then throw. - */ - assertNotMatch, - /** - * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_not_strict_equals.ts} instead. - * - * Make an assertion that `actual` and `expected` are not strictly equal. - * If the values are strictly equal then throw. - * - * ```ts - * import { assertNotStrictEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; - * - * assertNotStrictEquals(1, 1) - * ``` - */ - assertNotStrictEquals, - /** - * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_object_match.ts} instead. - * - * Make an assertion that `actual` object is a subset of `expected` object, deeply. - * If not, then throw. - */ - assertObjectMatch, - /** - * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_rejects.ts} instead. - * - * Executes a function which returns a promise, expecting it to reject. - * If it does not, then it throws. An error class and a string that should be - * included in the error message can also be asserted. - * - * @example - * ```ts - * import { assertRejects } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; - * - * Deno.test("doesThrow", async function () { - * await assertRejects(async () => { - * throw new TypeError("hello world!"); - * }, TypeError); - * await assertRejects( - * async () => { - * throw new TypeError("hello world!"); - * }, - * TypeError, - * "hello", - * ); - * }); - * - * // This test will not pass. - * Deno.test("fails", async function () { - * await assertRejects( - * async () => { - * console.log("Hello world"); - * }, - * ); - * }); - * ``` - * - * @example - * ```ts - * import { assertRejects } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; - * - * Deno.test("doesThrow", async function () { - * await assertRejects( - * async () => { - * throw new TypeError("hello world!"); - * }, - * ); - * await assertRejects( - * async () => { - * return Promise.reject(new Error()); - * }, - * ); - * }); - * - * // This test will not pass. - * Deno.test("fails", async function () { - * await assertRejects( - * async () => { - * console.log("Hello world"); - * }, - * ); - * }); - * ``` - */ - assertRejects, - /** - * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_strict_equals.ts} instead. - * - * Make an assertion that `actual` and `expected` are strictly equal. If - * not then throw. - * - * @example - * ```ts - * import { assertStrictEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; - * - * Deno.test("isStrictlyEqual", function (): void { - * const a = {}; - * const b = a; - * assertStrictEquals(a, b); - * }); - * - * // This test fails - * Deno.test("isNotStrictlyEqual", function (): void { - * const a = {}; - * const b = {}; - * assertStrictEquals(a, b); - * }); - * ``` - */ - assertStrictEquals, - /** - * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_string_includes.ts} instead. - * - * Make an assertion that actual includes expected. If not - * then throw. - */ - assertStringIncludes, - /** - * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_throws.ts} instead. - * - * Executes a function, expecting it to throw. If it does not, then it - * throws. An error class and a string that should be included in the - * error message can also be asserted. - * - * @example - * ```ts - * import { assertThrows } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; - * - * Deno.test("doesThrow", function (): void { - * assertThrows((): void => { - * throw new TypeError("hello world!"); - * }, TypeError); - * assertThrows( - * (): void => { - * throw new TypeError("hello world!"); - * }, - * TypeError, - * "hello", - * ); - * }); - * - * // This test will not pass. - * Deno.test("fails", function (): void { - * assertThrows((): void => { - * console.log("Hello world"); - * }); - * }); - * ``` - * - * @example - * ```ts - * import { assertThrows } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; - * - * Deno.test("doesThrow", function (): void { - * assertThrows((): void => { - * throw new TypeError("hello world!"); - * }); - * }); - * - * // This test will not pass. - * Deno.test("fails", function (): void { - * assertThrows((): void => { - * console.log("Hello world"); - * }); - * }); - * ``` - */ - assertThrows, - /** - * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/equal.ts} instead. - * - * Deep equality comparison used in assertions - * @param c actual value - * @param d expected value - */ - equal, - /** - * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/fail.ts} instead. - * - * Forcefully throws a failed assertion - */ - fail, - /** - * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/unimplemented.ts} instead. - * - * Use this to stub out methods that will throw when invoked. - */ - unimplemented, - /** - * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/unreachable.ts} instead. - * - * Use this to assert unreachable code. - */ - unreachable, -} from "../assert/mod.ts"; +/** + * Make an assertion that `obj` is not an instance of `type`. + * If so, then throw. + * + * @example + * ```ts + * import { assertNotInstanceOf } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * + * assertNotInstanceOf(new Date(), Number); // Doesn't throw + * assertNotInstanceOf(new Date(), Date); // Throws + * ``` + * + * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_not_instance_of.ts} instead. + */ +export function assertNotInstanceOf( + actual: A, + // deno-lint-ignore no-explicit-any + unexpectedType: new (...args: any[]) => T, + msg?: string, +): asserts actual is Exclude { + asserts.assertNotInstanceOf(actual, unexpectedType, msg); +} + +/** + * Make an assertion that `actual` not match RegExp `expected`. If match + * then throw. + * + * @example + * ```ts + * import { assertNotMatch } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * + * assertNotMatch("Denosaurus", RegExp(/Raptor/)); // Doesn't throw + * assertNotMatch("Raptor", RegExp(/Raptor/)); // Throws + * ``` + * + * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_not_match.ts} instead. + */ +export function assertNotMatch( + actual: string, + expected: RegExp, + msg?: string, +) { + asserts.assertNotMatch(actual, expected, msg); +} + +/** + * Make an assertion that `actual` and `expected` are not strictly equal. + * If the values are strictly equal then throw. + * + * @example + * ```ts + * import { assertNotStrictEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * + * assertNotStrictEquals(1, 1); // Doesn't throw + * assertNotStrictEquals(1, 2); // Throws + * ``` + * + * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_not_strict_equals.ts} instead. + */ +export function assertNotStrictEquals( + actual: T, + expected: T, + msg?: string, +) { + asserts.assertNotStrictEquals(actual, expected, msg); +} + +/** + * Make an assertion that `actual` object is a subset of `expected` object, + * deeply. If not, then throw. + * + * @example + * ```ts + * import { assertObjectMatch } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * + * assertObjectMatch({ foo: "bar" }, { foo: "bar" }); // Doesn't throw + * assertObjectMatch({ foo: "bar" }, { foo: "baz" }); // Throws + * ``` + * + * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_object_match.ts} instead. + */ +export function assertObjectMatch( + // deno-lint-ignore no-explicit-any + actual: Record, + expected: Record, + msg?: string, +) { + asserts.assertObjectMatch(actual, expected, msg); +} + +/** + * Executes a function which returns a promise, expecting it to reject. + * + * @example + * ```ts + * import { assertRejects } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * + * await assertRejects(async () => Promise.reject(new Error())); // Doesn't throw + * await assertRejects(async () => console.log("Hello world")); // Throws + * ``` + * + * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_rejects.ts} instead. + */ +export function assertRejects( + fn: () => PromiseLike, + msg?: string, +): Promise; +/** + * Executes a function which returns a promise, expecting it to reject. + * If it does not, then it throws. An error class and a string that should be + * included in the error message can also be asserted. + * + * @example + * ```ts + * import { assertRejects } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * + * await assertRejects(async () => Promise.reject(new Error()), Error); // Doesn't throw + * await assertRejects(async () => Promise.reject(new Error()), SyntaxError); // Throws + * ``` + * + * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_rejects.ts} instead. + */ +export function assertRejects( + fn: () => PromiseLike, + // deno-lint-ignore no-explicit-any + ErrorClass: new (...args: any[]) => E, + msgIncludes?: string, + msg?: string, +): Promise; +export async function assertRejects( + fn: () => PromiseLike, + errorClassOrMsg?: + // deno-lint-ignore no-explicit-any + | (new (...args: any[]) => E) + | string, + msgIncludesOrMsg?: string, + msg?: string, +): Promise { + return await asserts.assertRejects( + fn, + // deno-lint-ignore no-explicit-any + errorClassOrMsg as new (...args: any[]) => E, // Cast errorClassOrMsg to the correct type + msgIncludesOrMsg, + msg, + ); +} + +/** + * Make an assertion that `actual` and `expected` are strictly equal. If + * not then throw. + * + * @example + * ```ts + * import { assertStrictEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * + * const a = {}; + * const b = a; + * assertStrictEquals(a, b); // Doesn't throw + * + * const c = {}; + * const d = {}; + * assertStrictEquals(c, d); // Throws + * ``` + * + * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_strict_equals.ts} instead. + */ +export function assertStrictEquals( + actual: unknown, + expected: T, + msg?: string, +): asserts actual is T { + asserts.assertStrictEquals(actual, expected, msg); +} + +/** + * Make an assertion that actual includes expected. If not + * then throw. + * + * @example + * ```ts + * import { assertStringIncludes } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * + * assertStringIncludes("Hello", "ello"); // Doesn't throw + * assertStringIncludes("Hello", "world"); // Throws + * ``` + * + * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_string_includes.ts} instead. + */ +export function assertStringIncludes( + actual: string, + expected: string, + msg?: string, +) { + asserts.assertStringIncludes(actual, expected, msg); +} + +/** + * Executes a function, expecting it to throw. If it does not, then it + * throws. + * + * @example + * ```ts + * import { assertThrows } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * + * assertThrows(() => { throw new TypeError("hello world!"); }); // Doesn't throw + * assertThrows(() => console.log("hello world!")); // Throws + * ``` + * + * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_throws.ts} instead. + */ +export function assertThrows( + fn: () => unknown, + msg?: string, +): unknown; +/** + * Executes a function, expecting it to throw. If it does not, then it + * throws. An error class and a string that should be included in the + * error message can also be asserted. + * + * @example + * ```ts + * import { assertThrows } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * + * assertThrows(() => { throw new TypeError("hello world!"); }, TypeError); // Doesn't throw + * assertThrows(() => { throw new TypeError("hello world!"); }, RangeError); // Throws + * ``` + * + * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert_throws.ts} instead. + */ +export function assertThrows( + fn: () => unknown, + // deno-lint-ignore no-explicit-any + ErrorClass: new (...args: any[]) => E, + msgIncludes?: string, + msg?: string, +): E; +export function assertThrows( + fn: () => unknown, + errorClassOrMsg?: + // deno-lint-ignore no-explicit-any + | (new (...args: any[]) => E) + | string, + msgIncludesOrMsg?: string, + msg?: string, +): E | Error | unknown { + return asserts.assertThrows( + fn, + // deno-lint-ignore no-explicit-any + errorClassOrMsg as new (...args: any[]) => E, // Cast errorClassOrMsg to the correct type + msgIncludesOrMsg, + msg, + ); +} + +/** + * Make an assertion, error will be thrown if `expr` does not have truthy value. + * + * @example + * ```ts + * import { assert } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * + * assert("hello".includes("ello")); // Doesn't throw + * assert("hello".includes("world")); // Throws + * ``` + * + * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assert.ts} instead. + */ +export function assert(expr: unknown, msg = ""): asserts expr { + asserts.assert(expr, msg); +} + +/** + * Error thrown when an assertion fails. + * + * @example + * ```ts + * import { AssertionError } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * + * throw new AssertionError("Assertion failed"); + * ``` + * + * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/assertion_error.ts} instead. + */ +export class AssertionError extends Error { + /** Constructs a new instance. */ + constructor(message: string) { + super(message); + this.name = "AssertionError"; + } +} + +/** + * Deep equality comparison used in assertions + * @param c actual value + * @param d expected value + * + * @example + * ```ts + * import { equal } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * + * equal({ foo: "bar" }, { foo: "bar" }); // Returns `true` + * equal({ foo: "bar" }, { foo: "baz" }); // Returns `false + * ``` + * + * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/equal.ts} instead. + */ +export function equal(c: unknown, d: unknown): boolean { + return asserts.equal(c, d); +} + +/** + * Forcefully throws a failed assertion. + * + * @example + * ```ts + * import { fail } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * + * fail("Deliberately failed!"); // Throws + * ``` + * + * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/fail.ts} instead. + */ +export function fail(msg?: string): never { + asserts.fail(msg); +} + +/** + * Use this to stub out methods that will throw when invoked. + * + * @example + * ```ts + * import { unimplemented } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * + * unimplemented(); // Throws + * ``` + * + * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/unimplemented.ts} instead. + */ +export function unimplemented(msg?: string): never { + asserts.unimplemented(msg); +} + +/** + * Use this to assert unreachable code. + * + * @example + * ```ts + * import { unreachable } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * + * unreachable(); // Throws + * ``` + * + * @deprecated (will be removed after 1.0.0) Import from {@link https://deno.land/std/assert/unreachable.ts} instead. + */ +export function unreachable(): never { + asserts.unreachable(); +} From 2a35ba55bf2db036c72300100409e3cb055aa9b4 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Mon, 8 Jan 2024 13:36:07 +1100 Subject: [PATCH 07/12] refactor(assert): remove `void` return types (#4124) --- assert/assert_almost_equals.ts | 2 +- assert/assert_array_includes.ts | 2 +- assert/assert_equals.ts | 2 +- assert/assert_greater.ts | 2 +- assert/assert_greater_or_equal.ts | 2 +- assert/assert_less.ts | 2 +- assert/assert_less_or_equal.ts | 2 +- assert/assert_not_equals.ts | 2 +- assert/assert_not_strict_equals.ts | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/assert/assert_almost_equals.ts b/assert/assert_almost_equals.ts index 6be59720b647..6d309bd2b36e 100644 --- a/assert/assert_almost_equals.ts +++ b/assert/assert_almost_equals.ts @@ -22,7 +22,7 @@ export function assertAlmostEquals( expected: number, tolerance = 1e-7, msg?: string, -): void { +) { if (Object.is(actual, expected)) { return; } diff --git a/assert/assert_array_includes.ts b/assert/assert_array_includes.ts index b705a8bb1fba..c9f38f3d6143 100644 --- a/assert/assert_array_includes.ts +++ b/assert/assert_array_includes.ts @@ -25,7 +25,7 @@ export function assertArrayIncludes( actual: ArrayLikeArg, expected: ArrayLikeArg, msg?: string, -): void { +) { const missing: unknown[] = []; for (let i = 0; i < expected.length; i++) { let found = false; diff --git a/assert/assert_equals.ts b/assert/assert_equals.ts index 87c31e664363..b26649796f93 100644 --- a/assert/assert_equals.ts +++ b/assert/assert_equals.ts @@ -28,7 +28,7 @@ export function assertEquals( expected: T, msg?: string, options: { formatter?: (value: unknown) => string } = {}, -): void { +) { if (equal(actual, expected)) { return; } diff --git a/assert/assert_greater.ts b/assert/assert_greater.ts index c061ce74cfec..5b0846047be7 100644 --- a/assert/assert_greater.ts +++ b/assert/assert_greater.ts @@ -15,7 +15,7 @@ import { AssertionError } from "./assertion_error.ts"; * assertGreater(0, 1); // Throws * ``` */ -export function assertGreater(actual: T, expected: T, msg?: string): void { +export function assertGreater(actual: T, expected: T, msg?: string) { if (actual > expected) return; const actualString = format(actual); diff --git a/assert/assert_greater_or_equal.ts b/assert/assert_greater_or_equal.ts index dac145246a20..3a9e046c2ca3 100644 --- a/assert/assert_greater_or_equal.ts +++ b/assert/assert_greater_or_equal.ts @@ -19,7 +19,7 @@ export function assertGreaterOrEqual( actual: T, expected: T, msg?: string, -): void { +) { if (actual >= expected) return; const actualString = format(actual); diff --git a/assert/assert_less.ts b/assert/assert_less.ts index 03b8027e6540..6467c13d26b5 100644 --- a/assert/assert_less.ts +++ b/assert/assert_less.ts @@ -14,7 +14,7 @@ import { AssertionError } from "./assertion_error.ts"; * assertLess(2, 1); // Throws * ``` */ -export function assertLess(actual: T, expected: T, msg?: string): void { +export function assertLess(actual: T, expected: T, msg?: string) { if (actual < expected) return; const actualString = format(actual); diff --git a/assert/assert_less_or_equal.ts b/assert/assert_less_or_equal.ts index 4a6908d890bd..97fc642b9f93 100644 --- a/assert/assert_less_or_equal.ts +++ b/assert/assert_less_or_equal.ts @@ -19,7 +19,7 @@ export function assertLessOrEqual( actual: T, expected: T, msg?: string, -): void { +) { if (actual <= expected) return; const actualString = format(actual); diff --git a/assert/assert_not_equals.ts b/assert/assert_not_equals.ts index 976cb3579c49..a8c6b908c312 100644 --- a/assert/assert_not_equals.ts +++ b/assert/assert_not_equals.ts @@ -16,7 +16,7 @@ import { AssertionError } from "./assertion_error.ts"; * assertNotEquals(1, 1); // Throws * ``` */ -export function assertNotEquals(actual: T, expected: T, msg?: string): void { +export function assertNotEquals(actual: T, expected: T, msg?: string) { if (!equal(actual, expected)) { return; } diff --git a/assert/assert_not_strict_equals.ts b/assert/assert_not_strict_equals.ts index cea6c7d8eedc..a0dfdb9f62ed 100644 --- a/assert/assert_not_strict_equals.ts +++ b/assert/assert_not_strict_equals.ts @@ -18,7 +18,7 @@ export function assertNotStrictEquals( actual: T, expected: T, msg?: string, -): void { +) { if (!Object.is(actual, expected)) { return; } From 0a1a342fdaff5c50f71a6c202a643aed3a5ce329 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Mon, 8 Jan 2024 13:38:12 +1100 Subject: [PATCH 08/12] fix(http): punt removal version of `unstable_cookie_map.ts` (#4125) --- http/unstable_cookie_map.ts | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/http/unstable_cookie_map.ts b/http/unstable_cookie_map.ts index 811447851a42..6ca852412b1e 100644 --- a/http/unstable_cookie_map.ts +++ b/http/unstable_cookie_map.ts @@ -89,7 +89,7 @@ */ /** - * @deprecated (will be removed in 0.212.0) Use {@link https://deno.land/std/http/cookie.ts} instead. + * @deprecated (will be removed after 0.212.0) Use {@link https://deno.land/std/http/cookie.ts} instead. */ export interface CookieMapOptions { /** The {@linkcode Response} or the headers that will be used with the @@ -109,7 +109,7 @@ export interface CookieMapOptions { secure?: boolean; } -/** @deprecated (will be removed in 0.212.0) Use {@link https://deno.land/std/http/cookie.ts} instead. */ +/** @deprecated (will be removed after 0.212.0) Use {@link https://deno.land/std/http/cookie.ts} instead. */ export interface CookieMapSetDeleteOptions { /** The domain to scope the cookie for. */ domain?: string; @@ -137,18 +137,18 @@ export interface CookieMapSetDeleteOptions { * instance of {@linkcode Headers}, like {@linkcode Request} and * {@linkcode Response}. * - * @deprecated (will be removed in 0.212.0) Use {@link https://deno.land/std/http/cookie.ts} instead. + * @deprecated (will be removed after 0.212.0) Use {@link https://deno.land/std/http/cookie.ts} instead. */ export interface Headered { headers: Headers; } -/** @deprecated (will be removed in 0.212.0) Use {@link https://deno.land/std/http/cookie.ts} instead. */ +/** @deprecated (will be removed after 0.212.0) Use {@link https://deno.land/std/http/cookie.ts} instead. */ export interface Mergeable { [cookieMapHeadersInitSymbol](): [string, string][]; } -/** @deprecated (will be removed in 0.212.0) Use {@link https://deno.land/std/http/unstable_signed_cookie.ts} instead. */ +/** @deprecated (will be removed after 0.212.0) Use {@link https://deno.land/std/http/unstable_signed_cookie.ts} instead. */ export interface SecureCookieMapOptions { /** Keys which will be used to validate and sign cookies. The key ring should * implement the {@linkcode KeyRing} interface. */ @@ -172,13 +172,13 @@ export interface SecureCookieMapOptions { secure?: boolean; } -/** @deprecated (will be removed in 0.212.0) Use {@link https://deno.land/std/http/unstable_signed_cookie.ts} instead. */ +/** @deprecated (will be removed after 0.212.0) Use {@link https://deno.land/std/http/unstable_signed_cookie.ts} instead. */ export interface SecureCookieMapGetOptions { /** Overrides the flag that was set when the instance was created. */ signed?: boolean; } -/** @deprecated (will be removed in 0.212.0) Use {@link https://deno.land/std/http/unstable_signed_cookie.ts} instead. */ +/** @deprecated (will be removed after 0.212.0) Use {@link https://deno.land/std/http/unstable_signed_cookie.ts} instead. */ export interface SecureCookieMapSetDeleteOptions { /** The domain to scope the cookie for. */ domain?: string; @@ -320,7 +320,7 @@ class Cookie implements CookieAttributes { * `[string | string][]` from an instance to generate the final set of * headers. * - * @deprecated (will be removed in 0.212.0) Use {@link https://deno.land/std/http/cookie.ts} instead. + * @deprecated (will be removed after 0.212.0) Use {@link https://deno.land/std/http/cookie.ts} instead. */ export const cookieMapHeadersInitSymbol: unique symbol = Symbol.for( "Deno.std.cookieMap.headersInit", @@ -340,7 +340,7 @@ function isMergeable(value: unknown): value is Mergeable { * will not ensure that there are no other `Set-Cookie` headers from other * sources, it will simply append the various headers together. * - * @deprecated (will be removed in 0.212.0) Use {@link https://deno.land/std/http/cookie.ts} instead. + * @deprecated (will be removed after 0.212.0) Use {@link https://deno.land/std/http/cookie.ts} instead. */ export function mergeHeaders( ...sources: (Headered | HeadersInit | Mergeable)[] @@ -451,7 +451,7 @@ abstract class CookieMapBase implements Mergeable { * function can be used to generate a final set of headers for sending in the * response. * - * @deprecated (will be removed in 0.212.0) Use {@link https://deno.land/std/http/cookie.ts} instead. + * @deprecated (will be removed after 0.212.0) Use {@link https://deno.land/std/http/cookie.ts} instead. */ export class CookieMap extends CookieMapBase { /** Contains the number of valid cookies in the request headers. */ @@ -577,7 +577,7 @@ export class CookieMap extends CookieMapBase { /** * Types of data that can be signed cryptographically. * - * @deprecated (will be removed in 0.212.0) Use {@link https://deno.land/std/http/unstable_signed_cookie.ts} instead. + * @deprecated (will be removed after 0.212.0) Use {@link https://deno.land/std/http/unstable_signed_cookie.ts} instead. */ export type Data = string | number[] | ArrayBuffer | Uint8Array; @@ -585,7 +585,7 @@ export type Data = string | number[] | ArrayBuffer | Uint8Array; * An interface which describes the methods that {@linkcode SecureCookieMap} * uses to sign and verify cookies. * - * @deprecated (will be removed in 0.212.0) Use {@link https://deno.land/std/http/unstable_signed_cookie.ts} instead. + * @deprecated (will be removed after 0.212.0) Use {@link https://deno.land/std/http/unstable_signed_cookie.ts} instead. */ export interface KeyRing { /** Given a set of data and a digest, return the key index of the key used @@ -616,7 +616,7 @@ export interface KeyRing { * {@linkcode KeyRing} interface. While it is optional, if you don't plan to use * keys, you might want to consider using just the {@linkcode CookieMap}. * - * @deprecated (will be removed in 0.212.0) Use {@link https://deno.land/std/http/unstable_signed_cookie.ts} instead. + * @deprecated (will be removed after 0.212.0) Use {@link https://deno.land/std/http/unstable_signed_cookie.ts} instead. */ export class SecureCookieMap extends CookieMapBase { #keyRing?: KeyRing; From c8c07e6b84aef0f3f5056e31bb90b9f16a632f3b Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Mon, 8 Jan 2024 13:47:54 +1100 Subject: [PATCH 09/12] chore: ignore `/docs` in license checker tool (#4123) --- _tools/check_licence.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/_tools/check_licence.ts b/_tools/check_licence.ts index 7c7721ae2f41..afe618327cba 100644 --- a/_tools/check_licence.ts +++ b/_tools/check_licence.ts @@ -10,6 +10,7 @@ const EXCLUDED_DIRS = [ "**/crypto/_wasm/target", "**/crypto/_wasm/lib", "**/.git", + "**/docs/**", ]; const ROOT = new URL("../", import.meta.url); From 5ce897d044c89d4aad8b33e3eac65f16075fc648 Mon Sep 17 00:00:00 2001 From: Tim Reichen Date: Mon, 8 Jan 2024 03:55:23 +0100 Subject: [PATCH 10/12] deprecation(semver): rename `rangeFormat()` to `formatRange()` (#4090) Co-authored-by: Asher Gomez --- semver/format_range.ts | 14 +++++++ semver/format_range_test.ts | 73 +++++++++++++++++++++++++++++++++++++ semver/range_format.ts | 10 +++-- semver/range_test.ts | 71 +----------------------------------- 4 files changed, 94 insertions(+), 74 deletions(-) create mode 100644 semver/format_range.ts create mode 100644 semver/format_range_test.ts diff --git a/semver/format_range.ts b/semver/format_range.ts new file mode 100644 index 000000000000..ac2fb98d02c2 --- /dev/null +++ b/semver/format_range.ts @@ -0,0 +1,14 @@ +// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +import type { SemVerRange } from "./types.ts"; +import { comparatorFormat } from "./comparator_format.ts"; + +/** + * Formats the range into a string + * @example >=0.0.0 || <1.0.0 + * @param range The range to format + * @returns A string representation of the range + */ +export function formatRange(range: SemVerRange): string { + return range.ranges.map((c) => c.map((c) => comparatorFormat(c)).join(" ")) + .join("||"); +} diff --git a/semver/format_range_test.ts b/semver/format_range_test.ts new file mode 100644 index 000000000000..f6757e8f9d3a --- /dev/null +++ b/semver/format_range_test.ts @@ -0,0 +1,73 @@ +// Copyright Isaac Z. Schlueter and Contributors. All rights reserved. ISC license. +// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +import { assertEquals } from "../assert/mod.ts"; +import { formatRange } from "./format_range.ts"; +import { parseRange } from "./parse_range.ts"; + +Deno.test({ + name: "formatRange()", + fn: async (t) => { + const versions: [string, string][] = [ + ["1.0.0 - 2.0.0", ">=1.0.0 <=2.0.0"], + ["1.0.0", "1.0.0"], + [">=*", "*"], + ["", "*"], + ["*", "*"], + [">=1.0.0", ">=1.0.0"], + [">1.0.0", ">1.0.0"], + ["<=2.0.0", "<=2.0.0"], + ["1", ">=1.0.0 <2.0.0"], + ["<=2.0.0", "<=2.0.0"], + ["<=2.0.0", "<=2.0.0"], + ["<2.0.0", "<2.0.0"], + ["<2.0.0", "<2.0.0"], + [">=0.1.97", ">=0.1.97"], + [">=0.1.97", ">=0.1.97"], + ["0.1.20 || 1.2.4", "0.1.20||1.2.4"], + [">=0.2.3 || <0.0.1", ">=0.2.3||<0.0.1"], + [">=0.2.3 || <0.0.1", ">=0.2.3||<0.0.1"], + [">=0.2.3 || <0.0.1", ">=0.2.3||<0.0.1"], + ["||", "*||*"], + ["2.x.x", ">=2.0.0 <3.0.0"], + ["1.2.x", ">=1.2.0 <1.3.0"], + ["1.2.x || 2.x", ">=1.2.0 <1.3.0||>=2.0.0 <3.0.0"], + ["1.2.x || 2.x", ">=1.2.0 <1.3.0||>=2.0.0 <3.0.0"], + ["x", "*"], + ["2.*.*", ">=2.0.0 <3.0.0"], + ["1.2.*", ">=1.2.0 <1.3.0"], + ["1.2.* || 2.*", ">=1.2.0 <1.3.0||>=2.0.0 <3.0.0"], + ["2", ">=2.0.0 <3.0.0"], + ["2.3", ">=2.3.0 <2.4.0"], + ["~2.4", ">=2.4.0 <2.5.0"], + ["~2.4", ">=2.4.0 <2.5.0"], + ["~>3.2.1", ">=3.2.1 <3.3.0"], + ["~1", ">=1.0.0 <2.0.0"], + ["~>1", ">=1.0.0 <2.0.0"], + ["~1.0", ">=1.0.0 <1.1.0"], + ["^0", ">=0.0.0 <1.0.0"], + ["^0.1", ">=0.1.0 <0.2.0"], + ["^1.0", ">=1.0.0 <2.0.0"], + ["^1.2", ">=1.2.0 <2.0.0"], + ["^0.0.1", ">=0.0.1 <0.0.2"], + ["^0.0.1-beta", ">=0.0.1-beta <0.0.2"], + ["^0.1.2", ">=0.1.2 <0.2.0"], + ["^1.2.3", ">=1.2.3 <2.0.0"], + ["^1.2.3-beta.4", ">=1.2.3-beta.4 <2.0.0"], + ["<1", "<1.0.0"], + [">=1", ">=1.0.0"], + ["<1.2", "<1.2.0"], + ["1", ">=1.0.0 <2.0.0"], + ]; + + for (const [r, expected] of versions) { + await t.step({ + name: `${r} -> ${expected}`, + fn: () => { + const range = parseRange(r); + const actual = formatRange(range); + assertEquals(actual, expected); + }, + }); + } + }, +}); diff --git a/semver/range_format.ts b/semver/range_format.ts index 9dabafd67ce4..73c7e2bff1ea 100644 --- a/semver/range_format.ts +++ b/semver/range_format.ts @@ -1,14 +1,16 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -import type { SemVerRange } from "./types.ts"; -import { comparatorFormat } from "./comparator_format.ts"; + +import { formatRange } from "./format_range.ts"; +import { SemVerRange } from "./types.ts"; /** * Formats the range into a string * @example >=0.0.0 || <1.0.0 * @param range The range to format * @returns A string representation of the range + * + * @deprecated (will be removed after 0.213.0) Use {@linkcode formatRange} instead. */ export function rangeFormat(range: SemVerRange): string { - return range.ranges.map((c) => c.map((c) => comparatorFormat(c)).join(" ")) - .join("||"); + return formatRange(range); } diff --git a/semver/range_test.ts b/semver/range_test.ts index 59029572e0c9..eb13f708b498 100644 --- a/semver/range_test.ts +++ b/semver/range_test.ts @@ -1,7 +1,6 @@ // Copyright Isaac Z. Schlueter and Contributors. All rights reserved. ISC license. // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals } from "../assert/mod.ts"; -import { rangeFormat } from "./range_format.ts"; +import { assert } from "../assert/mod.ts"; import { parse } from "./parse.ts"; import { parseRange } from "./parse_range.ts"; import { testRange } from "./test_range.ts"; @@ -217,71 +216,3 @@ Deno.test("negativeUnlockedPrereleaseRange", function () { assert(!found, `${v} satisfied by ${r} unexpectedly`); } }); - -Deno.test({ - name: "validRange", - fn: async (t) => { - const versions: [string, string][] = [ - ["1.0.0 - 2.0.0", ">=1.0.0 <=2.0.0"], - ["1.0.0", "1.0.0"], - [">=*", "*"], - ["", "*"], - ["*", "*"], - [">=1.0.0", ">=1.0.0"], - [">1.0.0", ">1.0.0"], - ["<=2.0.0", "<=2.0.0"], - ["1", ">=1.0.0 <2.0.0"], - ["<=2.0.0", "<=2.0.0"], - ["<=2.0.0", "<=2.0.0"], - ["<2.0.0", "<2.0.0"], - ["<2.0.0", "<2.0.0"], - [">=0.1.97", ">=0.1.97"], - [">=0.1.97", ">=0.1.97"], - ["0.1.20 || 1.2.4", "0.1.20||1.2.4"], - [">=0.2.3 || <0.0.1", ">=0.2.3||<0.0.1"], - [">=0.2.3 || <0.0.1", ">=0.2.3||<0.0.1"], - [">=0.2.3 || <0.0.1", ">=0.2.3||<0.0.1"], - ["||", "*||*"], - ["2.x.x", ">=2.0.0 <3.0.0"], - ["1.2.x", ">=1.2.0 <1.3.0"], - ["1.2.x || 2.x", ">=1.2.0 <1.3.0||>=2.0.0 <3.0.0"], - ["1.2.x || 2.x", ">=1.2.0 <1.3.0||>=2.0.0 <3.0.0"], - ["x", "*"], - ["2.*.*", ">=2.0.0 <3.0.0"], - ["1.2.*", ">=1.2.0 <1.3.0"], - ["1.2.* || 2.*", ">=1.2.0 <1.3.0||>=2.0.0 <3.0.0"], - ["2", ">=2.0.0 <3.0.0"], - ["2.3", ">=2.3.0 <2.4.0"], - ["~2.4", ">=2.4.0 <2.5.0"], - ["~2.4", ">=2.4.0 <2.5.0"], - ["~>3.2.1", ">=3.2.1 <3.3.0"], - ["~1", ">=1.0.0 <2.0.0"], - ["~>1", ">=1.0.0 <2.0.0"], - ["~1.0", ">=1.0.0 <1.1.0"], - ["^0", ">=0.0.0 <1.0.0"], - ["^0.1", ">=0.1.0 <0.2.0"], - ["^1.0", ">=1.0.0 <2.0.0"], - ["^1.2", ">=1.2.0 <2.0.0"], - ["^0.0.1", ">=0.0.1 <0.0.2"], - ["^0.0.1-beta", ">=0.0.1-beta <0.0.2"], - ["^0.1.2", ">=0.1.2 <0.2.0"], - ["^1.2.3", ">=1.2.3 <2.0.0"], - ["^1.2.3-beta.4", ">=1.2.3-beta.4 <2.0.0"], - ["<1", "<1.0.0"], - [">=1", ">=1.0.0"], - ["<1.2", "<1.2.0"], - ["1", ">=1.0.0 <2.0.0"], - ]; - - for (const [r, expected] of versions) { - await t.step({ - name: `${r} -> ${expected}`, - fn: () => { - const range = parseRange(r); - const actual = rangeFormat(range); - assertEquals(actual, expected); - }, - }); - } - }, -}); From 69a23ed9d62ef80190e218dd3065038328bf7212 Mon Sep 17 00:00:00 2001 From: Simon Holloway Date: Mon, 8 Jan 2024 04:58:59 +0000 Subject: [PATCH 11/12] refactor(archive): prepare for `noUncheckedIndexedAccess` (#4110) * refactor(archive): prepare for noUncheckedIndexedAccess * adjust test to handle new TarHeader requirements --- archive/_common.ts | 6 ++++-- archive/untar.ts | 13 +++++++------ archive/untar_test.ts | 17 ++++++++++++++++- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/archive/_common.ts b/archive/_common.ts index f383bb9a03e6..0f6c427b093b 100644 --- a/archive/_common.ts +++ b/archive/_common.ts @@ -71,7 +71,7 @@ struct posix_header { // byte offset }; */ -export const ustarStructure: Array<{ field: string; length: number }> = [ +export const ustarStructure = [ { field: "fileName", length: 100, @@ -136,7 +136,9 @@ export const ustarStructure: Array<{ field: string; length: number }> = [ field: "padding", length: 12, }, -]; +] as const; + +export type UstarFields = (typeof ustarStructure)[number]["field"]; export async function readBlock( reader: Reader, diff --git a/archive/untar.ts b/archive/untar.ts index bf9feec71a02..0a597f9cd2dc 100644 --- a/archive/untar.ts +++ b/archive/untar.ts @@ -34,6 +34,7 @@ import { HEADER_LENGTH, readBlock, type TarMeta, + UstarFields, ustarStructure, } from "./_common.ts"; import { readAll } from "../streams/read_all.ts"; @@ -47,9 +48,9 @@ export interface TarMetaWithLinkName extends TarMeta { linkName?: string; } -export interface TarHeader { - [key: string]: Uint8Array; -} +export type TarHeader = { + [key in UstarFields]: Uint8Array; +}; // https://pubs.opengroup.org/onlinepubs/9699919799/utilities/pax.html#tag_20_92_13_06 // eight checksum bytes taken to be ascii spaces (decimal value 32) @@ -69,8 +70,8 @@ function trim(buffer: Uint8Array): Uint8Array { * Parse file header in a tar archive * @param length */ -function parseHeader(buffer: Uint8Array): { [key: string]: Uint8Array } { - const data: { [key: string]: Uint8Array } = {}; +function parseHeader(buffer: Uint8Array): TarHeader { + const data = {} as TarHeader; let offset = 0; ustarStructure.forEach(function (value) { const arr = buffer.subarray(offset, offset + value.length); @@ -222,7 +223,7 @@ export class Untar { // Ignore checksum header continue; } - sum += header[i]; + sum += header[i]!; } return sum; } diff --git a/archive/untar_test.ts b/archive/untar_test.ts index 1f3405dd1010..9f66e809223c 100644 --- a/archive/untar_test.ts +++ b/archive/untar_test.ts @@ -332,7 +332,22 @@ Deno.test({ // Test TarEntry type const bufSizes = [1, 53, 256, 511]; const header: TarHeader = { - test: new Uint8Array(bufSizes), + fileName: new Uint8Array(bufSizes), + fileMode: new Uint8Array(bufSizes), + uid: new Uint8Array(bufSizes), + gid: new Uint8Array(bufSizes), + fileSize: new Uint8Array(bufSizes), + mtime: new Uint8Array(bufSizes), + checksum: new Uint8Array(bufSizes), + type: new Uint8Array(bufSizes), + linkName: new Uint8Array(bufSizes), + ustar: new Uint8Array(bufSizes), + owner: new Uint8Array(bufSizes), + group: new Uint8Array(bufSizes), + majorNumber: new Uint8Array(bufSizes), + minorNumber: new Uint8Array(bufSizes), + fileNamePrefix: new Uint8Array(bufSizes), + padding: new Uint8Array(bufSizes), }; const content = new TextEncoder().encode("hello tar world!"); const reader = new Buffer(content); From 5eb47003cc1eb6f518824ce87c21fddcadff0922 Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 9 Jan 2024 10:37:06 +0100 Subject: [PATCH 12/12] revert WARNING --- log/handlers.ts | 2 +- log/handlers_test.ts | 40 ++++++++++++++++++++-------------------- log/levels.ts | 4 ++-- log/logger.ts | 2 +- log/logger_test.ts | 16 ++++++++-------- log/mod.ts | 4 ++-- log/mod_test.ts | 6 +++--- log/test.ts | 2 +- 8 files changed, 38 insertions(+), 38 deletions(-) diff --git a/log/handlers.ts b/log/handlers.ts index 2ec4b8b1095e..955d438629c5 100644 --- a/log/handlers.ts +++ b/log/handlers.ts @@ -88,7 +88,7 @@ export class ConsoleHandler extends BaseHandler { case LogLevels.INFO: msg = blue(msg); break; - case LogLevels.WARN: + case LogLevels.WARNING: msg = yellow(msg); break; case LogLevels.ERROR: diff --git a/log/handlers_test.ts b/log/handlers_test.ts index 0245d87f9ead..1f6745121ecf 100644 --- a/log/handlers_test.ts +++ b/log/handlers_test.ts @@ -33,7 +33,7 @@ Deno.test("simpleHandler", function () { [ "DEBUG debug-test", "INFO info-test", - "WARN warn-test", + "WARNING warning-test", "ERROR error-test", "CRITICAL critical-test", ], @@ -42,14 +42,14 @@ Deno.test("simpleHandler", function () { LogLevels.INFO, [ "INFO info-test", - "WARN warn-test", + "WARNING warning-test", "ERROR error-test", "CRITICAL critical-test", ], ], [ - LogLevels.WARN, - ["WARN warn-test", "ERROR error-test", "CRITICAL critical-test"], + LogLevels.WARNING, + ["WARNING warning-test", "ERROR error-test", "CRITICAL critical-test"], ], [LogLevels.ERROR, ["ERROR error-test", "CRITICAL critical-test"]], [LogLevels.CRITICAL, ["CRITICAL critical-test"]], @@ -164,7 +164,7 @@ Deno.test({ } } - const testFileHandler = new TestFileHandler("WARN", { + const testFileHandler = new TestFileHandler("WARNING", { filename: LOG_FILE, mode: "w", }); @@ -175,7 +175,7 @@ Deno.test({ new LogRecord({ msg: "The starry heavens above me and the moral law within me.", args: [], - level: LogLevels.WARN, + level: LogLevels.WARNING, loggerName: "default", }), ); @@ -188,7 +188,7 @@ Deno.test({ Deno.test({ name: "FileHandler with mode 'w' will wipe clean existing log file", async fn() { - const fileHandler = new FileHandler("WARN", { + const fileHandler = new FileHandler("WARNING", { filename: LOG_FILE, mode: "w", }); @@ -198,7 +198,7 @@ Deno.test({ new LogRecord({ msg: "Hello World", args: [], - level: LogLevels.WARN, + level: LogLevels.WARNING, loggerName: "default", }), ); @@ -210,7 +210,7 @@ Deno.test({ new LogRecord({ msg: "Hello World", args: [], - level: LogLevels.WARN, + level: LogLevels.WARNING, loggerName: "default", }), ); @@ -225,7 +225,7 @@ Deno.test({ Deno.test({ name: "FileHandler with mode 'x' will throw if log file already exists", fn() { - const fileHandler = new FileHandler("WARN", { + const fileHandler = new FileHandler("WARNING", { filename: LOG_FILE, mode: "x", }); @@ -259,7 +259,7 @@ Deno.test({ new TextEncoder().encode("hello world"), ); - const fileHandler = new RotatingFileHandler("WARN", { + const fileHandler = new RotatingFileHandler("WARNING", { filename: LOG_FILE, maxBytes: 50, maxBackupCount: 3, @@ -285,7 +285,7 @@ Deno.test({ LOG_FILE + ".3", new TextEncoder().encode("hello world"), ); - const fileHandler = new RotatingFileHandler("WARN", { + const fileHandler = new RotatingFileHandler("WARNING", { filename: LOG_FILE, maxBytes: 50, maxBackupCount: 3, @@ -308,7 +308,7 @@ Deno.test({ Deno.test({ name: "RotatingFileHandler with first rollover, monitor step by step", async fn() { - const fileHandler = new RotatingFileHandler("WARN", { + const fileHandler = new RotatingFileHandler("WARNING", { filename: LOG_FILE, maxBytes: 25, maxBackupCount: 3, @@ -358,7 +358,7 @@ Deno.test({ Deno.test({ name: "RotatingFileHandler with first rollover, check all at once", async fn() { - const fileHandler = new RotatingFileHandler("WARN", { + const fileHandler = new RotatingFileHandler("WARNING", { filename: LOG_FILE, maxBytes: 25, maxBackupCount: 3, @@ -418,7 +418,7 @@ Deno.test({ new TextEncoder().encode("original log.3 file"), ); - const fileHandler = new RotatingFileHandler("WARN", { + const fileHandler = new RotatingFileHandler("WARNING", { filename: LOG_FILE, maxBytes: 2, maxBackupCount: 3, @@ -463,7 +463,7 @@ Deno.test({ fn() { assertThrows( () => { - const fileHandler = new RotatingFileHandler("WARN", { + const fileHandler = new RotatingFileHandler("WARNING", { filename: LOG_FILE, maxBytes: 0, maxBackupCount: 3, @@ -482,7 +482,7 @@ Deno.test({ fn() { assertThrows( () => { - const fileHandler = new RotatingFileHandler("WARN", { + const fileHandler = new RotatingFileHandler("WARNING", { filename: LOG_FILE, maxBytes: 50, maxBackupCount: 0, @@ -499,7 +499,7 @@ Deno.test({ Deno.test({ name: "Window unload flushes buffer", async fn() { - const fileHandler = new FileHandler("WARN", { + const fileHandler = new FileHandler("WARNING", { filename: LOG_FILE, mode: "w", }); @@ -525,7 +525,7 @@ Deno.test({ Deno.test({ name: "RotatingFileHandler: rotate on byte length, not msg length", async fn() { - const fileHandler = new RotatingFileHandler("WARN", { + const fileHandler = new RotatingFileHandler("WARNING", { filename: LOG_FILE, maxBytes: 7, maxBackupCount: 1, @@ -559,7 +559,7 @@ Deno.test({ Deno.test({ name: "FileHandler: Critical logs trigger immediate flush", async fn() { - const fileHandler = new FileHandler("WARN", { + const fileHandler = new FileHandler("WARNING", { filename: LOG_FILE, mode: "w", }); diff --git a/log/levels.ts b/log/levels.ts index cfeed4674189..ddd0e5d4a24f 100644 --- a/log/levels.ts +++ b/log/levels.ts @@ -9,7 +9,7 @@ export const LogLevels = { NOTSET: 0, DEBUG: 10, INFO: 20, - WARN: 30, + WARNING: 30, ERROR: 40, CRITICAL: 50, } as const; @@ -29,7 +29,7 @@ const byLevel: Record = { [LogLevels.NOTSET]: "NOTSET", [LogLevels.DEBUG]: "DEBUG", [LogLevels.INFO]: "INFO", - [LogLevels.WARN]: "WARN", + [LogLevels.WARNING]: "WARNING", [LogLevels.ERROR]: "ERROR", [LogLevels.CRITICAL]: "CRITICAL", }; diff --git a/log/logger.ts b/log/logger.ts index 623bcc8fef5f..47c888527eaf 100644 --- a/log/logger.ts +++ b/log/logger.ts @@ -184,7 +184,7 @@ export class Logger { msg: (T extends GenericFunction ? never : T) | (() => T), ...args: unknown[] ): T | undefined { - return this.#_log(LogLevels.WARN, msg, ...args); + return this.#_log(LogLevels.WARNING, msg, ...args); } error(msg: () => T, ...args: unknown[]): T | undefined; diff --git a/log/logger_test.ts b/log/logger_test.ts index 67acacc74db9..8027f48d879d 100644 --- a/log/logger_test.ts +++ b/log/logger_test.ts @@ -87,7 +87,7 @@ Deno.test("logFunctions", function () { assertEquals(handler.messages, [ "DEBUG foo", "INFO bar", - "WARN baz", + "WARNING baz", "ERROR boo", "CRITICAL doo", ]); @@ -96,14 +96,14 @@ Deno.test("logFunctions", function () { assertEquals(handler.messages, [ "INFO bar", - "WARN baz", + "WARNING baz", "ERROR boo", "CRITICAL doo", ]); - handler = doLog("WARN"); + handler = doLog("WARNING"); - assertEquals(handler.messages, ["WARN baz", "ERROR boo", "CRITICAL doo"]); + assertEquals(handler.messages, ["WARNING baz", "ERROR boo", "CRITICAL doo"]); handler = doLog("ERROR"); @@ -181,8 +181,8 @@ Deno.test( assertEquals(data5, 3); const data6: number = logger.warn(3, 1); assertEquals(data6, 3); - assertEquals(handler.messages[4], "WARN 3"); - assertEquals(handler.messages[5], "WARN 3"); + assertEquals(handler.messages[4], "WARNING 3"); + assertEquals(handler.messages[5], "WARNING 3"); // bigint const data7: bigint = logger.error(5n); @@ -221,8 +221,8 @@ Deno.test( assertEquals(data15, "abc"); const data16: string | undefined = logger.warn(fn, 1); assertEquals(data16, "abc"); - assertEquals(handler.messages[14], "WARN abc"); - assertEquals(handler.messages[15], "WARN abc"); + assertEquals(handler.messages[14], "WARNING abc"); + assertEquals(handler.messages[15], "WARNING abc"); // object const data17: { payload: string; other: number } = logger.error({ diff --git a/log/mod.ts b/log/mod.ts index 6042cb40671b..a00ac0fb70f5 100644 --- a/log/mod.ts +++ b/log/mod.ts @@ -148,7 +148,7 @@ * handlers: { * console: new log.handlers.ConsoleHandler("DEBUG"), * - * file: new log.handlers.FileHandler("WARN", { + * file: new log.handlers.FileHandler("WARNING", { * filename: "./log.txt", * // you can change format of output message using any keys in `LogRecord`. * formatter: (record) => `${record.levelName} ${record.msg}`, @@ -173,7 +173,7 @@ * * // get default logger. * logger = log.getLogger(); - * logger.debug("fizz"); // logs to `console`, because `file` handler requires "WARN" level. + * logger.debug("fizz"); // logs to `console`, because `file` handler requires "WARNING" level. * logger.warn(41256); // logs to both `console` and `file` handlers. * * // get custom logger diff --git a/log/mod_test.ts b/log/mod_test.ts index 8f35ab7f64fc..b0e36ef7a96d 100644 --- a/log/mod_test.ts +++ b/log/mod_test.ts @@ -122,9 +122,9 @@ Deno.test({ assertEquals(testHandler.messages[2], "CRITICAL critical"); testHandler.messages = []; - logger.level = LogLevels.WARN; - assertEquals(logger.levelName, "WARN"); - assertEquals(logger.level, LogLevels.WARN); + logger.level = LogLevels.WARNING; + assertEquals(logger.levelName, "WARNING"); + assertEquals(logger.level, LogLevels.WARNING); logger.debug("debug2"); logger.error("error2"); diff --git a/log/test.ts b/log/test.ts index 516959d610f7..9e6d2bdcc740 100644 --- a/log/test.ts +++ b/log/test.ts @@ -23,7 +23,7 @@ Deno.test("defaultHandlers", async function () { } = { DEBUG: log.debug, INFO: log.info, - WARN: log.warn, + WARNING: log.warn, ERROR: log.error, CRITICAL: log.critical, };