From 3f0cf9619fce71a8898c495501df4bdb0e07e735 Mon Sep 17 00:00:00 2001 From: Leo K Date: Thu, 5 Aug 2021 13:08:58 +0200 Subject: [PATCH] refactor(cli/tests): remove unnecessary void return types (#11577) --- cli/tests/004_set_timeout.ts | 4 +- cli/tests/012_async.ts | 4 +- cli/tests/013_dynamic_import.ts | 2 +- cli/tests/014_duplicate_import.ts | 2 +- cli/tests/016_double_await.ts | 2 +- cli/tests/018_async_catch.ts | 4 +- cli/tests/025_hrtime.ts | 2 +- cli/tests/028_args.ts | 2 +- cli/tests/034_onload/imported.ts | 2 +- cli/tests/034_onload/main.ts | 6 +- cli/tests/034_onload/nest_imported.ts | 2 +- cli/tests/045_proxy_test.ts | 14 +- cli/tests/055_info_file_json.out | 8 +- cli/tests/076_info_json_deps_order.out | 18 +- cli/tests/bundle/file_tests-fixture11.ts | 2 +- cli/tests/bundle_im.ts | 4 +- cli/tests/cat.ts | 2 +- cli/tests/complex_permissions_test.ts | 10 +- cli/tests/echo.ts | 2 +- cli/tests/echo_server.ts | 2 +- cli/tests/error_001.ts | 2 +- cli/tests/error_002.ts | 2 +- cli/tests/error_005_missing_dynamic_import.ts | 2 +- .../error_012_bad_dynamic_import_specifier.ts | 2 +- cli/tests/error_023_stack_async.ts | 2 +- cli/tests/info_recursive_imports_test.ts | 2 +- cli/tests/js_import_detect.ts | 2 +- cli/tests/lock_check_err.json | 2 +- cli/tests/lock_check_err_with_bundle.json | 4 +- cli/tests/lock_check_ok.json | 2 +- cli/tests/lock_dynamic_imports.json | 6 +- cli/tests/permission_test.ts | 10 +- cli/tests/recursive_imports/A.ts | 2 +- cli/tests/recursive_imports/B.ts | 2 +- cli/tests/recursive_imports/C.ts | 2 +- cli/tests/recursive_imports/common.ts | 2 +- cli/tests/subdir/circular1.ts | 2 +- cli/tests/subdir/circular2.ts | 2 +- cli/tests/subdir/mod1.ts | 4 +- cli/tests/subdir/print_hello.ts | 2 +- cli/tests/subdir/subdir2/dynamic_import.ts | 2 +- cli/tests/subdir/subdir2/mod2.ts | 2 +- cli/tests/ts_decorators_bundle.ts | 2 +- cli/tests/type_definitions_for_export.ts | 2 +- cli/tests/unit/abort_controller_test.ts | 4 +- cli/tests/unit/blob_test.ts | 22 +-- cli/tests/unit/body_test.ts | 12 +- cli/tests/unit/buffer_test.ts | 52 +++--- cli/tests/unit/build_test.ts | 2 +- cli/tests/unit/chmod_test.ts | 24 ++- cli/tests/unit/chown_test.ts | 20 +-- cli/tests/unit/console_test.ts | 160 +++++++++--------- cli/tests/unit/copy_file_test.ts | 28 +-- cli/tests/unit/custom_event_test.ts | 4 +- cli/tests/unit/dir_test.ts | 10 +- cli/tests/unit/dom_exception_test.ts | 2 +- cli/tests/unit/error_stack_test.ts | 8 +- cli/tests/unit/event_target_test.ts | 46 ++--- cli/tests/unit/event_test.ts | 20 +-- cli/tests/unit/fetch_test.ts | 142 +++++++--------- cli/tests/unit/file_test.ts | 50 +++--- cli/tests/unit/filereader_test.ts | 46 ++--- cli/tests/unit/files_test.ts | 80 ++++----- cli/tests/unit/fs_events_test.ts | 6 +- cli/tests/unit/get_random_values_test.ts | 16 +- cli/tests/unit/globals_test.ts | 44 ++--- cli/tests/unit/headers_test.ts | 58 +++---- cli/tests/unit/http_test.ts | 2 +- cli/tests/unit/internals_test.ts | 2 +- cli/tests/unit/link_test.ts | 12 +- cli/tests/unit/make_temp_test.ts | 20 +-- cli/tests/unit/metrics_test.ts | 8 +- cli/tests/unit/mkdir_test.ts | 54 +++--- cli/tests/unit/navigator_test.ts | 2 +- cli/tests/unit/net_test.ts | 66 ++++---- cli/tests/unit/opcall_test.ts | 4 +- cli/tests/unit/os_test.ts | 38 ++--- cli/tests/unit/path_from_url_test.ts | 4 +- cli/tests/unit/performance_test.ts | 12 +- cli/tests/unit/permissions_test.ts | 4 +- cli/tests/unit/process_test.ts | 36 ++-- cli/tests/unit/progressevent_test.ts | 2 +- cli/tests/unit/read_dir_test.ts | 26 ++- cli/tests/unit/read_file_test.ts | 30 ++-- cli/tests/unit/read_link_test.ts | 16 +- cli/tests/unit/read_text_file_test.ts | 24 ++- cli/tests/unit/real_path_test.ts | 26 ++- cli/tests/unit/remove_test.ts | 34 ++-- cli/tests/unit/rename_test.ts | 42 ++--- cli/tests/unit/request_test.ts | 12 +- cli/tests/unit/resources_test.ts | 12 +- cli/tests/unit/response_test.ts | 2 +- cli/tests/unit/signal_test.ts | 12 +- cli/tests/unit/stat_test.ts | 42 ++--- cli/tests/unit/symlink_test.ts | 10 +- cli/tests/unit/sync_test.ts | 8 +- cli/tests/unit/testing_test.ts | 6 +- cli/tests/unit/text_encoding_test.ts | 44 ++--- cli/tests/unit/timers_test.ts | 84 +++++---- cli/tests/unit/tls_test.ts | 74 ++++---- cli/tests/unit/truncate_test.ts | 14 +- cli/tests/unit/tty_test.ts | 8 +- cli/tests/unit/umask_test.ts | 2 +- cli/tests/unit/url_search_params_test.ts | 72 ++++---- cli/tests/unit/url_test.ts | 44 ++--- cli/tests/unit/utime_test.ts | 32 ++-- cli/tests/unit/version_test.ts | 2 +- cli/tests/unit/wasm_test.ts | 8 +- cli/tests/unit/write_file_test.ts | 28 +-- cli/tests/unit/write_text_file_test.ts | 28 +-- cli/tests/websocket_test.ts | 118 ++++++------- cli/tests/workers/bench_large_message.ts | 2 +- cli/tests/workers/bench_round_robin.ts | 10 +- cli/tests/workers/bench_startup.ts | 10 +- cli/tests/workers/bench_worker.ts | 2 +- cli/tests/workers/deno_worker.ts | 2 +- cli/tests/workers/test.ts | 98 +++++------ cli/tests/workers/test_worker.ts | 2 +- cli/tests/workers/worker_globals.ts | 2 +- cli/tests/workers/worker_location.ts | 2 +- .../workers/worker_with_top_level_await.ts | 2 +- 121 files changed, 1095 insertions(+), 1177 deletions(-) diff --git a/cli/tests/004_set_timeout.ts b/cli/tests/004_set_timeout.ts index 58f899ee3b..214b25086c 100644 --- a/cli/tests/004_set_timeout.ts +++ b/cli/tests/004_set_timeout.ts @@ -1,10 +1,10 @@ -setTimeout((): void => { +setTimeout(() => { console.log("World"); }, 10); console.log("Hello"); -const id = setTimeout((): void => { +const id = setTimeout(() => { console.log("Not printed"); }, 10000); diff --git a/cli/tests/012_async.ts b/cli/tests/012_async.ts index 773272ca19..536197b686 100644 --- a/cli/tests/012_async.ts +++ b/cli/tests/012_async.ts @@ -1,6 +1,6 @@ // Check that we can use the async keyword. -async function main(): Promise { - await new Promise((resolve): void => { +async function main() { + await new Promise((resolve) => { console.log("2"); setTimeout(resolve, 100); }); diff --git a/cli/tests/013_dynamic_import.ts b/cli/tests/013_dynamic_import.ts index 6bbce31328..d4dc551524 100644 --- a/cli/tests/013_dynamic_import.ts +++ b/cli/tests/013_dynamic_import.ts @@ -1,4 +1,4 @@ -(async (): Promise => { +(async () => { const { returnsHi, returnsFoo2, printHello3 } = await import( "./subdir/mod1.ts" ); diff --git a/cli/tests/014_duplicate_import.ts b/cli/tests/014_duplicate_import.ts index 97864fea7d..88f9345269 100644 --- a/cli/tests/014_duplicate_import.ts +++ b/cli/tests/014_duplicate_import.ts @@ -4,6 +4,6 @@ import "./subdir/auto_print_hello.ts"; import "./subdir/auto_print_hello.ts"; -(async (): Promise => { +(async () => { await import("./subdir/auto_print_hello.ts"); })(); diff --git a/cli/tests/016_double_await.ts b/cli/tests/016_double_await.ts index 0f31b3a808..457a53ff34 100644 --- a/cli/tests/016_double_await.ts +++ b/cli/tests/016_double_await.ts @@ -1,6 +1,6 @@ // This is to test if Deno would die at 2nd await // See https://github.com/denoland/deno/issues/919 -(async (): Promise => { +(async () => { const currDirInfo = await Deno.stat("."); const parentDirInfo = await Deno.stat(".."); console.log(currDirInfo.isDirectory); diff --git a/cli/tests/018_async_catch.ts b/cli/tests/018_async_catch.ts index 85423ceda9..ac43a52e86 100644 --- a/cli/tests/018_async_catch.ts +++ b/cli/tests/018_async_catch.ts @@ -1,7 +1,7 @@ function fn(): Promise { throw new Error("message"); } -async function call(): Promise { +async function call() { try { console.log("before await fn()"); await fn(); @@ -11,4 +11,4 @@ async function call(): Promise { } console.log("after try-catch"); } -call().catch((): void => console.log("outer catch")); +call().catch(() => console.log("outer catch")); diff --git a/cli/tests/025_hrtime.ts b/cli/tests/025_hrtime.ts index 9f60b7a77e..b69d614885 100644 --- a/cli/tests/025_hrtime.ts +++ b/cli/tests/025_hrtime.ts @@ -1,4 +1,4 @@ -window.onload = async (): Promise => { +window.onload = async () => { console.log(performance.now() % 2 !== 0); await Deno.permissions.revoke({ name: "hrtime" }); console.log(performance.now() % 2 === 0); diff --git a/cli/tests/028_args.ts b/cli/tests/028_args.ts index f3604a8305..ec41d52f9e 100644 --- a/cli/tests/028_args.ts +++ b/cli/tests/028_args.ts @@ -1,3 +1,3 @@ -Deno.args.forEach((arg): void => { +Deno.args.forEach((arg) => { console.log(arg); }); diff --git a/cli/tests/034_onload/imported.ts b/cli/tests/034_onload/imported.ts index 9e1411beaf..3c7a0aae2d 100644 --- a/cli/tests/034_onload/imported.ts +++ b/cli/tests/034_onload/imported.ts @@ -1,7 +1,7 @@ import { assert } from "../../../test_util/std/testing/asserts.ts"; import "./nest_imported.ts"; -const handler = (e: Event): void => { +const handler = (e: Event) => { assert(!e.cancelable); console.log(`got ${e.type} event in event handler (imported)`); }; diff --git a/cli/tests/034_onload/main.ts b/cli/tests/034_onload/main.ts index f8c48ba7b2..7696ec122c 100644 --- a/cli/tests/034_onload/main.ts +++ b/cli/tests/034_onload/main.ts @@ -4,7 +4,7 @@ import "./imported.ts"; assert(window.hasOwnProperty("onload")); assert(window.onload === null); -const eventHandler = (e: Event): void => { +const eventHandler = (e: Event) => { assert(!e.cancelable); console.log(`got ${e.type} event in event handler (main)`); }; @@ -13,12 +13,12 @@ window.addEventListener("load", eventHandler); window.addEventListener("unload", eventHandler); -window.onload = (e: Event): void => { +window.onload = (e: Event) => { assert(!e.cancelable); console.log(`got ${e.type} event in onload function`); }; -window.onunload = (e: Event): void => { +window.onunload = (e: Event) => { assert(!e.cancelable); console.log(`got ${e.type} event in onunload function`); }; diff --git a/cli/tests/034_onload/nest_imported.ts b/cli/tests/034_onload/nest_imported.ts index d43b8ebe7b..8ca668de97 100644 --- a/cli/tests/034_onload/nest_imported.ts +++ b/cli/tests/034_onload/nest_imported.ts @@ -1,6 +1,6 @@ import { assert } from "../../../test_util/std/testing/asserts.ts"; -const handler = (e: Event): void => { +const handler = (e: Event) => { assert(!e.cancelable); console.log(`got ${e.type} event in event handler (nest_imported)`); }; diff --git a/cli/tests/045_proxy_test.ts b/cli/tests/045_proxy_test.ts index 6e338f4fc2..db6f008767 100644 --- a/cli/tests/045_proxy_test.ts +++ b/cli/tests/045_proxy_test.ts @@ -4,7 +4,7 @@ import { assertEquals } from "../../test_util/std/testing/asserts.ts"; const addr = Deno.args[1] || "127.0.0.1:4555"; -async function proxyServer(): Promise { +async function proxyServer() { const server = serve(addr); console.log(`Proxy server listening on http://${addr}/`); @@ -13,7 +13,7 @@ async function proxyServer(): Promise { } } -async function proxyRequest(req: ServerRequest): Promise { +async function proxyRequest(req: ServerRequest) { console.log(`Proxy request to: ${req.url}`); const proxyAuthorization = req.headers.get("proxy-authorization"); if (proxyAuthorization) { @@ -31,7 +31,7 @@ async function proxyRequest(req: ServerRequest): Promise { }); } -async function testFetch(): Promise { +async function testFetch() { const c = Deno.run({ cmd: [ Deno.execPath(), @@ -52,7 +52,7 @@ async function testFetch(): Promise { c.close(); } -async function testModuleDownload(): Promise { +async function testModuleDownload() { const http = Deno.run({ cmd: [ Deno.execPath(), @@ -72,7 +72,7 @@ async function testModuleDownload(): Promise { http.close(); } -async function testFetchNoProxy(): Promise { +async function testFetchNoProxy() { const c = Deno.run({ cmd: [ Deno.execPath(), @@ -94,7 +94,7 @@ async function testFetchNoProxy(): Promise { c.close(); } -async function testModuleDownloadNoProxy(): Promise { +async function testModuleDownloadNoProxy() { const http = Deno.run({ cmd: [ Deno.execPath(), @@ -115,7 +115,7 @@ async function testModuleDownloadNoProxy(): Promise { http.close(); } -async function testFetchProgrammaticProxy(): Promise { +async function testFetchProgrammaticProxy() { const c = Deno.run({ cmd: [ Deno.execPath(), diff --git a/cli/tests/055_info_file_json.out b/cli/tests/055_info_file_json.out index de0091ded3..0706689223 100644 --- a/cli/tests/055_info_file_json.out +++ b/cli/tests/055_info_file_json.out @@ -22,7 +22,7 @@ "code": "file://[WILDCARD]/cli/tests/subdir/subdir2/mod2.ts" } ], - "size": 320, + "size": 308, "mediaType": "TypeScript", "local": "[WILDCARD]mod1.ts", [WILDCARD] @@ -30,7 +30,7 @@ { "specifier": "file://[WILDCARD]/cli/tests/subdir/print_hello.ts", "dependencies": [], - "size": 63, + "size": 57, "mediaType": "TypeScript", "local": "[WILDCARD]print_hello.ts", [WILDCARD] @@ -43,11 +43,11 @@ "code": "file://[WILDCARD]/cli/tests/subdir/print_hello.ts" } ], - "size": 163, + "size": 157, "mediaType": "TypeScript", "local": "[WILDCARD]mod2.ts", [WILDCARD] } ], - "size": 757 + "size": 733 } diff --git a/cli/tests/076_info_json_deps_order.out b/cli/tests/076_info_json_deps_order.out index 55cf05b307..f8b26057d9 100644 --- a/cli/tests/076_info_json_deps_order.out +++ b/cli/tests/076_info_json_deps_order.out @@ -26,10 +26,10 @@ "code": "file://[WILDCARD]/cli/tests/recursive_imports/common.ts" } ], - "size": 114, + "size": 108, "mediaType": "TypeScript", "local": "[WILDCARD]A.ts", - "checksum": "da204c16d3114763810864083af8891a887d65fbe34e4c8b5bf985dbc8f0b01f" + "checksum": "3b45a105d892584298490cb73372b2cac57118e1e42a677a1d5cacea704d8d3a" }, { "specifier": "file://[WILDCARD]/cli/tests/recursive_imports/B.ts", @@ -43,10 +43,10 @@ "code": "file://[WILDCARD]/cli/tests/recursive_imports/common.ts" } ], - "size": 114, + "size": 108, "mediaType": "TypeScript", "local": "[WILDCARD]B.ts", - "checksum": "060ef62435d7e3a3276e8894307b19cf17772210a20dd091d24a670fadec6b83" + "checksum": "b12b0437ef9a91c4a4b1f66e8e4339f986b60bd8134031ccb296ce49df15b54e" }, { "specifier": "file://[WILDCARD]/cli/tests/recursive_imports/C.ts", @@ -60,19 +60,19 @@ "code": "file://[WILDCARD]/cli/tests/recursive_imports/common.ts" } ], - "size": 132, + "size": 126, "mediaType": "TypeScript", "local": "[WILDCARD]C.ts", - "checksum": "5190563583617a69f190f1cc76e6552df878df278cfaa5d5e30ebe0938cf5e0b" + "checksum": "605875a410741bfaeeade28cbccf45f219ad99d987ea695e35eda75d2c53a658" }, { "specifier": "file://[WILDCARD]/cli/tests/recursive_imports/common.ts", "dependencies": [], - "size": 34, + "size": 28, "mediaType": "TypeScript", "local": "[WILDCARD]common.ts", - "checksum": "01b595d69514bfd001ba2cf421feabeaef559513f10697bf1a22781f8a8ed7f0" + "checksum": "c70025f0b936c02980c3be1fbd78f6f36b6241927c44ea67580821a6e664d8b3" } ], - "size": 475 + "size": 451 } diff --git a/cli/tests/bundle/file_tests-fixture11.ts b/cli/tests/bundle/file_tests-fixture11.ts index d3f60d367a..1c361438f3 100644 --- a/cli/tests/bundle/file_tests-fixture11.ts +++ b/cli/tests/bundle/file_tests-fixture11.ts @@ -2,7 +2,7 @@ import { a as defaultA, O } from "./subdir/m.ts"; export { O } from "./subdir/m.ts"; interface AOptions { - a?(): void; + a?(); c?: O; } diff --git a/cli/tests/bundle_im.ts b/cli/tests/bundle_im.ts index c43f6294c1..74834de20d 100644 --- a/cli/tests/bundle_im.ts +++ b/cli/tests/bundle_im.ts @@ -8,10 +8,10 @@ export function returnsFoo2(): string { return returnsFoo(); } -export function printHello3(): void { +export function printHello3() { printHello2(); } -export function throwsError(): void { +export function throwsError() { throw Error("exception from mod1"); } diff --git a/cli/tests/cat.ts b/cli/tests/cat.ts index 0cfd99d22e..14ceec5530 100644 --- a/cli/tests/cat.ts +++ b/cli/tests/cat.ts @@ -1,5 +1,5 @@ import { copy } from "../../test_util/std/io/util.ts"; -async function main(): Promise { +async function main() { for (let i = 1; i < Deno.args.length; i++) { const filename = Deno.args[i]; const file = await Deno.open(filename); diff --git a/cli/tests/complex_permissions_test.ts b/cli/tests/complex_permissions_test.ts index 002d335404..bae1572465 100644 --- a/cli/tests/complex_permissions_test.ts +++ b/cli/tests/complex_permissions_test.ts @@ -2,18 +2,18 @@ const name = Deno.args[0]; // deno-lint-ignore no-explicit-any const test: { [key: string]: (...args: any[]) => void | Promise } = { - read(files: string[]): void { + read(files: string[]) { files.forEach((file) => Deno.readFileSync(file)); }, - write(files: string[]): void { + write(files: string[]) { files.forEach((file) => Deno.writeFileSync(file, new Uint8Array(0), { append: true }) ); }, - netFetch(urls: string[]): void { + netFetch(urls: string[]) { urls.forEach((url) => fetch(url)); }, - netListen(endpoints: string[]): void { + netListen(endpoints: string[]) { endpoints.forEach((endpoint) => { const index = endpoint.lastIndexOf(":"); const [hostname, port] = [ @@ -28,7 +28,7 @@ const test: { [key: string]: (...args: any[]) => void | Promise } = { listener.close(); }); }, - async netConnect(endpoints: string[]): Promise { + async netConnect(endpoints: string[]) { for (const endpoint of endpoints) { const index = endpoint.lastIndexOf(":"); const [hostname, port] = [ diff --git a/cli/tests/echo.ts b/cli/tests/echo.ts index bded2fd040..84a6454333 100644 --- a/cli/tests/echo.ts +++ b/cli/tests/echo.ts @@ -1,4 +1,4 @@ -function echo(args: string[]): void { +function echo(args: string[]) { const msg = args.join(", "); Deno.stdout.write(new TextEncoder().encode(msg)); } diff --git a/cli/tests/echo_server.ts b/cli/tests/echo_server.ts index 7c8b0e42d4..84284bea11 100644 --- a/cli/tests/echo_server.ts +++ b/cli/tests/echo_server.ts @@ -4,7 +4,7 @@ const [hostname, port] = addr.split(":"); const listener = Deno.listen({ hostname, port: Number(port) }); console.log("listening on", addr); listener.accept().then( - async (conn): Promise => { + async (conn) => { console.log("received bytes:", await copy(conn, conn)); conn.close(); listener.close(); diff --git a/cli/tests/error_001.ts b/cli/tests/error_001.ts index f06f80cb4c..b01068bc01 100644 --- a/cli/tests/error_001.ts +++ b/cli/tests/error_001.ts @@ -2,7 +2,7 @@ function foo(): never { throw Error("bad"); } -function bar(): void { +function bar() { foo(); } diff --git a/cli/tests/error_002.ts b/cli/tests/error_002.ts index eb66764b71..6aa0fcc3b6 100644 --- a/cli/tests/error_002.ts +++ b/cli/tests/error_002.ts @@ -1,6 +1,6 @@ import { throwsError } from "./subdir/mod1.ts"; -function foo(): void { +function foo() { throwsError(); } diff --git a/cli/tests/error_005_missing_dynamic_import.ts b/cli/tests/error_005_missing_dynamic_import.ts index 4ff10f275f..8ea8ff94e9 100644 --- a/cli/tests/error_005_missing_dynamic_import.ts +++ b/cli/tests/error_005_missing_dynamic_import.ts @@ -1,3 +1,3 @@ -(async (): Promise => { +(async () => { const _badModule = await import("./bad-module.ts"); })(); diff --git a/cli/tests/error_012_bad_dynamic_import_specifier.ts b/cli/tests/error_012_bad_dynamic_import_specifier.ts index 1b538b7871..5f39f407c6 100644 --- a/cli/tests/error_012_bad_dynamic_import_specifier.ts +++ b/cli/tests/error_012_bad_dynamic_import_specifier.ts @@ -1,3 +1,3 @@ -(async (): Promise => { +(async () => { const _badModule = await import("bad-module.ts"); })(); diff --git a/cli/tests/error_023_stack_async.ts b/cli/tests/error_023_stack_async.ts index 621933576b..99e676e26d 100644 --- a/cli/tests/error_023_stack_async.ts +++ b/cli/tests/error_023_stack_async.ts @@ -1,4 +1,4 @@ -const p = (async (): Promise => { +const p = (async () => { await Promise.resolve().then((): never => { throw new Error("async"); }); diff --git a/cli/tests/info_recursive_imports_test.ts b/cli/tests/info_recursive_imports_test.ts index 0937bf4a55..c9ba44755d 100644 --- a/cli/tests/info_recursive_imports_test.ts +++ b/cli/tests/info_recursive_imports_test.ts @@ -1,5 +1,5 @@ import { A } from "./recursive_imports/A.ts"; -export function test(): void { +export function test() { A(); } diff --git a/cli/tests/js_import_detect.ts b/cli/tests/js_import_detect.ts index 7b90dfe63b..751741996f 100644 --- a/cli/tests/js_import_detect.ts +++ b/cli/tests/js_import_detect.ts @@ -1,3 +1,3 @@ -function define(_foo: string[]): void {} +function define(_foo: string[]) {} define(["long"]); console.log("ok"); diff --git a/cli/tests/lock_check_err.json b/cli/tests/lock_check_err.json index 55a1446d41..0a1380dfcf 100644 --- a/cli/tests/lock_check_err.json +++ b/cli/tests/lock_check_err.json @@ -1,4 +1,4 @@ { - "http://127.0.0.1:4545/cli/tests/subdir/print_hello.ts": "fe7bbccaedb6579200a8b582f905139296402d06b1b91109d6e12c41a23125da", + "http://127.0.0.1:4545/cli/tests/subdir/print_hello.ts": "fa6692c8f9ff3fb107e773c3ece5274e9d08be282867a1e3ded1d9c00fcaa63c", "http://127.0.0.1:4545/cli/tests/003_relative_import.ts": "bad" } diff --git a/cli/tests/lock_check_err_with_bundle.json b/cli/tests/lock_check_err_with_bundle.json index b773ed0717..9c6a2e5f6b 100644 --- a/cli/tests/lock_check_err_with_bundle.json +++ b/cli/tests/lock_check_err_with_bundle.json @@ -1,5 +1,5 @@ { - "http://127.0.0.1:4545/cli/tests/subdir/mod1.ts": "bc699ebc05dec9a4baf2109258f03e6ec8dd5498e2f8c5469b62073b3b241657", - "http://127.0.0.1:4545/cli/tests/subdir/print_hello.ts": "fe7bbccaedb6579200a8b582f905139296402d06b1b91109d6e12c41a23125da", + "http://127.0.0.1:4545/cli/tests/subdir/mod1.ts": "bfc1037b02c99abc20367f739bca7455813a5950066abd77965bff33b6eece0f", + "http://127.0.0.1:4545/cli/tests/subdir/print_hello.ts": "fa6692c8f9ff3fb107e773c3ece5274e9d08be282867a1e3ded1d9c00fcaa63c", "http://127.0.0.1:4545/cli/tests/subdir/subdir2/mod2.ts": "bad" } diff --git a/cli/tests/lock_check_ok.json b/cli/tests/lock_check_ok.json index c4b68e158f..e0ee0a17ef 100644 --- a/cli/tests/lock_check_ok.json +++ b/cli/tests/lock_check_ok.json @@ -1,4 +1,4 @@ { - "http://127.0.0.1:4545/cli/tests/subdir/print_hello.ts": "fe7bbccaedb6579200a8b582f905139296402d06b1b91109d6e12c41a23125da", + "http://127.0.0.1:4545/cli/tests/subdir/print_hello.ts": "fa6692c8f9ff3fb107e773c3ece5274e9d08be282867a1e3ded1d9c00fcaa63c", "http://127.0.0.1:4545/cli/tests/003_relative_import.ts": "aa9e16de824f81871a1c7164d5bd6857df7db2e18621750bd66b0bde4df07f21" } diff --git a/cli/tests/lock_dynamic_imports.json b/cli/tests/lock_dynamic_imports.json index bfc1cf7e7f..fb822f64e2 100644 --- a/cli/tests/lock_dynamic_imports.json +++ b/cli/tests/lock_dynamic_imports.json @@ -1,6 +1,6 @@ { - "http://127.0.0.1:4545/cli/tests/013_dynamic_import.ts": "c875f10de49bded1ad76f1709d68e6cf2c0cfb8e8e862542a3fcb4ab09257b99", - "http://127.0.0.1:4545/cli/tests/subdir/mod1.ts": "bc699ebc05dec9a4baf2109258f03e6ec8dd5498e2f8c5469b62073b3b241657", - "http://127.0.0.1:4545/cli/tests/subdir/print_hello.ts": "fe7bbccaedb6579200a8b582f905139296402d06b1b91109d6e12c41a23125da", + "http://127.0.0.1:4545/cli/tests/013_dynamic_import.ts": "f0d2d108c100e769cda9f26b74326f21e44cab81611aa7f6cd2b731d4cbc1995", + "http://127.0.0.1:4545/cli/tests/subdir/mod1.ts": "bfc1037b02c99abc20367f739bca7455813a5950066abd77965bff33b6eece0f", + "http://127.0.0.1:4545/cli/tests/subdir/print_hello.ts": "fa6692c8f9ff3fb107e773c3ece5274e9d08be282867a1e3ded1d9c00fcaa63c", "http://127.0.0.1:4545/cli/tests/subdir/subdir2/mod2.ts": "bad" } diff --git a/cli/tests/permission_test.ts b/cli/tests/permission_test.ts index ac42b7d69e..057e935afd 100644 --- a/cli/tests/permission_test.ts +++ b/cli/tests/permission_test.ts @@ -2,20 +2,20 @@ const name = Deno.args[0]; // deno-lint-ignore no-explicit-any const test: { [key: string]: (...args: any[]) => void | Promise } = { - readRequired(): Promise { + readRequired() { Deno.readFileSync("README.md"); return Promise.resolve(); }, - writeRequired(): void { + writeRequired() { Deno.makeTempDirSync(); }, - envRequired(): void { + envRequired() { Deno.env.get("home"); }, - netRequired(): void { + netRequired() { Deno.listen({ transport: "tcp", port: 4541 }); }, - runRequired(): void { + runRequired() { const p = Deno.run({ cmd: Deno.build.os === "windows" ? ["cmd.exe", "/c", "echo hello"] diff --git a/cli/tests/recursive_imports/A.ts b/cli/tests/recursive_imports/A.ts index 04ef61581f..43ecdbe5e4 100644 --- a/cli/tests/recursive_imports/A.ts +++ b/cli/tests/recursive_imports/A.ts @@ -1,7 +1,7 @@ import { B } from "./B.ts"; import { thing } from "./common.ts"; -export function A(): void { +export function A() { thing(); B(); } diff --git a/cli/tests/recursive_imports/B.ts b/cli/tests/recursive_imports/B.ts index a6e6917fd0..9fff0fdc9e 100644 --- a/cli/tests/recursive_imports/B.ts +++ b/cli/tests/recursive_imports/B.ts @@ -1,7 +1,7 @@ import { C } from "./C.ts"; import { thing } from "./common.ts"; -export function B(): void { +export function B() { thing(); C(); } diff --git a/cli/tests/recursive_imports/C.ts b/cli/tests/recursive_imports/C.ts index be6ef92402..e47e77b41d 100644 --- a/cli/tests/recursive_imports/C.ts +++ b/cli/tests/recursive_imports/C.ts @@ -1,7 +1,7 @@ import { A } from "./A.ts"; import { thing } from "./common.ts"; -export function C(): void { +export function C() { if (A != null) { thing(); } diff --git a/cli/tests/recursive_imports/common.ts b/cli/tests/recursive_imports/common.ts index d0f41395d6..2b16a7bf14 100644 --- a/cli/tests/recursive_imports/common.ts +++ b/cli/tests/recursive_imports/common.ts @@ -1,2 +1,2 @@ -export function thing(): void { +export function thing() { } diff --git a/cli/tests/subdir/circular1.ts b/cli/tests/subdir/circular1.ts index f9054338ff..06fdb33736 100644 --- a/cli/tests/subdir/circular1.ts +++ b/cli/tests/subdir/circular1.ts @@ -1,6 +1,6 @@ import * as circular2 from "./circular2.ts"; -export function f1(): void { +export function f1() { console.log("f1"); } diff --git a/cli/tests/subdir/circular2.ts b/cli/tests/subdir/circular2.ts index a96ffb13d1..0864b7adf4 100644 --- a/cli/tests/subdir/circular2.ts +++ b/cli/tests/subdir/circular2.ts @@ -1,6 +1,6 @@ import * as circular1 from "./circular1.ts"; -export function f2(): void { +export function f2() { console.log("f2"); } diff --git a/cli/tests/subdir/mod1.ts b/cli/tests/subdir/mod1.ts index 9a4b530214..5e58f432ed 100644 --- a/cli/tests/subdir/mod1.ts +++ b/cli/tests/subdir/mod1.ts @@ -8,10 +8,10 @@ export function returnsFoo2(): string { return returnsFoo(); } -export function printHello3(): void { +export function printHello3() { printHello2(); } -export function throwsError(): void { +export function throwsError() { throw Error("exception from mod1"); } diff --git a/cli/tests/subdir/print_hello.ts b/cli/tests/subdir/print_hello.ts index 7ecce50405..b9c0ad5275 100644 --- a/cli/tests/subdir/print_hello.ts +++ b/cli/tests/subdir/print_hello.ts @@ -1,3 +1,3 @@ -export function printHello(): void { +export function printHello() { console.log("Hello"); } diff --git a/cli/tests/subdir/subdir2/dynamic_import.ts b/cli/tests/subdir/subdir2/dynamic_import.ts index a8921390d4..573887b711 100644 --- a/cli/tests/subdir/subdir2/dynamic_import.ts +++ b/cli/tests/subdir/subdir2/dynamic_import.ts @@ -1,4 +1,4 @@ -(async (): Promise => { +(async () => { const { printHello } = await import("../mod2.ts"); printHello(); })(); diff --git a/cli/tests/subdir/subdir2/mod2.ts b/cli/tests/subdir/subdir2/mod2.ts index c88d4708c8..9071d0aeb4 100644 --- a/cli/tests/subdir/subdir2/mod2.ts +++ b/cli/tests/subdir/subdir2/mod2.ts @@ -4,6 +4,6 @@ export function returnsFoo(): string { return "Foo"; } -export function printHello2(): void { +export function printHello2() { printHello(); } diff --git a/cli/tests/ts_decorators_bundle.ts b/cli/tests/ts_decorators_bundle.ts index 189edfbff3..72120b2ec3 100644 --- a/cli/tests/ts_decorators_bundle.ts +++ b/cli/tests/ts_decorators_bundle.ts @@ -18,7 +18,7 @@ function Decorator() { class SomeClass { @Decorator() - async test(): Promise {} + async test() {} } new SomeClass().test(); diff --git a/cli/tests/type_definitions_for_export.ts b/cli/tests/type_definitions_for_export.ts index e9eb6b139f..1f17b4962f 100644 --- a/cli/tests/type_definitions_for_export.ts +++ b/cli/tests/type_definitions_for_export.ts @@ -1,6 +1,6 @@ import { foo } from "./export_type_def.ts"; -function bar(a: number): void { +function bar(a: number) { console.log(a); } diff --git a/cli/tests/unit/abort_controller_test.ts b/cli/tests/unit/abort_controller_test.ts index d89bcdd445..46c0e93944 100644 --- a/cli/tests/unit/abort_controller_test.ts +++ b/cli/tests/unit/abort_controller_test.ts @@ -14,7 +14,7 @@ unitTest(function signalCallsOnabort() { const controller = new AbortController(); const { signal } = controller; let called = false; - signal.onabort = (evt): void => { + signal.onabort = (evt) => { assert(evt); assertEquals(evt.type, "abort"); called = true; @@ -41,7 +41,7 @@ unitTest(function onlyAbortsOnce() { const { signal } = controller; let called = 0; signal.addEventListener("abort", () => called++); - signal.onabort = (): void => { + signal.onabort = () => { called++; }; controller.abort(); diff --git a/cli/tests/unit/blob_test.ts b/cli/tests/unit/blob_test.ts index ebb91658a7..8ce2791602 100644 --- a/cli/tests/unit/blob_test.ts +++ b/cli/tests/unit/blob_test.ts @@ -7,14 +7,14 @@ import { } from "./test_util.ts"; import { concat } from "../../../test_util/std/bytes/mod.ts"; -unitTest(function blobString(): void { +unitTest(function blobString() { const b1 = new Blob(["Hello World"]); const str = "Test"; const b2 = new Blob([b1, str]); assertEquals(b2.size, b1.size + str.length); }); -unitTest(function blobBuffer(): void { +unitTest(function blobBuffer() { const buffer = new ArrayBuffer(12); const u8 = new Uint8Array(buffer); const f1 = new Float32Array(buffer); @@ -24,7 +24,7 @@ unitTest(function blobBuffer(): void { assertEquals(b2.size, 3 * u8.length); }); -unitTest(function blobSlice(): void { +unitTest(function blobSlice() { const blob = new Blob(["Deno", "Foo"]); const b1 = blob.slice(0, 3, "Text/HTML"); assert(b1 instanceof Blob); @@ -38,7 +38,7 @@ unitTest(function blobSlice(): void { assertEquals(b4.size, blob.size); }); -unitTest(function blobInvalidType(): void { +unitTest(function blobInvalidType() { const blob = new Blob(["foo"], { type: "\u0521", }); @@ -46,7 +46,7 @@ unitTest(function blobInvalidType(): void { assertEquals(blob.type, ""); }); -unitTest(function blobShouldNotThrowError(): void { +unitTest(function blobShouldNotThrowError() { let hasThrown = false; try { @@ -66,7 +66,7 @@ unitTest(function blobShouldNotThrowError(): void { }); /* TODO https://github.com/denoland/deno/issues/7540 -unitTest(function nativeEndLine(): void { +unitTest(function nativeEndLine() { const options = { ending: "native", } as const; @@ -76,12 +76,12 @@ unitTest(function nativeEndLine(): void { }); */ -unitTest(async function blobText(): Promise { +unitTest(async function blobText() { const blob = new Blob(["Hello World"]); assertEquals(await blob.text(), "Hello World"); }); -unitTest(async function blobStream(): Promise { +unitTest(async function blobStream() { const blob = new Blob(["Hello World"]); const stream = blob.stream(); assert(stream instanceof ReadableStream); @@ -99,18 +99,18 @@ unitTest(async function blobStream(): Promise { assertEquals(decoder.decode(bytes), "Hello World"); }); -unitTest(async function blobArrayBuffer(): Promise { +unitTest(async function blobArrayBuffer() { const uint = new Uint8Array([102, 111, 111]); const blob = new Blob([uint]); assertEquals(await blob.arrayBuffer(), uint.buffer); }); -unitTest(function blobConstructorNameIsBlob(): void { +unitTest(function blobConstructorNameIsBlob() { const blob = new Blob(); assertEquals(blob.constructor.name, "Blob"); }); -unitTest(function blobCustomInspectFunction(): void { +unitTest(function blobCustomInspectFunction() { const blob = new Blob(); assertEquals( Deno.inspect(blob), diff --git a/cli/tests/unit/body_test.ts b/cli/tests/unit/body_test.ts index d889abfabe..78da2a9d40 100644 --- a/cli/tests/unit/body_test.ts +++ b/cli/tests/unit/body_test.ts @@ -23,7 +23,7 @@ const intArrays = [ Float32Array, Float64Array, ]; -unitTest(async function arrayBufferFromByteArrays(): Promise { +unitTest(async function arrayBufferFromByteArrays() { const buffer = new TextEncoder().encode("ahoyhoy8").buffer; for (const type of intArrays) { @@ -36,7 +36,7 @@ unitTest(async function arrayBufferFromByteArrays(): Promise { //FormData unitTest( { perms: { net: true } }, - async function bodyMultipartFormData(): Promise { + async function bodyMultipartFormData() { const response = await fetch( "http://localhost:4545/multipart_form_data.txt", ); @@ -55,7 +55,7 @@ unitTest( unitTest( { perms: { net: true } }, - async function bodyURLEncodedFormData(): Promise { + async function bodyURLEncodedFormData() { const response = await fetch( "http://localhost:4545/cli/tests/subdir/form_urlencoded.txt", ); @@ -73,14 +73,14 @@ unitTest( }, ); -unitTest({ perms: {} }, async function bodyURLSearchParams(): Promise { +unitTest({ perms: {} }, async function bodyURLSearchParams() { const body = buildBody(new URLSearchParams({ hello: "world" })); const text = await body.text(); assertEquals(text, "hello=world"); }); -unitTest(async function bodyArrayBufferMultipleParts(): Promise { +unitTest(async function bodyArrayBufferMultipleParts() { const parts: Uint8Array[] = []; let size = 0; for (let i = 0; i <= 150000; i++) { @@ -91,7 +91,7 @@ unitTest(async function bodyArrayBufferMultipleParts(): Promise { let offset = 0; const stream = new ReadableStream({ - pull(controller): void { + pull(controller) { // parts.shift() takes forever: https://github.com/denoland/deno/issues/5259 const chunk = parts[offset++]; if (!chunk) return controller.close(); diff --git a/cli/tests/unit/buffer_test.ts b/cli/tests/unit/buffer_test.ts index 57476e0f3d..30198d0b9a 100644 --- a/cli/tests/unit/buffer_test.ts +++ b/cli/tests/unit/buffer_test.ts @@ -21,7 +21,7 @@ let testString: string | null; const ignoreMaxSizeTests = true; -function init(): void { +function init() { if (testBytes == null) { testBytes = new Uint8Array(N); for (let i = 0; i < N; i++) { @@ -32,7 +32,7 @@ function init(): void { } } -function check(buf: Deno.Buffer, s: string): void { +function check(buf: Deno.Buffer, s: string) { const bytes = buf.bytes(); assertEquals(buf.length, bytes.byteLength); const decoder = new TextDecoder(); @@ -67,7 +67,7 @@ async function empty( buf: Deno.Buffer, s: string, fub: Uint8Array, -): Promise { +) { check(buf, s); while (true) { const r = await buf.read(fub); @@ -87,7 +87,7 @@ function repeat(c: string, bytes: number): Uint8Array { return ui8; } -unitTest(function bufferNewBuffer(): void { +unitTest(function bufferNewBuffer() { init(); assert(testBytes); assert(testString); @@ -95,7 +95,7 @@ unitTest(function bufferNewBuffer(): void { check(buf, testString); }); -unitTest(async function bufferBasicOperations(): Promise { +unitTest(async function bufferBasicOperations() { init(); assert(testBytes); assert(testString); @@ -135,7 +135,7 @@ unitTest(async function bufferBasicOperations(): Promise { } }); -unitTest(async function bufferReadEmptyAtEOF(): Promise { +unitTest(async function bufferReadEmptyAtEOF() { // check that EOF of 'buf' is not reached (even though it's empty) if // results are written to buffer that has 0 length (ie. it can't store any data) const buf = new Deno.Buffer(); @@ -144,7 +144,7 @@ unitTest(async function bufferReadEmptyAtEOF(): Promise { assertEquals(result, 0); }); -unitTest(async function bufferLargeByteWrites(): Promise { +unitTest(async function bufferLargeByteWrites() { init(); const buf = new Deno.Buffer(); const limit = 9; @@ -155,7 +155,7 @@ unitTest(async function bufferLargeByteWrites(): Promise { check(buf, ""); }); -unitTest(async function bufferTooLargeByteWrites(): Promise { +unitTest(async function bufferTooLargeByteWrites() { init(); const tmp = new Uint8Array(72); const growLen = Number.MAX_VALUE; @@ -174,7 +174,7 @@ unitTest(async function bufferTooLargeByteWrites(): Promise { unitTest( { ignore: ignoreMaxSizeTests }, - function bufferGrowWriteMaxBuffer(): void { + function bufferGrowWriteMaxBuffer() { const bufSize = 16 * 1024; const capacities = [MAX_SIZE, MAX_SIZE - 1]; for (const capacity of capacities) { @@ -196,7 +196,7 @@ unitTest( unitTest( { ignore: ignoreMaxSizeTests }, - async function bufferGrowReadCloseMaxBufferPlus1(): Promise { + async function bufferGrowReadCloseMaxBufferPlus1() { const reader = new Deno.Buffer(new ArrayBuffer(MAX_SIZE + 1)); const buf = new Deno.Buffer(); @@ -212,7 +212,7 @@ unitTest( unitTest( { ignore: ignoreMaxSizeTests }, - function bufferGrowReadSyncCloseMaxBufferPlus1(): void { + function bufferGrowReadSyncCloseMaxBufferPlus1() { const reader = new Deno.Buffer(new ArrayBuffer(MAX_SIZE + 1)); const buf = new Deno.Buffer(); @@ -228,7 +228,7 @@ unitTest( unitTest( { ignore: ignoreMaxSizeTests }, - function bufferGrowReadSyncCloseToMaxBuffer(): void { + function bufferGrowReadSyncCloseToMaxBuffer() { const capacities = [MAX_SIZE, MAX_SIZE - 1]; for (const capacity of capacities) { const reader = new Deno.Buffer(new ArrayBuffer(capacity)); @@ -242,7 +242,7 @@ unitTest( unitTest( { ignore: ignoreMaxSizeTests }, - async function bufferGrowReadCloseToMaxBuffer(): Promise { + async function bufferGrowReadCloseToMaxBuffer() { const capacities = [MAX_SIZE, MAX_SIZE - 1]; for (const capacity of capacities) { const reader = new Deno.Buffer(new ArrayBuffer(capacity)); @@ -255,7 +255,7 @@ unitTest( unitTest( { ignore: ignoreMaxSizeTests }, - async function bufferReadCloseToMaxBufferWithInitialGrow(): Promise { + async function bufferReadCloseToMaxBufferWithInitialGrow() { const capacities = [MAX_SIZE, MAX_SIZE - 1, MAX_SIZE - 512]; for (const capacity of capacities) { const reader = new Deno.Buffer(new ArrayBuffer(capacity)); @@ -267,7 +267,7 @@ unitTest( }, ); -unitTest(async function bufferLargeByteReads(): Promise { +unitTest(async function bufferLargeByteReads() { init(); assert(testBytes); assert(testString); @@ -280,12 +280,12 @@ unitTest(async function bufferLargeByteReads(): Promise { check(buf, ""); }); -unitTest(function bufferCapWithPreallocatedSlice(): void { +unitTest(function bufferCapWithPreallocatedSlice() { const buf = new Deno.Buffer(new ArrayBuffer(10)); assertEquals(buf.capacity, 10); }); -unitTest(async function bufferReadFrom(): Promise { +unitTest(async function bufferReadFrom() { init(); assert(testBytes); assert(testString); @@ -307,7 +307,7 @@ unitTest(async function bufferReadFrom(): Promise { }); }); -unitTest(async function bufferReadFromSync(): Promise { +unitTest(async function bufferReadFromSync() { init(); assert(testBytes); assert(testString); @@ -329,7 +329,7 @@ unitTest(async function bufferReadFromSync(): Promise { }); }); -unitTest(async function bufferTestGrow(): Promise { +unitTest(async function bufferTestGrow() { const tmp = new Uint8Array(72); for (const startLen of [0, 100, 1000, 10000]) { const xBytes = repeat("x", startLen); @@ -353,7 +353,7 @@ unitTest(async function bufferTestGrow(): Promise { } }); -unitTest(async function testReadAll(): Promise { +unitTest(async function testReadAll() { init(); assert(testBytes); const reader = new Deno.Buffer(testBytes.buffer as ArrayBuffer); @@ -364,7 +364,7 @@ unitTest(async function testReadAll(): Promise { } }); -unitTest(function testReadAllSync(): void { +unitTest(function testReadAllSync() { init(); assert(testBytes); const reader = new Deno.Buffer(testBytes.buffer as ArrayBuffer); @@ -375,7 +375,7 @@ unitTest(function testReadAllSync(): void { } }); -unitTest(async function testWriteAll(): Promise { +unitTest(async function testWriteAll() { init(); assert(testBytes); const writer = new Deno.Buffer(); @@ -387,7 +387,7 @@ unitTest(async function testWriteAll(): Promise { } }); -unitTest(function testWriteAllSync(): void { +unitTest(function testWriteAllSync() { init(); assert(testBytes); const writer = new Deno.Buffer(); @@ -399,7 +399,7 @@ unitTest(function testWriteAllSync(): void { } }); -unitTest(function testBufferBytesArrayBufferLength(): void { +unitTest(function testBufferBytesArrayBufferLength() { // defaults to copy const args = [{}, { copy: undefined }, undefined, { copy: true }]; for (const arg of args) { @@ -418,7 +418,7 @@ unitTest(function testBufferBytesArrayBufferLength(): void { } }); -unitTest(function testBufferBytesCopyFalse(): void { +unitTest(function testBufferBytesCopyFalse() { const bufSize = 64 * 1024; const bytes = new TextEncoder().encode("a".repeat(bufSize)); const reader = new Deno.Buffer(); @@ -433,7 +433,7 @@ unitTest(function testBufferBytesCopyFalse(): void { assert(actualBytes.buffer.byteLength > actualBytes.byteLength); }); -unitTest(function testBufferBytesCopyFalseGrowExactBytes(): void { +unitTest(function testBufferBytesCopyFalseGrowExactBytes() { const bufSize = 64 * 1024; const bytes = new TextEncoder().encode("a".repeat(bufSize)); const reader = new Deno.Buffer(); diff --git a/cli/tests/unit/build_test.ts b/cli/tests/unit/build_test.ts index 731290326b..01027d4f1d 100644 --- a/cli/tests/unit/build_test.ts +++ b/cli/tests/unit/build_test.ts @@ -1,7 +1,7 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. import { assert, unitTest } from "./test_util.ts"; -unitTest(function buildInfo(): void { +unitTest(function buildInfo() { // Deno.build is injected by rollup at compile time. Here // we check it has been properly transformed. const { arch, os } = Deno.build; diff --git a/cli/tests/unit/chmod_test.ts b/cli/tests/unit/chmod_test.ts index 80f2401340..5908ea09af 100644 --- a/cli/tests/unit/chmod_test.ts +++ b/cli/tests/unit/chmod_test.ts @@ -9,7 +9,7 @@ import { unitTest( { ignore: Deno.build.os === "windows", perms: { read: true, write: true } }, - function chmodSyncSuccess(): void { + function chmodSyncSuccess() { const enc = new TextEncoder(); const data = enc.encode("Hello"); const tempDir = Deno.makeTempDirSync(); @@ -26,7 +26,7 @@ unitTest( unitTest( { ignore: Deno.build.os === "windows", perms: { read: true, write: true } }, - function chmodSyncUrl(): void { + function chmodSyncUrl() { const enc = new TextEncoder(); const data = enc.encode("Hello"); const tempDir = Deno.makeTempDirSync(); @@ -49,7 +49,7 @@ unitTest( ignore: Deno.build.os === "windows", perms: { read: true, write: true }, }, - function chmodSyncSymlinkSuccess(): void { + function chmodSyncSymlinkSuccess() { const enc = new TextEncoder(); const data = enc.encode("Hello"); const tempDir = Deno.makeTempDirSync(); @@ -75,14 +75,14 @@ unitTest( }, ); -unitTest({ perms: { write: true } }, function chmodSyncFailure(): void { +unitTest({ perms: { write: true } }, function chmodSyncFailure() { assertThrows(() => { const filename = "/badfile.txt"; Deno.chmodSync(filename, 0o777); }, Deno.errors.NotFound); }); -unitTest({ perms: { write: false } }, function chmodSyncPerm(): void { +unitTest({ perms: { write: false } }, function chmodSyncPerm() { assertThrows(() => { Deno.chmodSync("/somefile.txt", 0o777); }, Deno.errors.PermissionDenied); @@ -90,7 +90,7 @@ unitTest({ perms: { write: false } }, function chmodSyncPerm(): void { unitTest( { ignore: Deno.build.os === "windows", perms: { read: true, write: true } }, - async function chmodSuccess(): Promise { + async function chmodSuccess() { const enc = new TextEncoder(); const data = enc.encode("Hello"); const tempDir = Deno.makeTempDirSync(); @@ -107,7 +107,7 @@ unitTest( unitTest( { ignore: Deno.build.os === "windows", perms: { read: true, write: true } }, - async function chmodUrl(): Promise { + async function chmodUrl() { const enc = new TextEncoder(); const data = enc.encode("Hello"); const tempDir = Deno.makeTempDirSync(); @@ -131,7 +131,7 @@ unitTest( ignore: Deno.build.os === "windows", perms: { read: true, write: true }, }, - async function chmodSymlinkSuccess(): Promise { + async function chmodSymlinkSuccess() { const enc = new TextEncoder(); const data = enc.encode("Hello"); const tempDir = Deno.makeTempDirSync(); @@ -157,18 +157,14 @@ unitTest( }, ); -unitTest({ perms: { write: true } }, async function chmodFailure(): Promise< - void -> { +unitTest({ perms: { write: true } }, async function chmodFailure() { await assertThrowsAsync(async () => { const filename = "/badfile.txt"; await Deno.chmod(filename, 0o777); }, Deno.errors.NotFound); }); -unitTest({ perms: { write: false } }, async function chmodPerm(): Promise< - void -> { +unitTest({ perms: { write: false } }, async function chmodPerm() { await assertThrowsAsync(async () => { await Deno.chmod("/somefile.txt", 0o777); }, Deno.errors.PermissionDenied); diff --git a/cli/tests/unit/chown_test.ts b/cli/tests/unit/chown_test.ts index 2fac679ce5..a8d264a6c0 100644 --- a/cli/tests/unit/chown_test.ts +++ b/cli/tests/unit/chown_test.ts @@ -31,7 +31,7 @@ async function getUidAndGid(): Promise<{ uid: number; gid: number }> { unitTest( { ignore: Deno.build.os == "windows" }, - async function chownNoWritePermission(): Promise { + async function chownNoWritePermission() { const filePath = "chown_test_file.txt"; await assertThrowsAsync(async () => { await Deno.chown(filePath, 1000, 1000); @@ -41,7 +41,7 @@ unitTest( unitTest( { perms: { run: true, write: true }, ignore: Deno.build.os == "windows" }, - async function chownSyncFileNotExist(): Promise { + async function chownSyncFileNotExist() { const { uid, gid } = await getUidAndGid(); const filePath = Deno.makeTempDirSync() + "/chown_test_file.txt"; @@ -53,7 +53,7 @@ unitTest( unitTest( { perms: { run: true, write: true }, ignore: Deno.build.os == "windows" }, - async function chownFileNotExist(): Promise { + async function chownFileNotExist() { const { uid, gid } = await getUidAndGid(); const filePath = (await Deno.makeTempDir()) + "/chown_test_file.txt"; @@ -65,7 +65,7 @@ unitTest( unitTest( { perms: { write: true }, ignore: Deno.build.os == "windows" }, - function chownSyncPermissionDenied(): void { + function chownSyncPermissionDenied() { const dirPath = Deno.makeTempDirSync(); const filePath = dirPath + "/chown_test_file.txt"; Deno.writeTextFileSync(filePath, "Hello"); @@ -80,7 +80,7 @@ unitTest( unitTest( { perms: { write: true }, ignore: Deno.build.os == "windows" }, - async function chownPermissionDenied(): Promise { + async function chownPermissionDenied() { const dirPath = await Deno.makeTempDir(); const filePath = dirPath + "/chown_test_file.txt"; await Deno.writeTextFile(filePath, "Hello"); @@ -95,7 +95,7 @@ unitTest( unitTest( { perms: { run: true, write: true }, ignore: Deno.build.os == "windows" }, - async function chownSyncSucceed(): Promise { + async function chownSyncSucceed() { // TODO(bartlomieju): when a file's owner is actually being changed, // chown only succeeds if run under priviledged user (root) // The test script has no such privilege, so need to find a better way to test this case @@ -115,7 +115,7 @@ unitTest( unitTest( { perms: { run: true, write: true }, ignore: Deno.build.os == "windows" }, - async function chownSyncWithUrl(): Promise { + async function chownSyncWithUrl() { const { uid, gid } = await getUidAndGid(); const dirPath = Deno.makeTempDirSync(); const fileUrl = new URL(`file://${dirPath}/chown_test_file.txt`); @@ -127,7 +127,7 @@ unitTest( unitTest( { perms: { run: true, write: true }, ignore: Deno.build.os == "windows" }, - async function chownSucceed(): Promise { + async function chownSucceed() { const { uid, gid } = await getUidAndGid(); const dirPath = await Deno.makeTempDir(); const filePath = dirPath + "/chown_test_file.txt"; @@ -139,7 +139,7 @@ unitTest( unitTest( { perms: { run: true, write: true }, ignore: Deno.build.os == "windows" }, - async function chownUidOnly(): Promise { + async function chownUidOnly() { const { uid } = await getUidAndGid(); const dirPath = await Deno.makeTempDir(); const filePath = dirPath + "/chown_test_file.txt"; @@ -151,7 +151,7 @@ unitTest( unitTest( { perms: { run: true, write: true }, ignore: Deno.build.os == "windows" }, - async function chownWithUrl(): Promise { + async function chownWithUrl() { // TODO(bartlomieju): same as chownSyncSucceed const { uid, gid } = await getUidAndGid(); diff --git a/cli/tests/unit/console_test.ts b/cli/tests/unit/console_test.ts index 0fb75c89f6..3d34c83cef 100644 --- a/cli/tests/unit/console_test.ts +++ b/cli/tests/unit/console_test.ts @@ -64,7 +64,7 @@ function cssToAnsiEsc(css: Css, prevCss: Css | null = null): string { // test cases from web-platform-tests // via https://github.com/web-platform-tests/wpt/blob/master/console/console-is-a-namespace.any.js -unitTest(function consoleShouldBeANamespace(): void { +unitTest(function consoleShouldBeANamespace() { const prototype1 = Object.getPrototypeOf(console); const prototype2 = Object.getPrototypeOf(prototype1); @@ -72,12 +72,12 @@ unitTest(function consoleShouldBeANamespace(): void { assertEquals(prototype2, Object.prototype); }); -unitTest(function consoleHasRightInstance(): void { +unitTest(function consoleHasRightInstance() { assert(console instanceof Console); assertEquals({} instanceof Console, false); }); -unitTest(function consoleTestAssertShouldNotThrowError(): void { +unitTest(function consoleTestAssertShouldNotThrowError() { mockConsole((console) => { console.assert(true); let hasThrown = undefined; @@ -91,14 +91,14 @@ unitTest(function consoleTestAssertShouldNotThrowError(): void { }); }); -unitTest(function consoleTestStringifyComplexObjects(): void { +unitTest(function consoleTestStringifyComplexObjects() { assertEquals(stringify("foo"), "foo"); assertEquals(stringify(["foo", "bar"]), `[ "foo", "bar" ]`); assertEquals(stringify({ foo: "bar" }), `{ foo: "bar" }`); }); unitTest( - function consoleTestStringifyComplexObjectsWithEscapedSequences(): void { + function consoleTestStringifyComplexObjectsWithEscapedSequences() { assertEquals( stringify( ["foo\b", "foo\f", "foo\n", "foo\r", "foo\t", "foo\v", "foo\0"], @@ -167,14 +167,14 @@ unitTest( }, ); -unitTest(function consoleTestStringifyQuotes(): void { +unitTest(function consoleTestStringifyQuotes() { assertEquals(stringify(["\\"]), `[ "\\\\" ]`); assertEquals(stringify(['\\,"']), `[ '\\\\,"' ]`); assertEquals(stringify([`\\,",'`]), `[ \`\\\\,",'\` ]`); assertEquals(stringify(["\\,\",',`"]), `[ "\\\\,\\",',\`" ]`); }); -unitTest(function consoleTestStringifyLongStrings(): void { +unitTest(function consoleTestStringifyLongStrings() { const veryLongString = "a".repeat(200); // If we stringify an object containing the long string, it gets abbreviated. let actual = stringify({ veryLongString }); @@ -185,7 +185,7 @@ unitTest(function consoleTestStringifyLongStrings(): void { assertEquals(actual, veryLongString); }); -unitTest(function consoleTestStringifyCircular(): void { +unitTest(function consoleTestStringifyCircular() { class Base { a = 1; m1() {} @@ -283,11 +283,11 @@ unitTest(function consoleTestStringifyCircular(): void { assertEquals(stringify(undefined), "undefined"); assertEquals(stringify(new Extended()), "Extended { a: 1, b: 2 }"); assertEquals( - stringify(function f(): void {}), + stringify(function f() {}), "[Function: f]", ); assertEquals( - stringify(async function af(): Promise {}), + stringify(async function af() {}), "[AsyncFunction: af]", ); assertEquals( @@ -354,7 +354,7 @@ unitTest(function consoleTestStringifyCircular(): void { assertEquals(stripColor(Deno.inspect(nestedObj)), nestedObjExpected); }); -unitTest(function consoleTestStringifyFunctionWithPrototypeRemoved(): void { +unitTest(function consoleTestStringifyFunctionWithPrototypeRemoved() { const f = function f() {}; Reflect.setPrototypeOf(f, null); assertEquals(stringify(f), "[Function: f]"); @@ -369,7 +369,7 @@ unitTest(function consoleTestStringifyFunctionWithPrototypeRemoved(): void { assertEquals(stringify(agf), "[Function: agf]"); }); -unitTest(function consoleTestStringifyFunctionWithProperties(): void { +unitTest(function consoleTestStringifyFunctionWithProperties() { const f = () => "test"; f.x = () => "foo"; f.y = 3; @@ -413,7 +413,7 @@ unitTest(function consoleTestStringifyFunctionWithProperties(): void { ); }); -unitTest(function consoleTestStringifyWithDepth(): void { +unitTest(function consoleTestStringifyWithDepth() { // deno-lint-ignore no-explicit-any const nestedObj: any = { a: { b: { c: { d: { e: { f: 42 } } } } } }; assertEquals( @@ -436,7 +436,7 @@ unitTest(function consoleTestStringifyWithDepth(): void { ); }); -unitTest(function consoleTestStringifyLargeObject(): void { +unitTest(function consoleTestStringifyLargeObject() { const obj = { a: 2, o: { @@ -768,7 +768,7 @@ unitTest(function consoleTestStringifyIterable() { */ }); -unitTest(function consoleTestStringifyIterableWhenGrouped(): void { +unitTest(function consoleTestStringifyIterableWhenGrouped() { const withOddNumberOfEls = new Float64Array( [ 2.1, @@ -846,7 +846,7 @@ unitTest(function consoleTestStringifyIterableWhenGrouped(): void { ); }); -unitTest(async function consoleTestStringifyPromises(): Promise { +unitTest(async function consoleTestStringifyPromises() { const pendingPromise = new Promise((_res, _rej) => {}); assertEquals(stringify(pendingPromise), "Promise { }"); @@ -869,7 +869,7 @@ unitTest(async function consoleTestStringifyPromises(): Promise { assertEquals(strLines[1], " Error: Whoops"); }); -unitTest(function consoleTestWithCustomInspector(): void { +unitTest(function consoleTestWithCustomInspector() { class A { [customInspect](): string { return "b"; @@ -879,7 +879,7 @@ unitTest(function consoleTestWithCustomInspector(): void { assertEquals(stringify(new A()), "b"); }); -unitTest(function consoleTestWithCustomInspectorUsingInspectFunc(): void { +unitTest(function consoleTestWithCustomInspectorUsingInspectFunc() { class A { [customInspect]( inspect: (v: unknown, opts?: Deno.InspectOptions) => string, @@ -891,7 +891,7 @@ unitTest(function consoleTestWithCustomInspectorUsingInspectFunc(): void { assertEquals(stringify(new A()), "b { c: 1 }"); }); -unitTest(function consoleTestWithCustomInspectorError(): void { +unitTest(function consoleTestWithCustomInspectorError() { class A { [customInspect](): never { throw new Error("BOOM"); @@ -913,7 +913,7 @@ unitTest(function consoleTestWithCustomInspectorError(): void { ); }); -unitTest(function consoleTestWithCustomInspectFunction(): void { +unitTest(function consoleTestWithCustomInspectFunction() { function a() {} Object.assign(a, { [customInspect]() { @@ -924,7 +924,7 @@ unitTest(function consoleTestWithCustomInspectFunction(): void { assertEquals(stringify(a), "b"); }); -unitTest(function consoleTestWithIntegerFormatSpecifier(): void { +unitTest(function consoleTestWithIntegerFormatSpecifier() { assertEquals(stringify("%i"), "%i"); assertEquals(stringify("%i", 42.0), "42"); assertEquals(stringify("%i", 42), "42"); @@ -942,7 +942,7 @@ unitTest(function consoleTestWithIntegerFormatSpecifier(): void { ); }); -unitTest(function consoleTestWithFloatFormatSpecifier(): void { +unitTest(function consoleTestWithFloatFormatSpecifier() { assertEquals(stringify("%f"), "%f"); assertEquals(stringify("%f", 42.0), "42"); assertEquals(stringify("%f", 42), "42"); @@ -957,7 +957,7 @@ unitTest(function consoleTestWithFloatFormatSpecifier(): void { assertEquals(stringify("%f %f", 42), "42 %f"); }); -unitTest(function consoleTestWithStringFormatSpecifier(): void { +unitTest(function consoleTestWithStringFormatSpecifier() { assertEquals(stringify("%s"), "%s"); assertEquals(stringify("%s", undefined), "undefined"); assertEquals(stringify("%s", "foo"), "foo"); @@ -968,7 +968,7 @@ unitTest(function consoleTestWithStringFormatSpecifier(): void { assertEquals(stringify("%s", Symbol("foo")), "Symbol(foo)"); }); -unitTest(function consoleTestWithObjectFormatSpecifier(): void { +unitTest(function consoleTestWithObjectFormatSpecifier() { assertEquals(stringify("%o"), "%o"); assertEquals(stringify("%o", 42), "42"); assertEquals(stringify("%o", "foo"), `"foo"`); @@ -980,13 +980,13 @@ unitTest(function consoleTestWithObjectFormatSpecifier(): void { ); }); -unitTest(function consoleTestWithStyleSpecifier(): void { +unitTest(function consoleTestWithStyleSpecifier() { assertEquals(stringify("%cfoo%cbar"), "%cfoo%cbar"); assertEquals(stringify("%cfoo%cbar", ""), "foo%cbar"); assertEquals(stripColor(stringify("%cfoo%cbar", "", "color: red")), "foobar"); }); -unitTest(function consoleParseCssColor(): void { +unitTest(function consoleParseCssColor() { assertEquals(parseCssColor("black"), [0, 0, 0]); assertEquals(parseCssColor("darkmagenta"), [139, 0, 139]); assertEquals(parseCssColor("slateblue"), [106, 90, 205]); @@ -1005,7 +1005,7 @@ unitTest(function consoleParseCssColor(): void { ); }); -unitTest(function consoleParseCss(): void { +unitTest(function consoleParseCss() { assertEquals( parseCss("background-color: red"), { ...DEFAULT_CSS, backgroundColor: [255, 0, 0] }, @@ -1059,7 +1059,7 @@ unitTest(function consoleParseCss(): void { ); }); -unitTest(function consoleCssToAnsi(): void { +unitTest(function consoleCssToAnsi() { assertEquals( cssToAnsiEsc({ ...DEFAULT_CSS, backgroundColor: [200, 201, 202] }), "_[48;2;200;201;202m", @@ -1099,7 +1099,7 @@ unitTest(function consoleCssToAnsi(): void { ); }); -unitTest(function consoleTestWithVariousOrInvalidFormatSpecifier(): void { +unitTest(function consoleTestWithVariousOrInvalidFormatSpecifier() { assertEquals(stringify("%s:%s"), "%s:%s"); assertEquals(stringify("%i:%i"), "%i:%i"); assertEquals(stringify("%d:%d"), "%d:%d"); @@ -1115,13 +1115,13 @@ unitTest(function consoleTestWithVariousOrInvalidFormatSpecifier(): void { assertEquals(stringify("abc%", 1), "abc% 1"); }); -unitTest(function consoleTestCallToStringOnLabel(): void { +unitTest(function consoleTestCallToStringOnLabel() { const methods = ["count", "countReset", "time", "timeLog", "timeEnd"]; mockConsole((console) => { for (const method of methods) { let hasCalled = false; console[method]({ - toString(): void { + toString() { hasCalled = true; }, }); @@ -1130,7 +1130,7 @@ unitTest(function consoleTestCallToStringOnLabel(): void { }); }); -unitTest(function consoleTestError(): void { +unitTest(function consoleTestError() { class MyError extends Error { constructor(errStr: string) { super(errStr); @@ -1148,7 +1148,7 @@ unitTest(function consoleTestError(): void { } }); -unitTest(function consoleTestClear(): void { +unitTest(function consoleTestClear() { mockConsole((console, out) => { console.clear(); assertEquals(out.toString(), "\x1b[1;1H" + "\x1b[0J"); @@ -1156,7 +1156,7 @@ unitTest(function consoleTestClear(): void { }); // Test bound this issue -unitTest(function consoleDetachedLog(): void { +unitTest(function consoleDetachedLog() { mockConsole((console) => { const log = console.log; const dir = console.dir; @@ -1197,7 +1197,7 @@ unitTest(function consoleDetachedLog(): void { class StringBuffer { chunks: string[] = []; - add(x: string): void { + add(x: string) { this.chunks.push(x); } toString(): string { @@ -1213,12 +1213,12 @@ type ConsoleExamineFunc = ( both?: StringBuffer, ) => void; -function mockConsole(f: ConsoleExamineFunc): void { +function mockConsole(f: ConsoleExamineFunc) { const out = new StringBuffer(); const err = new StringBuffer(); const both = new StringBuffer(); const csl = new Console( - (x: string, level: number, printsNewLine: boolean): void => { + (x: string, level: number, printsNewLine: boolean) => { const content = x + (printsNewLine ? "\n" : ""); const buf = level > 1 ? err : out; buf.add(content); @@ -1229,8 +1229,8 @@ function mockConsole(f: ConsoleExamineFunc): void { } // console.group test -unitTest(function consoleGroup(): void { - mockConsole((console, out): void => { +unitTest(function consoleGroup() { + mockConsole((console, out) => { console.group("1"); console.log("2"); console.group("3"); @@ -1254,8 +1254,8 @@ unitTest(function consoleGroup(): void { }); // console.group with console.warn test -unitTest(function consoleGroupWarn(): void { - mockConsole((console, _out, _err, both): void => { +unitTest(function consoleGroupWarn() { + mockConsole((console, _out, _err, both) => { assert(both); console.warn("1"); console.group(); @@ -1284,8 +1284,8 @@ unitTest(function consoleGroupWarn(): void { }); // console.table test -unitTest(function consoleTable(): void { - mockConsole((console, out): void => { +unitTest(function consoleTable() { + mockConsole((console, out) => { console.table({ a: "test", b: 1 }); assertEquals( stripColor(out.toString()), @@ -1298,7 +1298,7 @@ unitTest(function consoleTable(): void { `, ); }); - mockConsole((console, out): void => { + mockConsole((console, out) => { console.table({ a: { b: 10 }, b: { b: 20, c: 30 } }, ["c"]); assertEquals( stripColor(out.toString()), @@ -1311,7 +1311,7 @@ unitTest(function consoleTable(): void { `, ); }); - mockConsole((console, out): void => { + mockConsole((console, out) => { console.table([1, 2, [3, [4]], [5, 6], [[7], [8]]]); assertEquals( stripColor(out.toString()), @@ -1327,7 +1327,7 @@ unitTest(function consoleTable(): void { `, ); }); - mockConsole((console, out): void => { + mockConsole((console, out) => { console.table(new Set([1, 2, 3, "test"])); assertEquals( stripColor(out.toString()), @@ -1342,7 +1342,7 @@ unitTest(function consoleTable(): void { `, ); }); - mockConsole((console, out): void => { + mockConsole((console, out) => { console.table( new Map([ [1, "one"], @@ -1360,7 +1360,7 @@ unitTest(function consoleTable(): void { `, ); }); - mockConsole((console, out): void => { + mockConsole((console, out) => { console.table({ a: true, b: { c: { d: 10 }, e: [1, 2, [5, 6]] }, @@ -1382,7 +1382,7 @@ unitTest(function consoleTable(): void { `, ); }); - mockConsole((console, out): void => { + mockConsole((console, out) => { console.table([ 1, "test", @@ -1404,7 +1404,7 @@ unitTest(function consoleTable(): void { `, ); }); - mockConsole((console, out): void => { + mockConsole((console, out) => { console.table([]); assertEquals( stripColor(out.toString()), @@ -1415,7 +1415,7 @@ unitTest(function consoleTable(): void { `, ); }); - mockConsole((console, out): void => { + mockConsole((console, out) => { console.table({}); assertEquals( stripColor(out.toString()), @@ -1426,7 +1426,7 @@ unitTest(function consoleTable(): void { `, ); }); - mockConsole((console, out): void => { + mockConsole((console, out) => { console.table(new Set()); assertEquals( stripColor(out.toString()), @@ -1437,7 +1437,7 @@ unitTest(function consoleTable(): void { `, ); }); - mockConsole((console, out): void => { + mockConsole((console, out) => { console.table(new Map()); assertEquals( stripColor(out.toString()), @@ -1448,11 +1448,11 @@ unitTest(function consoleTable(): void { `, ); }); - mockConsole((console, out): void => { + mockConsole((console, out) => { console.table("test"); assertEquals(out.toString(), "test\n"); }); - mockConsole((console, out): void => { + mockConsole((console, out) => { console.table(["Hello", "你好", "Amapá"]); assertEquals( stripColor(out.toString()), @@ -1466,7 +1466,7 @@ unitTest(function consoleTable(): void { `, ); }); - mockConsole((console, out): void => { + mockConsole((console, out) => { console.table([ [1, 2], [3, 4], @@ -1482,7 +1482,7 @@ unitTest(function consoleTable(): void { `, ); }); - mockConsole((console, out): void => { + mockConsole((console, out) => { console.table({ 1: { a: 4, b: 5 }, 2: null, 3: { b: 6, c: 7 } }, ["b"]); assertEquals( stripColor(out.toString()), @@ -1532,7 +1532,7 @@ unitTest(function consoleTable(): void { }); // console.log(Error) test -unitTest(function consoleLogShouldNotThrowError(): void { +unitTest(function consoleLogShouldNotThrowError() { mockConsole((console) => { let result = 0; try { @@ -1545,14 +1545,14 @@ unitTest(function consoleLogShouldNotThrowError(): void { }); // output errors to the console should not include "Uncaught" - mockConsole((console, out): void => { + mockConsole((console, out) => { console.log(new Error("foo")); assertEquals(out.toString().includes("Uncaught"), false); }); }); // console.log(Invalid Date) test -unitTest(function consoleLogShoultNotThrowErrorWhenInvalidDateIsPassed(): void { +unitTest(function consoleLogShoultNotThrowErrorWhenInvalidDateIsPassed() { mockConsole((console, out) => { const invalidDate = new Date("test"); console.log(invalidDate); @@ -1561,39 +1561,39 @@ unitTest(function consoleLogShoultNotThrowErrorWhenInvalidDateIsPassed(): void { }); // console.dir test -unitTest(function consoleDir(): void { - mockConsole((console, out): void => { +unitTest(function consoleDir() { + mockConsole((console, out) => { console.dir("DIR"); assertEquals(out.toString(), "DIR\n"); }); - mockConsole((console, out): void => { + mockConsole((console, out) => { console.dir("DIR", { indentLevel: 2 }); assertEquals(out.toString(), " DIR\n"); }); }); // console.dir test -unitTest(function consoleDirXml(): void { - mockConsole((console, out): void => { +unitTest(function consoleDirXml() { + mockConsole((console, out) => { console.dirxml("DIRXML"); assertEquals(out.toString(), "DIRXML\n"); }); - mockConsole((console, out): void => { + mockConsole((console, out) => { console.dirxml("DIRXML", { indentLevel: 2 }); assertEquals(out.toString(), " DIRXML\n"); }); }); // console.trace test -unitTest(function consoleTrace(): void { - mockConsole((console, _out, err): void => { +unitTest(function consoleTrace() { + mockConsole((console, _out, err) => { console.trace("%s", "custom message"); assert(err); assert(err.toString().includes("Trace: custom message")); }); }); -unitTest(function inspectString(): void { +unitTest(function inspectString() { assertEquals( stripColor(Deno.inspect("\0")), `"\\x00"`, @@ -1604,7 +1604,7 @@ unitTest(function inspectString(): void { ); }); -unitTest(function inspectGetters(): void { +unitTest(function inspectGetters() { assertEquals( stripColor(Deno.inspect({ get foo() { @@ -1633,12 +1633,12 @@ unitTest(function inspectGetters(): void { ); }); -unitTest(function inspectPrototype(): void { +unitTest(function inspectPrototype() { class A {} assertEquals(Deno.inspect(A.prototype), "A {}"); }); -unitTest(function inspectSorted(): void { +unitTest(function inspectSorted() { assertEquals( stripColor(Deno.inspect({ b: 2, a: 1 }, { sorted: true })), "{ a: 1, b: 2 }", @@ -1659,7 +1659,7 @@ unitTest(function inspectSorted(): void { ); }); -unitTest(function inspectTrailingComma(): void { +unitTest(function inspectTrailingComma() { assertEquals( stripColor(Deno.inspect( [ @@ -1714,7 +1714,7 @@ unitTest(function inspectTrailingComma(): void { ); }); -unitTest(function inspectCompact(): void { +unitTest(function inspectCompact() { assertEquals( stripColor(Deno.inspect({ a: 1, b: 2 }, { compact: false })), `{ @@ -1724,7 +1724,7 @@ unitTest(function inspectCompact(): void { ); }); -unitTest(function inspectIterableLimit(): void { +unitTest(function inspectIterableLimit() { assertEquals( stripColor(Deno.inspect(["a", "b", "c"], { iterableLimit: 2 })), `[ "a", "b", ... 1 more items ]`, @@ -1746,7 +1746,7 @@ unitTest(function inspectIterableLimit(): void { ); }); -unitTest(function inspectProxy(): void { +unitTest(function inspectProxy() { assertEquals( stripColor(Deno.inspect( new Proxy([1, 2, 3], {}), @@ -1785,7 +1785,7 @@ unitTest(function inspectProxy(): void { ); assertEquals( stripColor(Deno.inspect( - new Proxy([1, 2, 3], { get(): void {} }), + new Proxy([1, 2, 3], { get() {} }), { showProxy: true }, )), "Proxy [ [ 1, 2, 3 ], { get: [Function: get] } ]", @@ -1803,7 +1803,7 @@ unitTest(function inspectProxy(): void { ); assertEquals( stripColor(Deno.inspect( - new Proxy([1, 2, 3, 4, 5, 6, 7], { get(): void {} }), + new Proxy([1, 2, 3, 4, 5, 6, 7], { get() {} }), { showProxy: true }, )), `Proxy [ [ @@ -1813,14 +1813,14 @@ unitTest(function inspectProxy(): void { ); assertEquals( stripColor(Deno.inspect( - new Proxy(function fn() {}, { get(): void {} }), + new Proxy(function fn() {}, { get() {} }), { showProxy: true }, )), "Proxy [ [Function: fn], { get: [Function: get] } ]", ); }); -unitTest(function inspectColors(): void { +unitTest(function inspectColors() { assertEquals(Deno.inspect(1), "1"); assertStringIncludes(Deno.inspect(1, { colors: true }), "\x1b["); }); diff --git a/cli/tests/unit/copy_file_test.ts b/cli/tests/unit/copy_file_test.ts index 96d08b10e0..f89c1c9ee3 100644 --- a/cli/tests/unit/copy_file_test.ts +++ b/cli/tests/unit/copy_file_test.ts @@ -12,7 +12,7 @@ function readFileString(filename: string | URL): string { return dec.decode(dataRead); } -function writeFileString(filename: string | URL, s: string): void { +function writeFileString(filename: string | URL, s: string) { const enc = new TextEncoder(); const data = enc.encode(s); Deno.writeFileSync(filename, data, { mode: 0o666 }); @@ -21,7 +21,7 @@ function writeFileString(filename: string | URL, s: string): void { function assertSameContent( filename1: string | URL, filename2: string | URL, -): void { +) { const data1 = Deno.readFileSync(filename1); const data2 = Deno.readFileSync(filename2); assertEquals(data1, data2); @@ -29,7 +29,7 @@ function assertSameContent( unitTest( { perms: { read: true, write: true } }, - function copyFileSyncSuccess(): void { + function copyFileSyncSuccess() { const tempDir = Deno.makeTempDirSync(); const fromFilename = tempDir + "/from.txt"; const toFilename = tempDir + "/to.txt"; @@ -46,7 +46,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - function copyFileSyncByUrl(): void { + function copyFileSyncByUrl() { const tempDir = Deno.makeTempDirSync(); const fromUrl = new URL( `file://${Deno.build.os === "windows" ? "/" : ""}${tempDir}/from.txt`, @@ -67,7 +67,7 @@ unitTest( unitTest( { perms: { write: true, read: true } }, - function copyFileSyncFailure(): void { + function copyFileSyncFailure() { const tempDir = Deno.makeTempDirSync(); const fromFilename = tempDir + "/from.txt"; const toFilename = tempDir + "/to.txt"; @@ -82,7 +82,7 @@ unitTest( unitTest( { perms: { write: true, read: false } }, - function copyFileSyncPerm1(): void { + function copyFileSyncPerm1() { assertThrows(() => { Deno.copyFileSync("/from.txt", "/to.txt"); }, Deno.errors.PermissionDenied); @@ -91,7 +91,7 @@ unitTest( unitTest( { perms: { write: false, read: true } }, - function copyFileSyncPerm2(): void { + function copyFileSyncPerm2() { assertThrows(() => { Deno.copyFileSync("/from.txt", "/to.txt"); }, Deno.errors.PermissionDenied); @@ -100,7 +100,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - function copyFileSyncOverwrite(): void { + function copyFileSyncOverwrite() { const tempDir = Deno.makeTempDirSync(); const fromFilename = tempDir + "/from.txt"; const toFilename = tempDir + "/to.txt"; @@ -119,7 +119,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function copyFileSuccess(): Promise { + async function copyFileSuccess() { const tempDir = Deno.makeTempDirSync(); const fromFilename = tempDir + "/from.txt"; const toFilename = tempDir + "/to.txt"; @@ -136,7 +136,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function copyFileByUrl(): Promise { + async function copyFileByUrl() { const tempDir = Deno.makeTempDirSync(); const fromUrl = new URL( `file://${Deno.build.os === "windows" ? "/" : ""}${tempDir}/from.txt`, @@ -157,7 +157,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function copyFileFailure(): Promise { + async function copyFileFailure() { const tempDir = Deno.makeTempDirSync(); const fromFilename = tempDir + "/from.txt"; const toFilename = tempDir + "/to.txt"; @@ -172,7 +172,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function copyFileOverwrite(): Promise { + async function copyFileOverwrite() { const tempDir = Deno.makeTempDirSync(); const fromFilename = tempDir + "/from.txt"; const toFilename = tempDir + "/to.txt"; @@ -191,7 +191,7 @@ unitTest( unitTest( { perms: { read: false, write: true } }, - async function copyFilePerm1(): Promise { + async function copyFilePerm1() { await assertThrowsAsync(async () => { await Deno.copyFile("/from.txt", "/to.txt"); }, Deno.errors.PermissionDenied); @@ -200,7 +200,7 @@ unitTest( unitTest( { perms: { read: true, write: false } }, - async function copyFilePerm2(): Promise { + async function copyFilePerm2() { await assertThrowsAsync(async () => { await Deno.copyFile("/from.txt", "/to.txt"); }, Deno.errors.PermissionDenied); diff --git a/cli/tests/unit/custom_event_test.ts b/cli/tests/unit/custom_event_test.ts index 0db770056e..3b62429969 100644 --- a/cli/tests/unit/custom_event_test.ts +++ b/cli/tests/unit/custom_event_test.ts @@ -1,7 +1,7 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. import { assertEquals, unitTest } from "./test_util.ts"; -unitTest(function customEventInitializedWithDetail(): void { +unitTest(function customEventInitializedWithDetail() { const type = "touchstart"; const detail = { message: "hello" }; const customEventInit = { @@ -20,7 +20,7 @@ unitTest(function customEventInitializedWithDetail(): void { assertEquals(event.type, type); }); -unitTest(function toStringShouldBeWebCompatibility(): void { +unitTest(function toStringShouldBeWebCompatibility() { const type = "touchstart"; const event = new CustomEvent(type, {}); assertEquals(event.toString(), "[object CustomEvent]"); diff --git a/cli/tests/unit/dir_test.ts b/cli/tests/unit/dir_test.ts index e64baf97bf..baed6f6d6e 100644 --- a/cli/tests/unit/dir_test.ts +++ b/cli/tests/unit/dir_test.ts @@ -1,13 +1,13 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. import { assert, assertEquals, assertThrows, unitTest } from "./test_util.ts"; -unitTest({ perms: { read: true } }, function dirCwdNotNull(): void { +unitTest({ perms: { read: true } }, function dirCwdNotNull() { assert(Deno.cwd() != null); }); unitTest( { perms: { read: true, write: true } }, - function dirCwdChdirSuccess(): void { + function dirCwdChdirSuccess() { const initialdir = Deno.cwd(); const path = Deno.makeTempDirSync(); Deno.chdir(path); @@ -21,7 +21,7 @@ unitTest( }, ); -unitTest({ perms: { read: true, write: true } }, function dirCwdError(): void { +unitTest({ perms: { read: true, write: true } }, function dirCwdError() { // excluding windows since it throws resource busy, while removeSync if (["linux", "darwin"].includes(Deno.build.os)) { const initialdir = Deno.cwd(); @@ -38,7 +38,7 @@ unitTest({ perms: { read: true, write: true } }, function dirCwdError(): void { } }); -unitTest({ perms: { read: false } }, function dirCwdPermError(): void { +unitTest({ perms: { read: false } }, function dirCwdPermError() { assertThrows( () => { Deno.cwd(); @@ -50,7 +50,7 @@ unitTest({ perms: { read: false } }, function dirCwdPermError(): void { unitTest( { perms: { read: true, write: true } }, - function dirChdirError(): void { + function dirChdirError() { const path = Deno.makeTempDirSync() + "test"; assertThrows(() => { Deno.chdir(path); diff --git a/cli/tests/unit/dom_exception_test.ts b/cli/tests/unit/dom_exception_test.ts index ea310fc9a8..b5f5b1f87e 100644 --- a/cli/tests/unit/dom_exception_test.ts +++ b/cli/tests/unit/dom_exception_test.ts @@ -1,6 +1,6 @@ import { assertEquals, assertStringIncludes, unitTest } from "./test_util.ts"; -unitTest(function customInspectFunction(): void { +unitTest(function customInspectFunction() { const blob = new DOMException("test"); assertEquals( Deno.inspect(blob), diff --git a/cli/tests/unit/error_stack_test.ts b/cli/tests/unit/error_stack_test.ts index 1445124e94..0da3ff9936 100644 --- a/cli/tests/unit/error_stack_test.ts +++ b/cli/tests/unit/error_stack_test.ts @@ -1,7 +1,7 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. import { assert, assertEquals, assertMatch, unitTest } from "./test_util.ts"; -unitTest(function errorStackMessageLine(): void { +unitTest(function errorStackMessageLine() { const e1 = new Error(); e1.name = "Foo"; e1.message = "bar"; @@ -41,8 +41,8 @@ unitTest(function errorStackMessageLine(): void { assertMatch(e6.stack!, /^null: null\n/); }); -unitTest(function captureStackTrace(): void { - function foo(): void { +unitTest(function captureStackTrace() { + function foo() { const error = new Error(); const stack1 = error.stack!; Error.captureStackTrace(error, foo); @@ -55,7 +55,7 @@ unitTest(function captureStackTrace(): void { // FIXME(bartlomieju): no longer works after migrating // to JavaScript runtime code -unitTest({ ignore: true }, function applySourceMap(): void { +unitTest({ ignore: true }, function applySourceMap() { const result = Deno.applySourceMap({ fileName: "CLI_SNAPSHOT.js", lineNumber: 23, diff --git a/cli/tests/unit/event_target_test.ts b/cli/tests/unit/event_target_test.ts index 29de04c8cb..0d0d891544 100644 --- a/cli/tests/unit/event_target_test.ts +++ b/cli/tests/unit/event_target_test.ts @@ -1,7 +1,7 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. import { assertEquals, unitTest } from "./test_util.ts"; -unitTest(function addEventListenerTest(): void { +unitTest(function addEventListenerTest() { const document = new EventTarget(); assertEquals(document.addEventListener("x", null, false), undefined); @@ -9,12 +9,12 @@ unitTest(function addEventListenerTest(): void { assertEquals(document.addEventListener("x", null), undefined); }); -unitTest(function constructedEventTargetCanBeUsedAsExpected(): void { +unitTest(function constructedEventTargetCanBeUsedAsExpected() { const target = new EventTarget(); const event = new Event("foo", { bubbles: true, cancelable: false }); let callCount = 0; - const listener = (e: Event): void => { + const listener = (e: Event) => { assertEquals(e, event); ++callCount; }; @@ -32,13 +32,13 @@ unitTest(function constructedEventTargetCanBeUsedAsExpected(): void { assertEquals(callCount, 2); }); -unitTest(function anEventTargetCanBeSubclassed(): void { +unitTest(function anEventTargetCanBeSubclassed() { class NicerEventTarget extends EventTarget { on( type: string, callback: ((e: Event) => void) | null, options?: AddEventListenerOptions, - ): void { + ) { this.addEventListener(type, callback, options); } @@ -46,7 +46,7 @@ unitTest(function anEventTargetCanBeSubclassed(): void { type: string, callback: ((e: Event) => void) | null, options?: EventListenerOptions, - ): void { + ) { this.removeEventListener(type, callback, options); } } @@ -55,7 +55,7 @@ unitTest(function anEventTargetCanBeSubclassed(): void { new Event("foo", { bubbles: true, cancelable: false }); let callCount = 0; - const listener = (): void => { + const listener = () => { ++callCount; }; @@ -66,19 +66,19 @@ unitTest(function anEventTargetCanBeSubclassed(): void { assertEquals(callCount, 0); }); -unitTest(function removingNullEventListenerShouldSucceed(): void { +unitTest(function removingNullEventListenerShouldSucceed() { const document = new EventTarget(); assertEquals(document.removeEventListener("x", null, false), undefined); assertEquals(document.removeEventListener("x", null, true), undefined); assertEquals(document.removeEventListener("x", null), undefined); }); -unitTest(function constructedEventTargetUseObjectPrototype(): void { +unitTest(function constructedEventTargetUseObjectPrototype() { const target = new EventTarget(); const event = new Event("toString", { bubbles: true, cancelable: false }); let callCount = 0; - const listener = (e: Event): void => { + const listener = (e: Event) => { assertEquals(e, event); ++callCount; }; @@ -96,12 +96,12 @@ unitTest(function constructedEventTargetUseObjectPrototype(): void { assertEquals(callCount, 2); }); -unitTest(function toStringShouldBeWebCompatible(): void { +unitTest(function toStringShouldBeWebCompatible() { const target = new EventTarget(); assertEquals(target.toString(), "[object EventTarget]"); }); -unitTest(function dispatchEventShouldNotThrowError(): void { +unitTest(function dispatchEventShouldNotThrowError() { let hasThrown = false; try { @@ -110,7 +110,7 @@ unitTest(function dispatchEventShouldNotThrowError(): void { bubbles: true, cancelable: false, }); - const listener = (): void => {}; + const listener = () => {}; target.addEventListener("hasOwnProperty", listener); target.dispatchEvent(event); } catch { @@ -120,7 +120,7 @@ unitTest(function dispatchEventShouldNotThrowError(): void { assertEquals(hasThrown, false); }); -unitTest(function eventTargetThisShouldDefaultToWindow(): void { +unitTest(function eventTargetThisShouldDefaultToWindow() { const { addEventListener, dispatchEvent, @@ -128,7 +128,7 @@ unitTest(function eventTargetThisShouldDefaultToWindow(): void { } = EventTarget.prototype; let n = 1; const event = new Event("hello"); - const listener = (): void => { + const listener = () => { n = 2; }; @@ -149,13 +149,13 @@ unitTest(function eventTargetThisShouldDefaultToWindow(): void { assertEquals(n, 1); }); -unitTest(function eventTargetShouldAcceptEventListenerObject(): void { +unitTest(function eventTargetShouldAcceptEventListenerObject() { const target = new EventTarget(); const event = new Event("foo", { bubbles: true, cancelable: false }); let callCount = 0; const listener = { - handleEvent(e: Event): void { + handleEvent(e: Event) { assertEquals(e, event); ++callCount; }, @@ -174,12 +174,12 @@ unitTest(function eventTargetShouldAcceptEventListenerObject(): void { assertEquals(callCount, 2); }); -unitTest(function eventTargetShouldAcceptAsyncFunction(): void { +unitTest(function eventTargetShouldAcceptAsyncFunction() { const target = new EventTarget(); const event = new Event("foo", { bubbles: true, cancelable: false }); let callCount = 0; - const listener = (e: Event): void => { + const listener = (e: Event) => { assertEquals(e, event); ++callCount; }; @@ -198,13 +198,13 @@ unitTest(function eventTargetShouldAcceptAsyncFunction(): void { }); unitTest( - function eventTargetShouldAcceptAsyncFunctionForEventListenerObject(): void { + function eventTargetShouldAcceptAsyncFunctionForEventListenerObject() { const target = new EventTarget(); const event = new Event("foo", { bubbles: true, cancelable: false }); let callCount = 0; const listener = { - handleEvent(e: Event): void { + handleEvent(e: Event) { assertEquals(e, event); ++callCount; }, @@ -223,7 +223,7 @@ unitTest( assertEquals(callCount, 2); }, ); -unitTest(function eventTargetDispatchShouldSetTargetNoListener(): void { +unitTest(function eventTargetDispatchShouldSetTargetNoListener() { const target = new EventTarget(); const event = new Event("foo"); assertEquals(event.target, null); @@ -231,7 +231,7 @@ unitTest(function eventTargetDispatchShouldSetTargetNoListener(): void { assertEquals(event.target, target); }); -unitTest(function eventTargetDispatchShouldSetTargetInListener(): void { +unitTest(function eventTargetDispatchShouldSetTargetInListener() { const target = new EventTarget(); const event = new Event("foo"); assertEquals(event.target, null); diff --git a/cli/tests/unit/event_test.ts b/cli/tests/unit/event_test.ts index c7cd2f58d7..13f2590ced 100644 --- a/cli/tests/unit/event_test.ts +++ b/cli/tests/unit/event_test.ts @@ -6,7 +6,7 @@ import { unitTest, } from "./test_util.ts"; -unitTest(function eventInitializedWithType(): void { +unitTest(function eventInitializedWithType() { const type = "click"; const event = new Event(type); @@ -18,7 +18,7 @@ unitTest(function eventInitializedWithType(): void { assertEquals(event.cancelable, false); }); -unitTest(function eventInitializedWithTypeAndDict(): void { +unitTest(function eventInitializedWithTypeAndDict() { const init = "submit"; const eventInit = { bubbles: true, cancelable: true } as EventInit; const event = new Event(init, eventInit); @@ -31,7 +31,7 @@ unitTest(function eventInitializedWithTypeAndDict(): void { assertEquals(event.cancelable, true); }); -unitTest(function eventComposedPathSuccess(): void { +unitTest(function eventComposedPathSuccess() { const type = "click"; const event = new Event(type); const composedPath = event.composedPath(); @@ -39,7 +39,7 @@ unitTest(function eventComposedPathSuccess(): void { assertEquals(composedPath, []); }); -unitTest(function eventStopPropagationSuccess(): void { +unitTest(function eventStopPropagationSuccess() { const type = "click"; const event = new Event(type); @@ -48,7 +48,7 @@ unitTest(function eventStopPropagationSuccess(): void { assertEquals(event.cancelBubble, true); }); -unitTest(function eventStopImmediatePropagationSuccess(): void { +unitTest(function eventStopImmediatePropagationSuccess() { const type = "click"; const event = new Event(type); @@ -57,7 +57,7 @@ unitTest(function eventStopImmediatePropagationSuccess(): void { assertEquals(event.cancelBubble, true); }); -unitTest(function eventPreventDefaultSuccess(): void { +unitTest(function eventPreventDefaultSuccess() { const type = "click"; const event = new Event(type); @@ -72,7 +72,7 @@ unitTest(function eventPreventDefaultSuccess(): void { assertEquals(cancelableEvent.defaultPrevented, true); }); -unitTest(function eventInitializedWithNonStringType(): void { +unitTest(function eventInitializedWithNonStringType() { // deno-lint-ignore no-explicit-any const type: any = undefined; const event = new Event(type); @@ -86,7 +86,7 @@ unitTest(function eventInitializedWithNonStringType(): void { }); // ref https://github.com/web-platform-tests/wpt/blob/master/dom/events/Event-isTrusted.any.js -unitTest(function eventIsTrusted(): void { +unitTest(function eventIsTrusted() { const desc1 = Object.getOwnPropertyDescriptor(new Event("x"), "isTrusted"); assert(desc1); assertEquals(typeof desc1.get, "function"); @@ -98,7 +98,7 @@ unitTest(function eventIsTrusted(): void { assertEquals(desc1!.get, desc2!.get); }); -unitTest(function eventInspectOutput(): void { +unitTest(function eventInspectOutput() { // deno-lint-ignore no-explicit-any const cases: Array<[any, (event: any) => string]> = [ [ @@ -133,7 +133,7 @@ unitTest(function eventInspectOutput(): void { } }); -unitTest(function inspectEvent(): void { +unitTest(function inspectEvent() { // has a customInspect implementation that previously would throw on a getter assertEquals( Deno.inspect(Event.prototype), diff --git a/cli/tests/unit/fetch_test.ts b/cli/tests/unit/fetch_test.ts index 45ab2d12cb..24825c6537 100644 --- a/cli/tests/unit/fetch_test.ts +++ b/cli/tests/unit/fetch_test.ts @@ -12,7 +12,7 @@ import { Buffer } from "../../../test_util/std/io/buffer.ts"; unitTest( { perms: { net: true } }, - async function fetchRequiresOneArgument(): Promise { + async function fetchRequiresOneArgument() { await assertThrowsAsync( fetch as unknown as () => Promise, TypeError, @@ -20,11 +20,9 @@ unitTest( }, ); -unitTest({ perms: { net: true } }, async function fetchProtocolError(): Promise< - void -> { +unitTest({ perms: { net: true } }, async function fetchProtocolError() { await assertThrowsAsync( - async (): Promise => { + async () => { await fetch("file:///"); }, TypeError, @@ -58,10 +56,10 @@ function findClosedPortInRange( unitTest( { perms: { net: true } }, - async function fetchConnectionError(): Promise { + async function fetchConnectionError() { const port = findClosedPortInRange(4000, 9999); await assertThrowsAsync( - async (): Promise => { + async () => { await fetch(`http://localhost:${port}`); }, TypeError, @@ -72,9 +70,9 @@ unitTest( unitTest( { perms: { net: true } }, - async function fetchDnsError(): Promise { + async function fetchDnsError() { await assertThrowsAsync( - async (): Promise => { + async () => { await fetch("http://nil/"); }, TypeError, @@ -85,9 +83,9 @@ unitTest( unitTest( { perms: { net: true } }, - async function fetchInvalidUriError(): Promise { + async function fetchInvalidUriError() { await assertThrowsAsync( - async (): Promise => { + async () => { await fetch("http:///"); }, TypeError, @@ -95,27 +93,25 @@ unitTest( }, ); -unitTest({ perms: { net: true } }, async function fetchJsonSuccess(): Promise< - void -> { +unitTest({ perms: { net: true } }, async function fetchJsonSuccess() { const response = await fetch("http://localhost:4545/cli/tests/fixture.json"); const json = await response.json(); assertEquals(json.name, "deno"); }); -unitTest(async function fetchPerm(): Promise { +unitTest(async function fetchPerm() { await assertThrowsAsync(async () => { await fetch("http://localhost:4545/cli/tests/fixture.json"); }, Deno.errors.PermissionDenied); }); -unitTest({ perms: { net: true } }, async function fetchUrl(): Promise { +unitTest({ perms: { net: true } }, async function fetchUrl() { const response = await fetch("http://localhost:4545/cli/tests/fixture.json"); assertEquals(response.url, "http://localhost:4545/cli/tests/fixture.json"); const _json = await response.json(); }); -unitTest({ perms: { net: true } }, async function fetchURL(): Promise { +unitTest({ perms: { net: true } }, async function fetchURL() { const response = await fetch( new URL("http://localhost:4545/cli/tests/fixture.json"), ); @@ -123,16 +119,14 @@ unitTest({ perms: { net: true } }, async function fetchURL(): Promise { const _json = await response.json(); }); -unitTest({ perms: { net: true } }, async function fetchHeaders(): Promise< - void -> { +unitTest({ perms: { net: true } }, async function fetchHeaders() { const response = await fetch("http://localhost:4545/cli/tests/fixture.json"); const headers = response.headers; assertEquals(headers.get("Content-Type"), "application/json"); const _json = await response.json(); }); -unitTest({ perms: { net: true } }, async function fetchBlob(): Promise { +unitTest({ perms: { net: true } }, async function fetchBlob() { const response = await fetch("http://localhost:4545/cli/tests/fixture.json"); const headers = response.headers; const blob = await response.blob(); @@ -142,7 +136,7 @@ unitTest({ perms: { net: true } }, async function fetchBlob(): Promise { unitTest( { perms: { net: true } }, - async function fetchBodyUsedReader(): Promise { + async function fetchBodyUsedReader() { const response = await fetch( "http://localhost:4545/cli/tests/fixture.json", ); @@ -160,7 +154,7 @@ unitTest( unitTest( { perms: { net: true } }, - async function fetchBodyUsedCancelStream(): Promise { + async function fetchBodyUsedCancelStream() { const response = await fetch( "http://localhost:4545/cli/tests/fixture.json", ); @@ -173,9 +167,7 @@ unitTest( }, ); -unitTest({ perms: { net: true } }, async function fetchAsyncIterator(): Promise< - void -> { +unitTest({ perms: { net: true } }, async function fetchAsyncIterator() { const response = await fetch("http://localhost:4545/cli/tests/fixture.json"); const headers = response.headers; @@ -189,9 +181,7 @@ unitTest({ perms: { net: true } }, async function fetchAsyncIterator(): Promise< assertEquals(total, Number(headers.get("Content-Length"))); }); -unitTest({ perms: { net: true } }, async function fetchBodyReader(): Promise< - void -> { +unitTest({ perms: { net: true } }, async function fetchBodyReader() { const response = await fetch("http://localhost:4545/cli/tests/fixture.json"); const headers = response.headers; assert(response.body !== null); @@ -210,7 +200,7 @@ unitTest({ perms: { net: true } }, async function fetchBodyReader(): Promise< unitTest( { perms: { net: true } }, - async function fetchBodyReaderBigBody(): Promise { + async function fetchBodyReaderBigBody() { const data = "a".repeat(10 << 10); // 10mb const response = await fetch("http://localhost:4545/echo_server", { method: "POST", @@ -230,9 +220,7 @@ unitTest( }, ); -unitTest({ perms: { net: true } }, async function responseClone(): Promise< - void -> { +unitTest({ perms: { net: true } }, async function responseClone() { const response = await fetch("http://localhost:4545/cli/tests/fixture.json"); const response1 = response.clone(); assert(response !== response1); @@ -247,7 +235,7 @@ unitTest({ perms: { net: true } }, async function responseClone(): Promise< unitTest( { perms: { net: true } }, - async function fetchMultipartFormDataSuccess(): Promise { + async function fetchMultipartFormDataSuccess() { const response = await fetch( "http://localhost:4545/multipart_form_data.txt", ); @@ -264,14 +252,14 @@ unitTest( unitTest( { perms: { net: true } }, - async function fetchMultipartFormBadContentType(): Promise { + async function fetchMultipartFormBadContentType() { const response = await fetch( "http://localhost:4545/multipart_form_bad_content_type", ); assert(response.body !== null); await assertThrowsAsync( - async (): Promise => { + async () => { await response.formData(); }, TypeError, @@ -282,7 +270,7 @@ unitTest( unitTest( { perms: { net: true } }, - async function fetchURLEncodedFormDataSuccess(): Promise { + async function fetchURLEncodedFormDataSuccess() { const response = await fetch( "http://localhost:4545/cli/tests/subdir/form_urlencoded.txt", ); @@ -296,7 +284,7 @@ unitTest( unitTest( { perms: { net: true } }, - async function fetchInitFormDataBinaryFileBody(): Promise { + async function fetchInitFormDataBinaryFileBody() { // Some random bytes // deno-fmt-ignore const binaryFile = new Uint8Array([108,2,0,0,145,22,162,61,157,227,166,77,138,75,180,56,119,188,177,183]); @@ -315,7 +303,7 @@ unitTest( unitTest( { perms: { net: true } }, - async function fetchInitFormDataMultipleFilesBody(): Promise { + async function fetchInitFormDataMultipleFilesBody() { const files = [ { // deno-fmt-ignore @@ -371,7 +359,7 @@ unitTest( { perms: { net: true }, }, - async function fetchWithRedirection(): Promise { + async function fetchWithRedirection() { const response = await fetch("http://localhost:4546/README.md"); assertEquals(response.status, 200); assertEquals(response.statusText, "OK"); @@ -385,7 +373,7 @@ unitTest( { perms: { net: true }, }, - async function fetchWithRelativeRedirection(): Promise { + async function fetchWithRelativeRedirection() { const response = await fetch( "http://localhost:4545/cli/tests/001_hello.js", ); @@ -400,7 +388,7 @@ unitTest( { perms: { net: true }, }, - async function fetchWithRelativeRedirectionUrl(): Promise { + async function fetchWithRelativeRedirectionUrl() { const cases = [ ["end", "http://localhost:4550/a/b/end"], ["/end", "http://localhost:4550/end"], @@ -421,7 +409,7 @@ unitTest( { perms: { net: true }, }, - async function fetchWithInfRedirection(): Promise { + async function fetchWithInfRedirection() { await assertThrowsAsync( () => fetch("http://localhost:4549/cli/tests"), TypeError, @@ -432,7 +420,7 @@ unitTest( unitTest( { perms: { net: true } }, - async function fetchInitStringBody(): Promise { + async function fetchInitStringBody() { const data = "Hello World"; const response = await fetch("http://localhost:4545/echo_server", { method: "POST", @@ -446,7 +434,7 @@ unitTest( unitTest( { perms: { net: true } }, - async function fetchRequestInitStringBody(): Promise { + async function fetchRequestInitStringBody() { const data = "Hello World"; const req = new Request("http://localhost:4545/echo_server", { method: "POST", @@ -460,7 +448,7 @@ unitTest( unitTest( { perms: { net: true } }, - async function fetchSeparateInit(): Promise { + async function fetchSeparateInit() { // related to: https://github.com/denoland/deno/issues/10396 const req = new Request("http://localhost:4545/cli/tests/001_hello.js"); const init = { @@ -475,7 +463,7 @@ unitTest( unitTest( { perms: { net: true } }, - async function fetchInitTypedArrayBody(): Promise { + async function fetchInitTypedArrayBody() { const data = "Hello World"; const response = await fetch("http://localhost:4545/echo_server", { method: "POST", @@ -488,7 +476,7 @@ unitTest( unitTest( { perms: { net: true } }, - async function fetchInitArrayBufferBody(): Promise { + async function fetchInitArrayBufferBody() { const data = "Hello World"; const response = await fetch("http://localhost:4545/echo_server", { method: "POST", @@ -501,7 +489,7 @@ unitTest( unitTest( { perms: { net: true } }, - async function fetchInitURLSearchParamsBody(): Promise { + async function fetchInitURLSearchParamsBody() { const data = "param1=value1¶m2=value2"; const params = new URLSearchParams(data); const response = await fetch("http://localhost:4545/echo_server", { @@ -518,9 +506,7 @@ unitTest( }, ); -unitTest({ perms: { net: true } }, async function fetchInitBlobBody(): Promise< - void -> { +unitTest({ perms: { net: true } }, async function fetchInitBlobBody() { const data = "const a = 1"; const blob = new Blob([data], { type: "text/javascript", @@ -536,7 +522,7 @@ unitTest({ perms: { net: true } }, async function fetchInitBlobBody(): Promise< unitTest( { perms: { net: true } }, - async function fetchInitFormDataBody(): Promise { + async function fetchInitFormDataBody() { const form = new FormData(); form.append("field", "value"); const response = await fetch("http://localhost:4545/echo_server", { @@ -550,7 +536,7 @@ unitTest( unitTest( { perms: { net: true } }, - async function fetchInitFormDataBlobFilenameBody(): Promise { + async function fetchInitFormDataBlobFilenameBody() { const form = new FormData(); form.append("field", "value"); form.append("file", new Blob([new TextEncoder().encode("deno")])); @@ -568,7 +554,7 @@ unitTest( unitTest( { perms: { net: true } }, - async function fetchInitFormDataTextFileBody(): Promise { + async function fetchInitFormDataTextFileBody() { const fileContent = "deno land"; const form = new FormData(); form.append("field", "value"); @@ -596,9 +582,7 @@ unitTest( }, ); -unitTest({ perms: { net: true } }, async function fetchUserAgent(): Promise< - void -> { +unitTest({ perms: { net: true } }, async function fetchUserAgent() { const data = "Hello World"; const response = await fetch("http://localhost:4545/echo_server", { method: "POST", @@ -658,7 +642,7 @@ unitTest( { perms: { net: true }, }, - async function fetchRequest(): Promise { + async function fetchRequest() { const addr = "127.0.0.1:4501"; const buf = bufferServer(addr); const response = await fetch(`http://${addr}/blah`, { @@ -690,7 +674,7 @@ unitTest( { perms: { net: true }, }, - async function fetchPostBodyString(): Promise { + async function fetchPostBodyString() { const addr = "127.0.0.1:4502"; const buf = bufferServer(addr); const body = "hello world"; @@ -727,7 +711,7 @@ unitTest( { perms: { net: true }, }, - async function fetchPostBodyTypedArray(): Promise { + async function fetchPostBodyTypedArray() { const addr = "127.0.0.1:4503"; const buf = bufferServer(addr); const bodyStr = "hello world"; @@ -764,7 +748,7 @@ unitTest( { perms: { net: true }, }, - async function fetchWithNonAsciiRedirection(): Promise { + async function fetchWithNonAsciiRedirection() { const response = await fetch("http://localhost:4545/non_ascii_redirect", { redirect: "manual", }); @@ -778,7 +762,7 @@ unitTest( { perms: { net: true }, }, - async function fetchWithManualRedirection(): Promise { + async function fetchWithManualRedirection() { const response = await fetch("http://localhost:4546/", { redirect: "manual", }); // will redirect to http://localhost:4545/ @@ -794,7 +778,7 @@ unitTest( { perms: { net: true }, }, - async function fetchWithErrorRedirection(): Promise { + async function fetchWithErrorRedirection() { await assertThrowsAsync( () => fetch("http://localhost:4546/", { @@ -806,7 +790,7 @@ unitTest( }, ); -unitTest(function responseRedirect(): void { +unitTest(function responseRedirect() { const redir = Response.redirect("example.com/newLocation", 301); assertEquals(redir.status, 301); assertEquals(redir.statusText, ""); @@ -818,7 +802,7 @@ unitTest(function responseRedirect(): void { assertEquals(redir.type, "default"); }); -unitTest(async function responseWithoutBody(): Promise { +unitTest(async function responseWithoutBody() { const response = new Response(); assertEquals(await response.arrayBuffer(), new ArrayBuffer(0)); const blob = await response.blob(); @@ -830,9 +814,7 @@ unitTest(async function responseWithoutBody(): Promise { }); }); -unitTest({ perms: { net: true } }, async function fetchBodyReadTwice(): Promise< - void -> { +unitTest({ perms: { net: true } }, async function fetchBodyReadTwice() { const response = await fetch("http://localhost:4545/cli/tests/fixture.json"); // Read body @@ -855,7 +837,7 @@ unitTest({ perms: { net: true } }, async function fetchBodyReadTwice(): Promise< unitTest( { perms: { net: true } }, - async function fetchBodyReaderAfterRead(): Promise { + async function fetchBodyReaderAfterRead() { const response = await fetch( "http://localhost:4545/cli/tests/fixture.json", ); @@ -878,7 +860,7 @@ unitTest( unitTest( { perms: { net: true } }, - async function fetchBodyReaderWithCancelAndNewReader(): Promise { + async function fetchBodyReaderWithCancelAndNewReader() { const data = "a".repeat(1 << 10); const response = await fetch("http://localhost:4545/echo_server", { method: "POST", @@ -906,7 +888,7 @@ unitTest( unitTest( { perms: { net: true } }, - async function fetchBodyReaderWithReadCancelAndNewReader(): Promise { + async function fetchBodyReaderWithReadCancelAndNewReader() { const data = "a".repeat(1 << 10); const response = await fetch("http://localhost:4545/echo_server", { @@ -936,7 +918,7 @@ unitTest( unitTest( { perms: { net: true } }, - async function fetchResourceCloseAfterStreamCancel(): Promise { + async function fetchResourceCloseAfterStreamCancel() { const res = await fetch("http://localhost:4545/cli/tests/fixture.json"); assert(res.body !== null); @@ -954,7 +936,7 @@ unitTest( // the software in your host machine. (os error 10053) unitTest( { perms: { net: true }, ignore: Deno.build.os == "windows" }, - async function fetchNullBodyStatus(): Promise { + async function fetchNullBodyStatus() { const nullBodyStatus = [101, 204, 205, 304]; for (const status of nullBodyStatus) { @@ -972,7 +954,7 @@ unitTest( unitTest( { perms: { net: true } }, - async function fetchResponseContentLength(): Promise { + async function fetchResponseContentLength() { const body = new Uint8Array(2 ** 16); const headers = new Headers([["content-type", "application/octet-stream"]]); const res = await fetch("http://localhost:4545/echo_server", { @@ -989,7 +971,7 @@ unitTest( }, ); -unitTest(function fetchResponseConstructorNullBody(): void { +unitTest(function fetchResponseConstructorNullBody() { const nullBodyStatus = [204, 205, 304]; for (const status of nullBodyStatus) { @@ -1006,7 +988,7 @@ unitTest(function fetchResponseConstructorNullBody(): void { } }); -unitTest(function fetchResponseConstructorInvalidStatus(): void { +unitTest(function fetchResponseConstructorInvalidStatus() { const invalidStatus = [101, 600, 199, null, "", NaN]; for (const status of invalidStatus) { @@ -1022,7 +1004,7 @@ unitTest(function fetchResponseConstructorInvalidStatus(): void { } }); -unitTest(function fetchResponseEmptyConstructor(): void { +unitTest(function fetchResponseEmptyConstructor() { const response = new Response(); assertEquals(response.status, 200); assertEquals(response.body, null); @@ -1099,7 +1081,7 @@ unitTest( { perms: { net: true }, }, - async function fetchPostBodyReadableStream(): Promise { + async function fetchPostBodyReadableStream() { const addr = "127.0.0.1:4502"; const buf = bufferServer(addr); const stream = new TransformStream(); @@ -1143,7 +1125,7 @@ unitTest( }, ); -unitTest({}, function fetchWritableRespProps(): void { +unitTest({}, function fetchWritableRespProps() { const original = new Response("https://deno.land", { status: 404, headers: { "x-deno": "foo" }, diff --git a/cli/tests/unit/file_test.ts b/cli/tests/unit/file_test.ts index f4bb0bb4de..52dd1365e9 100644 --- a/cli/tests/unit/file_test.ts +++ b/cli/tests/unit/file_test.ts @@ -2,7 +2,7 @@ import { assert, assertEquals, unitTest } from "./test_util.ts"; // deno-lint-ignore no-explicit-any -function testFirstArgument(arg1: any[], expectedSize: number): void { +function testFirstArgument(arg1: any[], expectedSize: number) { const file = new File(arg1, "name"); assert(file instanceof File); assertEquals(file.name, "name"); @@ -10,47 +10,47 @@ function testFirstArgument(arg1: any[], expectedSize: number): void { assertEquals(file.type, ""); } -unitTest(function fileEmptyFileBits(): void { +unitTest(function fileEmptyFileBits() { testFirstArgument([], 0); }); -unitTest(function fileStringFileBits(): void { +unitTest(function fileStringFileBits() { testFirstArgument(["bits"], 4); }); -unitTest(function fileUnicodeStringFileBits(): void { +unitTest(function fileUnicodeStringFileBits() { testFirstArgument(["𝓽𝓮𝔁𝓽"], 16); }); -unitTest(function fileStringObjectFileBits(): void { +unitTest(function fileStringObjectFileBits() { testFirstArgument([new String("string object")], 13); }); -unitTest(function fileEmptyBlobFileBits(): void { +unitTest(function fileEmptyBlobFileBits() { testFirstArgument([new Blob()], 0); }); -unitTest(function fileBlobFileBits(): void { +unitTest(function fileBlobFileBits() { testFirstArgument([new Blob(["bits"])], 4); }); -unitTest(function fileEmptyFileFileBits(): void { +unitTest(function fileEmptyFileFileBits() { testFirstArgument([new File([], "world.txt")], 0); }); -unitTest(function fileFileFileBits(): void { +unitTest(function fileFileFileBits() { testFirstArgument([new File(["bits"], "world.txt")], 4); }); -unitTest(function fileArrayBufferFileBits(): void { +unitTest(function fileArrayBufferFileBits() { testFirstArgument([new ArrayBuffer(8)], 8); }); -unitTest(function fileTypedArrayFileBits(): void { +unitTest(function fileTypedArrayFileBits() { testFirstArgument([new Uint8Array([0x50, 0x41, 0x53, 0x53])], 4); }); -unitTest(function fileVariousFileBits(): void { +unitTest(function fileVariousFileBits() { testFirstArgument( [ "bits", @@ -64,45 +64,45 @@ unitTest(function fileVariousFileBits(): void { ); }); -unitTest(function fileNumberInFileBits(): void { +unitTest(function fileNumberInFileBits() { testFirstArgument([12], 2); }); -unitTest(function fileArrayInFileBits(): void { +unitTest(function fileArrayInFileBits() { testFirstArgument([[1, 2, 3]], 5); }); -unitTest(function fileObjectInFileBits(): void { +unitTest(function fileObjectInFileBits() { // "[object Object]" testFirstArgument([{}], 15); }); // deno-lint-ignore no-explicit-any -function testSecondArgument(arg2: any, expectedFileName: string): void { +function testSecondArgument(arg2: any, expectedFileName: string) { const file = new File(["bits"], arg2); assert(file instanceof File); assertEquals(file.name, expectedFileName); } -unitTest(function fileUsingFileName(): void { +unitTest(function fileUsingFileName() { testSecondArgument("dummy", "dummy"); }); -unitTest(function fileUsingNullFileName(): void { +unitTest(function fileUsingNullFileName() { testSecondArgument(null, "null"); }); -unitTest(function fileUsingNumberFileName(): void { +unitTest(function fileUsingNumberFileName() { testSecondArgument(1, "1"); }); -unitTest(function fileUsingEmptyStringFileName(): void { +unitTest(function fileUsingEmptyStringFileName() { testSecondArgument("", ""); }); unitTest( { perms: { read: true, write: true } }, - function fileTruncateSyncSuccess(): void { + function fileTruncateSyncSuccess() { const filename = Deno.makeTempDirSync() + "/test_fileTruncateSync.txt"; const file = Deno.openSync(filename, { create: true, @@ -124,7 +124,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function fileTruncateSuccess(): Promise { + async function fileTruncateSuccess() { const filename = Deno.makeTempDirSync() + "/test_fileTruncate.txt"; const file = await Deno.open(filename, { create: true, @@ -144,7 +144,7 @@ unitTest( }, ); -unitTest({ perms: { read: true } }, function fileStatSyncSuccess(): void { +unitTest({ perms: { read: true } }, function fileStatSyncSuccess() { const file = Deno.openSync("README.md"); const fileInfo = file.statSync(); assert(fileInfo.isFile); @@ -159,9 +159,7 @@ unitTest({ perms: { read: true } }, function fileStatSyncSuccess(): void { file.close(); }); -unitTest({ perms: { read: true } }, async function fileStatSuccess(): Promise< - void -> { +unitTest({ perms: { read: true } }, async function fileStatSuccess() { const file = await Deno.open("README.md"); const fileInfo = await file.stat(); assert(fileInfo.isFile); diff --git a/cli/tests/unit/filereader_test.ts b/cli/tests/unit/filereader_test.ts index eb1f114754..bc9beab70c 100644 --- a/cli/tests/unit/filereader_test.ts +++ b/cli/tests/unit/filereader_test.ts @@ -1,7 +1,7 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. import { assertEquals, unitTest } from "./test_util.ts"; -unitTest(function fileReaderConstruct(): void { +unitTest(function fileReaderConstruct() { const fr = new FileReader(); assertEquals(fr.readyState, FileReader.EMPTY); @@ -10,7 +10,7 @@ unitTest(function fileReaderConstruct(): void { assertEquals(FileReader.DONE, 2); }); -unitTest(async function fileReaderLoadBlob(): Promise { +unitTest(async function fileReaderLoadBlob() { await new Promise((resolve) => { const fr = new FileReader(); const b1 = new Blob(["Hello World"]); @@ -44,18 +44,18 @@ unitTest(async function fileReaderLoadBlob(): Promise { hasDispatchedEvents.progress += 1; }); - fr.onloadstart = (): void => { + fr.onloadstart = () => { hasOnEvents.loadstart = true; }; - fr.onprogress = (): void => { + fr.onprogress = () => { assertEquals(fr.readyState, FileReader.LOADING); hasOnEvents.progress += 1; }; - fr.onload = (): void => { + fr.onload = () => { hasOnEvents.load = true; }; - fr.onloadend = (ev): void => { + fr.onloadend = (ev) => { hasOnEvents.loadend = true; result = fr.result as string; @@ -77,7 +77,7 @@ unitTest(async function fileReaderLoadBlob(): Promise { }); }); -unitTest(async function fileReaderLoadBlobDouble(): Promise { +unitTest(async function fileReaderLoadBlobDouble() { // impl note from https://w3c.github.io/FileAPI/ // Event handler for the load or error events could have started another load, // if that happens the loadend event for the first load is not fired @@ -89,7 +89,7 @@ unitTest(async function fileReaderLoadBlobDouble(): Promise { await new Promise((resolve) => { let result: string | null = null; - fr.onload = (): void => { + fr.onload = () => { result = fr.result as string; assertEquals(result === "First load" || result === "Second load", true); @@ -97,7 +97,7 @@ unitTest(async function fileReaderLoadBlobDouble(): Promise { fr.readAsText(b2); } }; - fr.onloadend = (): void => { + fr.onloadend = () => { assertEquals(result, "Second load"); resolve(); @@ -107,13 +107,13 @@ unitTest(async function fileReaderLoadBlobDouble(): Promise { }); }); -unitTest(async function fileReaderLoadBlobArrayBuffer(): Promise { +unitTest(async function fileReaderLoadBlobArrayBuffer() { await new Promise((resolve) => { const fr = new FileReader(); const b1 = new Blob(["Hello World"]); let result: ArrayBuffer | null = null; - fr.onloadend = (ev): void => { + fr.onloadend = (ev) => { assertEquals(fr.result instanceof ArrayBuffer, true); result = fr.result as ArrayBuffer; @@ -129,13 +129,13 @@ unitTest(async function fileReaderLoadBlobArrayBuffer(): Promise { }); }); -unitTest(async function fileReaderLoadBlobDataUrl(): Promise { +unitTest(async function fileReaderLoadBlobDataUrl() { await new Promise((resolve) => { const fr = new FileReader(); const b1 = new Blob(["Hello World"]); let result: string | null = null; - fr.onloadend = (ev): void => { + fr.onloadend = (ev) => { result = fr.result as string; assertEquals( result, @@ -149,7 +149,7 @@ unitTest(async function fileReaderLoadBlobDataUrl(): Promise { }); }); -unitTest(async function fileReaderLoadBlobAbort(): Promise { +unitTest(async function fileReaderLoadBlobAbort() { await new Promise((resolve) => { const fr = new FileReader(); const b1 = new Blob(["Hello World"]); @@ -160,10 +160,10 @@ unitTest(async function fileReaderLoadBlobAbort(): Promise { abort: false, }; - fr.onload = (): void => { + fr.onload = () => { hasOnEvents.load = true; }; - fr.onloadend = (ev): void => { + fr.onloadend = (ev) => { hasOnEvents.loadend = true; assertEquals(hasOnEvents.load, false); @@ -175,7 +175,7 @@ unitTest(async function fileReaderLoadBlobAbort(): Promise { assertEquals(ev.lengthComputable, false); resolve(); }; - fr.onabort = (): void => { + fr.onabort = () => { hasOnEvents.abort = true; }; @@ -184,7 +184,7 @@ unitTest(async function fileReaderLoadBlobAbort(): Promise { }); }); -unitTest(async function fileReaderLoadBlobAbort(): Promise { +unitTest(async function fileReaderLoadBlobAbort() { await new Promise((resolve) => { const fr = new FileReader(); const b1 = new Blob(["Hello World"]); @@ -195,10 +195,10 @@ unitTest(async function fileReaderLoadBlobAbort(): Promise { abort: false, }; - fr.onload = (): void => { + fr.onload = () => { hasOnEvents.load = true; }; - fr.onloadend = (ev): void => { + fr.onloadend = (ev) => { hasOnEvents.loadend = true; assertEquals(hasOnEvents.load, false); @@ -210,7 +210,7 @@ unitTest(async function fileReaderLoadBlobAbort(): Promise { assertEquals(ev.lengthComputable, false); resolve(); }; - fr.onabort = (): void => { + fr.onabort = () => { hasOnEvents.abort = true; }; @@ -220,7 +220,7 @@ unitTest(async function fileReaderLoadBlobAbort(): Promise { }); unitTest( - async function fileReaderDispatchesEventsInCorrectOrder(): Promise { + async function fileReaderDispatchesEventsInCorrectOrder() { await new Promise((resolve) => { const fr = new FileReader(); const b1 = new Blob(["Hello World"]); @@ -228,7 +228,7 @@ unitTest( fr.addEventListener("loadend", () => { out += "1"; }); - fr.onloadend = (_ev): void => { + fr.onloadend = (_ev) => { out += "2"; }; fr.addEventListener("loadend", () => { diff --git a/cli/tests/unit/files_test.ts b/cli/tests/unit/files_test.ts index 348d012b42..a409434c1d 100644 --- a/cli/tests/unit/files_test.ts +++ b/cli/tests/unit/files_test.ts @@ -10,15 +10,13 @@ import { } from "./test_util.ts"; import { copy } from "../../../test_util/std/io/util.ts"; -unitTest(function filesStdioFileDescriptors(): void { +unitTest(function filesStdioFileDescriptors() { assertEquals(Deno.stdin.rid, 0); assertEquals(Deno.stdout.rid, 1); assertEquals(Deno.stderr.rid, 2); }); -unitTest({ perms: { read: true } }, async function filesCopyToStdout(): Promise< - void -> { +unitTest({ perms: { read: true } }, async function filesCopyToStdout() { const filename = "cli/tests/fixture.json"; const file = await Deno.open(filename); assert(file.rid > 2); @@ -28,7 +26,7 @@ unitTest({ perms: { read: true } }, async function filesCopyToStdout(): Promise< file.close(); }); -unitTest({ perms: { read: true } }, async function filesIter(): Promise { +unitTest({ perms: { read: true } }, async function filesIter() { const filename = "cli/tests/hello.txt"; const file = await Deno.open(filename); @@ -43,7 +41,7 @@ unitTest({ perms: { read: true } }, async function filesIter(): Promise { unitTest( { perms: { read: true } }, - async function filesIterCustomBufSize(): Promise { + async function filesIterCustomBufSize() { const filename = "cli/tests/hello.txt"; const file = await Deno.open(filename); @@ -60,7 +58,7 @@ unitTest( }, ); -unitTest({ perms: { read: true } }, function filesIterSync(): void { +unitTest({ perms: { read: true } }, function filesIterSync() { const filename = "cli/tests/hello.txt"; const file = Deno.openSync(filename); @@ -75,7 +73,7 @@ unitTest({ perms: { read: true } }, function filesIterSync(): void { unitTest( { perms: { read: true } }, - function filesIterSyncCustomBufSize(): void { + function filesIterSyncCustomBufSize() { const filename = "cli/tests/hello.txt"; const file = Deno.openSync(filename); @@ -92,7 +90,7 @@ unitTest( }, ); -unitTest(async function readerIter(): Promise { +unitTest(async function readerIter() { // ref: https://github.com/denoland/deno/issues/2330 const encoder = new TextEncoder(); @@ -127,7 +125,7 @@ unitTest(async function readerIter(): Promise { assertEquals(totalSize, 12); }); -unitTest(async function readerIterSync(): Promise { +unitTest(async function readerIterSync() { // ref: https://github.com/denoland/deno/issues/2330 const encoder = new TextEncoder(); @@ -166,7 +164,7 @@ unitTest( { perms: { read: true, write: true }, }, - function openSyncMode(): void { + function openSyncMode() { const path = Deno.makeTempDirSync() + "/test_openSync.txt"; const file = Deno.openSync(path, { write: true, @@ -185,7 +183,7 @@ unitTest( { perms: { read: true, write: true }, }, - async function openMode(): Promise { + async function openMode() { const path = (await Deno.makeTempDir()) + "/test_open.txt"; const file = await Deno.open(path, { write: true, @@ -204,7 +202,7 @@ unitTest( { perms: { read: true, write: true }, }, - function openSyncUrl(): void { + function openSyncUrl() { const tempDir = Deno.makeTempDirSync(); const fileUrl = new URL( `file://${ @@ -230,7 +228,7 @@ unitTest( { perms: { read: true, write: true }, }, - async function openUrl(): Promise { + async function openUrl() { const tempDir = await Deno.makeTempDir(); const fileUrl = new URL( `file://${ @@ -254,7 +252,7 @@ unitTest( unitTest( { perms: { write: false } }, - async function writePermFailure(): Promise { + async function writePermFailure() { const filename = "tests/hello.txt"; const openOptions: Deno.OpenOptions[] = [{ write: true }, { append: true }]; for (const options of openOptions) { @@ -265,10 +263,10 @@ unitTest( }, ); -unitTest(async function openOptions(): Promise { +unitTest(async function openOptions() { const filename = "cli/tests/fixture.json"; await assertThrowsAsync( - async (): Promise => { + async () => { await Deno.open(filename, { write: false }); }, Error, @@ -276,7 +274,7 @@ unitTest(async function openOptions(): Promise { ); await assertThrowsAsync( - async (): Promise => { + async () => { await Deno.open(filename, { truncate: true, write: false }); }, Error, @@ -284,7 +282,7 @@ unitTest(async function openOptions(): Promise { ); await assertThrowsAsync( - async (): Promise => { + async () => { await Deno.open(filename, { create: true, write: false }); }, Error, @@ -292,7 +290,7 @@ unitTest(async function openOptions(): Promise { ); await assertThrowsAsync( - async (): Promise => { + async () => { await Deno.open(filename, { createNew: true, append: false }); }, Error, @@ -300,9 +298,7 @@ unitTest(async function openOptions(): Promise { ); }); -unitTest({ perms: { read: false } }, async function readPermFailure(): Promise< - void -> { +unitTest({ perms: { read: false } }, async function readPermFailure() { await assertThrowsAsync(async () => { await Deno.open("package.json", { read: true }); }, Deno.errors.PermissionDenied); @@ -310,7 +306,7 @@ unitTest({ perms: { read: false } }, async function readPermFailure(): Promise< unitTest( { perms: { write: true } }, - async function writeNullBufferFailure(): Promise { + async function writeNullBufferFailure() { const tempDir = Deno.makeTempDirSync(); const filename = tempDir + "hello.txt"; const w = { @@ -322,7 +318,7 @@ unitTest( // writing null should throw an error await assertThrowsAsync( - async (): Promise => { + async () => { // deno-lint-ignore no-explicit-any await file.write(null as any); }, @@ -334,7 +330,7 @@ unitTest( unitTest( { perms: { write: true, read: true } }, - async function readNullBufferFailure(): Promise { + async function readNullBufferFailure() { const tempDir = Deno.makeTempDirSync(); const filename = tempDir + "hello.txt"; const file = await Deno.open(filename, { @@ -362,7 +358,7 @@ unitTest( unitTest( { perms: { write: false, read: false } }, - async function readWritePermFailure(): Promise { + async function readWritePermFailure() { const filename = "tests/hello.txt"; await assertThrowsAsync(async () => { await Deno.open(filename, { read: true }); @@ -372,7 +368,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function createFile(): Promise { + async function createFile() { const tempDir = await Deno.makeTempDir(); const filename = tempDir + "/test.txt"; const f = await Deno.create(filename); @@ -393,7 +389,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function createFileWithUrl(): Promise { + async function createFileWithUrl() { const tempDir = await Deno.makeTempDir(); const fileUrl = new URL( `file://${Deno.build.os === "windows" ? "/" : ""}${tempDir}/test.txt`, @@ -415,7 +411,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function createSyncFile(): Promise { + async function createSyncFile() { const tempDir = await Deno.makeTempDir(); const filename = tempDir + "/test.txt"; const f = Deno.createSync(filename); @@ -436,7 +432,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function createSyncFileWithUrl(): Promise { + async function createSyncFileWithUrl() { const tempDir = await Deno.makeTempDir(); const fileUrl = new URL( `file://${Deno.build.os === "windows" ? "/" : ""}${tempDir}/test.txt`, @@ -458,7 +454,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function openModeWrite(): Promise { + async function openModeWrite() { const tempDir = Deno.makeTempDirSync(); const encoder = new TextEncoder(); const filename = tempDir + "hello.txt"; @@ -501,7 +497,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function openModeWriteRead(): Promise { + async function openModeWriteRead() { const tempDir = Deno.makeTempDirSync(); const encoder = new TextEncoder(); const filename = tempDir + "hello.txt"; @@ -535,7 +531,7 @@ unitTest( }, ); -unitTest({ perms: { read: true } }, async function seekStart(): Promise { +unitTest({ perms: { read: true } }, async function seekStart() { const filename = "cli/tests/hello.txt"; const file = await Deno.open(filename); const seekPosition = 6; @@ -552,7 +548,7 @@ unitTest({ perms: { read: true } }, async function seekStart(): Promise { file.close(); }); -unitTest({ perms: { read: true } }, function seekSyncStart(): void { +unitTest({ perms: { read: true } }, function seekSyncStart() { const filename = "cli/tests/hello.txt"; const file = Deno.openSync(filename); const seekPosition = 6; @@ -569,9 +565,7 @@ unitTest({ perms: { read: true } }, function seekSyncStart(): void { file.close(); }); -unitTest({ perms: { read: true } }, async function seekCurrent(): Promise< - void -> { +unitTest({ perms: { read: true } }, async function seekCurrent() { const filename = "cli/tests/hello.txt"; const file = await Deno.open(filename); // Deliberately move 1 step forward @@ -588,7 +582,7 @@ unitTest({ perms: { read: true } }, async function seekCurrent(): Promise< file.close(); }); -unitTest({ perms: { read: true } }, function seekSyncCurrent(): void { +unitTest({ perms: { read: true } }, function seekSyncCurrent() { const filename = "cli/tests/hello.txt"; const file = Deno.openSync(filename); // Deliberately move 1 step forward @@ -605,7 +599,7 @@ unitTest({ perms: { read: true } }, function seekSyncCurrent(): void { file.close(); }); -unitTest({ perms: { read: true } }, async function seekEnd(): Promise { +unitTest({ perms: { read: true } }, async function seekEnd() { const filename = "cli/tests/hello.txt"; const file = await Deno.open(filename); const seekPosition = -6; @@ -619,7 +613,7 @@ unitTest({ perms: { read: true } }, async function seekEnd(): Promise { file.close(); }); -unitTest({ perms: { read: true } }, function seekSyncEnd(): void { +unitTest({ perms: { read: true } }, function seekSyncEnd() { const filename = "cli/tests/hello.txt"; const file = Deno.openSync(filename); const seekPosition = -6; @@ -633,11 +627,11 @@ unitTest({ perms: { read: true } }, function seekSyncEnd(): void { file.close(); }); -unitTest({ perms: { read: true } }, async function seekMode(): Promise { +unitTest({ perms: { read: true } }, async function seekMode() { const filename = "cli/tests/hello.txt"; const file = await Deno.open(filename); await assertThrowsAsync( - async (): Promise => { + async () => { await file.seek(1, -1); }, TypeError, diff --git a/cli/tests/unit/fs_events_test.ts b/cli/tests/unit/fs_events_test.ts index 87f3ec241e..7c944a4e8b 100644 --- a/cli/tests/unit/fs_events_test.ts +++ b/cli/tests/unit/fs_events_test.ts @@ -38,7 +38,7 @@ async function getTwoEvents( unitTest( { perms: { read: true, write: true } }, - async function watchFsBasic(): Promise { + async function watchFsBasic() { const testDir = await Deno.makeTempDir(); const iter = Deno.watchFs(testDir); @@ -65,7 +65,7 @@ unitTest( // This should be removed at 2.0 unitTest( { perms: { read: true, write: true } }, - async function watchFsReturn(): Promise { + async function watchFsReturn() { const testDir = await Deno.makeTempDir(); const iter = Deno.watchFs(testDir); @@ -83,7 +83,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function watchFsClose(): Promise { + async function watchFsClose() { const testDir = await Deno.makeTempDir(); const iter = Deno.watchFs(testDir); diff --git a/cli/tests/unit/get_random_values_test.ts b/cli/tests/unit/get_random_values_test.ts index 3f9f311f68..a9b493104c 100644 --- a/cli/tests/unit/get_random_values_test.ts +++ b/cli/tests/unit/get_random_values_test.ts @@ -1,49 +1,49 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. import { assertNotEquals, assertStrictEquals, unitTest } from "./test_util.ts"; -unitTest(function getRandomValuesInt8Array(): void { +unitTest(function getRandomValuesInt8Array() { const arr = new Int8Array(32); crypto.getRandomValues(arr); assertNotEquals(arr, new Int8Array(32)); }); -unitTest(function getRandomValuesUint8Array(): void { +unitTest(function getRandomValuesUint8Array() { const arr = new Uint8Array(32); crypto.getRandomValues(arr); assertNotEquals(arr, new Uint8Array(32)); }); -unitTest(function getRandomValuesUint8ClampedArray(): void { +unitTest(function getRandomValuesUint8ClampedArray() { const arr = new Uint8ClampedArray(32); crypto.getRandomValues(arr); assertNotEquals(arr, new Uint8ClampedArray(32)); }); -unitTest(function getRandomValuesInt16Array(): void { +unitTest(function getRandomValuesInt16Array() { const arr = new Int16Array(4); crypto.getRandomValues(arr); assertNotEquals(arr, new Int16Array(4)); }); -unitTest(function getRandomValuesUint16Array(): void { +unitTest(function getRandomValuesUint16Array() { const arr = new Uint16Array(4); crypto.getRandomValues(arr); assertNotEquals(arr, new Uint16Array(4)); }); -unitTest(function getRandomValuesInt32Array(): void { +unitTest(function getRandomValuesInt32Array() { const arr = new Int32Array(8); crypto.getRandomValues(arr); assertNotEquals(arr, new Int32Array(8)); }); -unitTest(function getRandomValuesUint32Array(): void { +unitTest(function getRandomValuesUint32Array() { const arr = new Uint32Array(8); crypto.getRandomValues(arr); assertNotEquals(arr, new Uint32Array(8)); }); -unitTest(function getRandomValuesReturnValue(): void { +unitTest(function getRandomValuesReturnValue() { const arr = new Uint32Array(8); const rtn = crypto.getRandomValues(arr); assertNotEquals(arr, new Uint32Array(8)); diff --git a/cli/tests/unit/globals_test.ts b/cli/tests/unit/globals_test.ts index 08ae237656..0051dce490 100644 --- a/cli/tests/unit/globals_test.ts +++ b/cli/tests/unit/globals_test.ts @@ -1,72 +1,72 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. import { assert, unitTest } from "./test_util.ts"; -unitTest(function globalThisExists(): void { +unitTest(function globalThisExists() { assert(globalThis != null); }); -unitTest(function noInternalGlobals(): void { +unitTest(function noInternalGlobals() { // globalThis.__bootstrap should not be there. for (const key of Object.keys(globalThis)) { assert(!key.startsWith("_")); } }); -unitTest(function windowExists(): void { +unitTest(function windowExists() { assert(window != null); }); -unitTest(function selfExists(): void { +unitTest(function selfExists() { assert(self != null); }); -unitTest(function windowWindowExists(): void { +unitTest(function windowWindowExists() { assert(window.window === window); }); -unitTest(function windowSelfExists(): void { +unitTest(function windowSelfExists() { assert(window.self === window); }); -unitTest(function globalThisEqualsWindow(): void { +unitTest(function globalThisEqualsWindow() { assert(globalThis === window); }); -unitTest(function globalThisEqualsSelf(): void { +unitTest(function globalThisEqualsSelf() { assert(globalThis === self); }); -unitTest(function globalThisInstanceofWindow(): void { +unitTest(function globalThisInstanceofWindow() { assert(globalThis instanceof Window); }); -unitTest(function globalThisConstructorLength(): void { +unitTest(function globalThisConstructorLength() { assert(globalThis.constructor.length === 0); }); -unitTest(function globalThisInstanceofEventTarget(): void { +unitTest(function globalThisInstanceofEventTarget() { assert(globalThis instanceof EventTarget); }); -unitTest(function navigatorInstanceofNavigator(): void { +unitTest(function navigatorInstanceofNavigator() { // TODO(nayeemrmn): Add `Navigator` to deno_lint globals. // deno-lint-ignore no-undef assert(navigator instanceof Navigator); }); -unitTest(function DenoNamespaceExists(): void { +unitTest(function DenoNamespaceExists() { assert(Deno != null); }); -unitTest(function DenoNamespaceEqualsWindowDeno(): void { +unitTest(function DenoNamespaceEqualsWindowDeno() { assert(Deno === window.Deno); }); -unitTest(function DenoNamespaceIsNotFrozen(): void { +unitTest(function DenoNamespaceIsNotFrozen() { assert(!Object.isFrozen(Deno)); }); -unitTest(function webAssemblyExists(): void { +unitTest(function webAssemblyExists() { assert(typeof WebAssembly.compile === "function"); }); @@ -84,7 +84,7 @@ unitTest(function DenoNamespaceConfigurable() { assert(!desc.writable); }); -unitTest(function DenoCoreNamespaceIsImmutable(): void { +unitTest(function DenoCoreNamespaceIsImmutable() { const { print } = Deno.core; try { Deno.core.print = 1; @@ -100,18 +100,18 @@ unitTest(function DenoCoreNamespaceIsImmutable(): void { assert(print === Deno.core.print); }); -unitTest(async function windowQueueMicrotask(): Promise { +unitTest(async function windowQueueMicrotask() { let resolve1: () => void | undefined; let resolve2: () => void | undefined; let microtaskDone = false; - const p1 = new Promise((res): void => { - resolve1 = (): void => { + const p1 = new Promise((res) => { + resolve1 = () => { microtaskDone = true; res(); }; }); - const p2 = new Promise((res): void => { - resolve2 = (): void => { + const p2 = new Promise((res) => { + resolve2 = () => { assert(microtaskDone); res(); }; diff --git a/cli/tests/unit/headers_test.ts b/cli/tests/unit/headers_test.ts index c79673d84f..bc695e7d90 100644 --- a/cli/tests/unit/headers_test.ts +++ b/cli/tests/unit/headers_test.ts @@ -5,14 +5,14 @@ const { // @ts-expect-error TypeScript (as of 3.7) does not support indexing namespaces by symbol } = Deno[Deno.internal]; -unitTest(function headersHasCorrectNameProp(): void { +unitTest(function headersHasCorrectNameProp() { assertEquals(Headers.name, "Headers"); }); // Logic heavily copied from web-platform-tests, make // sure pass mostly header basic test // ref: https://github.com/web-platform-tests/wpt/blob/7c50c216081d6ea3c9afe553ee7b64534020a1b2/fetch/api/headers/headers-basic.html -unitTest(function newHeaderTest(): void { +unitTest(function newHeaderTest() { new Headers(); new Headers(undefined); new Headers({}); @@ -38,7 +38,7 @@ for (const name in headerDict) { headerSeq.push([name, headerDict[name]]); } -unitTest(function newHeaderWithSequence(): void { +unitTest(function newHeaderWithSequence() { const headers = new Headers(headerSeq); for (const name in headerDict) { assertEquals(headers.get(name), String(headerDict[name])); @@ -46,14 +46,14 @@ unitTest(function newHeaderWithSequence(): void { assertEquals(headers.get("length"), null); }); -unitTest(function newHeaderWithRecord(): void { +unitTest(function newHeaderWithRecord() { const headers = new Headers(headerDict); for (const name in headerDict) { assertEquals(headers.get(name), String(headerDict[name])); } }); -unitTest(function newHeaderWithHeadersInstance(): void { +unitTest(function newHeaderWithHeadersInstance() { const headers = new Headers(headerDict); const headers2 = new Headers(headers); for (const name in headerDict) { @@ -61,7 +61,7 @@ unitTest(function newHeaderWithHeadersInstance(): void { } }); -unitTest(function headerAppendSuccess(): void { +unitTest(function headerAppendSuccess() { const headers = new Headers(); for (const name in headerDict) { headers.append(name, headerDict[name]); @@ -69,7 +69,7 @@ unitTest(function headerAppendSuccess(): void { } }); -unitTest(function headerSetSuccess(): void { +unitTest(function headerSetSuccess() { const headers = new Headers(); for (const name in headerDict) { headers.set(name, headerDict[name]); @@ -77,7 +77,7 @@ unitTest(function headerSetSuccess(): void { } }); -unitTest(function headerHasSuccess(): void { +unitTest(function headerHasSuccess() { const headers = new Headers(headerDict); for (const name in headerDict) { assert(headers.has(name), "headers has name " + name); @@ -88,7 +88,7 @@ unitTest(function headerHasSuccess(): void { } }); -unitTest(function headerDeleteSuccess(): void { +unitTest(function headerDeleteSuccess() { const headers = new Headers(headerDict); for (const name in headerDict) { assert(headers.has(name), "headers have a header: " + name); @@ -97,7 +97,7 @@ unitTest(function headerDeleteSuccess(): void { } }); -unitTest(function headerGetSuccess(): void { +unitTest(function headerGetSuccess() { const headers = new Headers(headerDict); for (const name in headerDict) { assertEquals(headers.get(name), String(headerDict[name])); @@ -105,7 +105,7 @@ unitTest(function headerGetSuccess(): void { } }); -unitTest(function headerEntriesSuccess(): void { +unitTest(function headerEntriesSuccess() { const headers = new Headers(headerDict); const iterators = headers.entries(); for (const it of iterators) { @@ -116,7 +116,7 @@ unitTest(function headerEntriesSuccess(): void { } }); -unitTest(function headerKeysSuccess(): void { +unitTest(function headerKeysSuccess() { const headers = new Headers(headerDict); const iterators = headers.keys(); for (const it of iterators) { @@ -124,7 +124,7 @@ unitTest(function headerKeysSuccess(): void { } }); -unitTest(function headerValuesSuccess(): void { +unitTest(function headerValuesSuccess() { const headers = new Headers(headerDict); const iterators = headers.values(); const entries = headers.entries(); @@ -146,16 +146,16 @@ const headerEntriesDict: Record = { "Content-Types": "value6", }; -unitTest(function headerForEachSuccess(): void { +unitTest(function headerForEachSuccess() { const headers = new Headers(headerEntriesDict); const keys = Object.keys(headerEntriesDict); - keys.forEach((key): void => { + keys.forEach((key) => { const value = headerEntriesDict[key]; const newkey = key.toLowerCase(); headerEntriesDict[newkey] = value; }); let callNum = 0; - headers.forEach((value, key, container): void => { + headers.forEach((value, key, container) => { assertEquals(headers, container); assertEquals(value, headerEntriesDict[key]); callNum++; @@ -163,7 +163,7 @@ unitTest(function headerForEachSuccess(): void { assertEquals(callNum, keys.length); }); -unitTest(function headerSymbolIteratorSuccess(): void { +unitTest(function headerSymbolIteratorSuccess() { assert(Symbol.iterator in Headers.prototype); const headers = new Headers(headerEntriesDict); for (const header of headers) { @@ -174,7 +174,7 @@ unitTest(function headerSymbolIteratorSuccess(): void { } }); -unitTest(function headerTypesAvailable(): void { +unitTest(function headerTypesAvailable() { function newHeaders(): Headers { return new Headers(); } @@ -184,7 +184,7 @@ unitTest(function headerTypesAvailable(): void { // Modified from https://github.com/bitinn/node-fetch/blob/7d3293200a91ad52b5ca7962f9d6fd1c04983edb/test/test.js#L2001-L2014 // Copyright (c) 2016 David Frank. MIT License. -unitTest(function headerIllegalReject(): void { +unitTest(function headerIllegalReject() { let errorCount = 0; try { new Headers({ "He y": "ok" }); @@ -238,7 +238,7 @@ unitTest(function headerIllegalReject(): void { }); // If pair does not contain exactly two items,then throw a TypeError. -unitTest(function headerParamsShouldThrowTypeError(): void { +unitTest(function headerParamsShouldThrowTypeError() { let hasThrown = 0; try { @@ -255,12 +255,12 @@ unitTest(function headerParamsShouldThrowTypeError(): void { assertEquals(hasThrown, 2); }); -unitTest(function headerParamsArgumentsCheck(): void { +unitTest(function headerParamsArgumentsCheck() { const methodRequireOneParam = ["delete", "get", "has", "forEach"] as const; const methodRequireTwoParams = ["append", "set"] as const; - methodRequireOneParam.forEach((method): void => { + methodRequireOneParam.forEach((method) => { const headers = new Headers(); let hasThrown = 0; try { @@ -277,7 +277,7 @@ unitTest(function headerParamsArgumentsCheck(): void { assertEquals(hasThrown, 2); }); - methodRequireTwoParams.forEach((method): void => { + methodRequireTwoParams.forEach((method) => { const headers = new Headers(); let hasThrown = 0; @@ -310,7 +310,7 @@ unitTest(function headerParamsArgumentsCheck(): void { }); }); -unitTest(function headersInitMultiple(): void { +unitTest(function headersInitMultiple() { const headers = new Headers([ ["Set-Cookie", "foo=bar"], ["Set-Cookie", "bar=baz"], @@ -325,7 +325,7 @@ unitTest(function headersInitMultiple(): void { ]); }); -unitTest(function headersAppendMultiple(): void { +unitTest(function headersAppendMultiple() { const headers = new Headers([ ["Set-Cookie", "foo=bar"], ["X-Deno", "foo"], @@ -340,7 +340,7 @@ unitTest(function headersAppendMultiple(): void { ]); }); -unitTest(function headersAppendDuplicateSetCookieKey(): void { +unitTest(function headersAppendDuplicateSetCookieKey() { const headers = new Headers([["Set-Cookie", "foo=bar"]]); headers.append("set-Cookie", "foo=baz"); headers.append("Set-cookie", "baz=bar"); @@ -352,7 +352,7 @@ unitTest(function headersAppendDuplicateSetCookieKey(): void { ]); }); -unitTest(function headersGetSetCookie(): void { +unitTest(function headersGetSetCookie() { const headers = new Headers([ ["Set-Cookie", "foo=bar"], ["set-Cookie", "bar=qat"], @@ -360,7 +360,7 @@ unitTest(function headersGetSetCookie(): void { assertEquals(headers.get("SET-COOKIE"), "foo=bar, bar=qat"); }); -unitTest(function toStringShouldBeWebCompatibility(): void { +unitTest(function toStringShouldBeWebCompatibility() { const headers = new Headers(); assertEquals(headers.toString(), "[object Headers]"); }); @@ -369,7 +369,7 @@ function stringify(...args: unknown[]): string { return inspectArgs(args).replace(/\n$/, ""); } -unitTest(function customInspectReturnsCorrectHeadersFormat(): void { +unitTest(function customInspectReturnsCorrectHeadersFormat() { const blankHeaders = new Headers(); assertEquals(stringify(blankHeaders), "Headers {}"); const singleHeader = new Headers([["Content-Type", "application/json"]]); diff --git a/cli/tests/unit/http_test.ts b/cli/tests/unit/http_test.ts index 3232d3f27d..ffd29ff86f 100644 --- a/cli/tests/unit/http_test.ts +++ b/cli/tests/unit/http_test.ts @@ -200,7 +200,7 @@ unitTest({ perms: { net: true } }, async function httpServerInvalidMethod() { unitTest( { perms: { read: true, net: true } }, - async function httpServerWithTls(): Promise { + async function httpServerWithTls() { const hostname = "localhost"; const port = 4501; diff --git a/cli/tests/unit/internals_test.ts b/cli/tests/unit/internals_test.ts index 9a5820dec9..d3512de057 100644 --- a/cli/tests/unit/internals_test.ts +++ b/cli/tests/unit/internals_test.ts @@ -1,7 +1,7 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. import { assert, unitTest } from "./test_util.ts"; -unitTest(function internalsExists(): void { +unitTest(function internalsExists() { const { inspectArgs, // @ts-expect-error TypeScript (as of 3.7) does not support indexing namespaces by symbol diff --git a/cli/tests/unit/link_test.ts b/cli/tests/unit/link_test.ts index 86cd65bae6..5d3553ac3b 100644 --- a/cli/tests/unit/link_test.ts +++ b/cli/tests/unit/link_test.ts @@ -3,7 +3,7 @@ import { assert, assertEquals, assertThrows, unitTest } from "./test_util.ts"; unitTest( { perms: { read: true, write: true } }, - function linkSyncSuccess(): void { + function linkSyncSuccess() { const testDir = Deno.makeTempDirSync(); const oldData = "Hardlink"; const oldName = testDir + "/oldname"; @@ -42,7 +42,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - function linkSyncExists(): void { + function linkSyncExists() { const testDir = Deno.makeTempDirSync(); const oldName = testDir + "/oldname"; const newName = testDir + "/newname"; @@ -58,7 +58,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - function linkSyncNotFound(): void { + function linkSyncNotFound() { const testDir = Deno.makeTempDirSync(); const oldName = testDir + "/oldname"; const newName = testDir + "/newname"; @@ -71,7 +71,7 @@ unitTest( unitTest( { perms: { read: false, write: true } }, - function linkSyncReadPerm(): void { + function linkSyncReadPerm() { assertThrows(() => { Deno.linkSync("oldbaddir", "newbaddir"); }, Deno.errors.PermissionDenied); @@ -80,7 +80,7 @@ unitTest( unitTest( { perms: { read: true, write: false } }, - function linkSyncWritePerm(): void { + function linkSyncWritePerm() { assertThrows(() => { Deno.linkSync("oldbaddir", "newbaddir"); }, Deno.errors.PermissionDenied); @@ -89,7 +89,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function linkSuccess(): Promise { + async function linkSuccess() { const testDir = Deno.makeTempDirSync(); const oldData = "Hardlink"; const oldName = testDir + "/oldname"; diff --git a/cli/tests/unit/make_temp_test.ts b/cli/tests/unit/make_temp_test.ts index b43d257e03..5b28c210bf 100644 --- a/cli/tests/unit/make_temp_test.ts +++ b/cli/tests/unit/make_temp_test.ts @@ -7,7 +7,7 @@ import { unitTest, } from "./test_util.ts"; -unitTest({ perms: { write: true } }, function makeTempDirSyncSuccess(): void { +unitTest({ perms: { write: true } }, function makeTempDirSyncSuccess() { const dir1 = Deno.makeTempDirSync({ prefix: "hello", suffix: "world" }); const dir2 = Deno.makeTempDirSync({ prefix: "hello", suffix: "world" }); // Check that both dirs are different. @@ -30,7 +30,7 @@ unitTest({ perms: { write: true } }, function makeTempDirSyncSuccess(): void { unitTest( { perms: { read: true, write: true } }, - function makeTempDirSyncMode(): void { + function makeTempDirSyncMode() { const path = Deno.makeTempDirSync(); const pathInfo = Deno.statSync(path); if (Deno.build.os !== "windows") { @@ -39,7 +39,7 @@ unitTest( }, ); -unitTest(function makeTempDirSyncPerm(): void { +unitTest(function makeTempDirSyncPerm() { // makeTempDirSync should require write permissions (for now). assertThrows(() => { Deno.makeTempDirSync({ dir: "/baddir" }); @@ -48,7 +48,7 @@ unitTest(function makeTempDirSyncPerm(): void { unitTest( { perms: { write: true } }, - async function makeTempDirSuccess(): Promise { + async function makeTempDirSuccess() { const dir1 = await Deno.makeTempDir({ prefix: "hello", suffix: "world" }); const dir2 = await Deno.makeTempDir({ prefix: "hello", suffix: "world" }); // Check that both dirs are different. @@ -72,7 +72,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function makeTempDirMode(): Promise { + async function makeTempDirMode() { const path = await Deno.makeTempDir(); const pathInfo = Deno.statSync(path); if (Deno.build.os !== "windows") { @@ -81,7 +81,7 @@ unitTest( }, ); -unitTest({ perms: { write: true } }, function makeTempFileSyncSuccess(): void { +unitTest({ perms: { write: true } }, function makeTempFileSyncSuccess() { const file1 = Deno.makeTempFileSync({ prefix: "hello", suffix: "world" }); const file2 = Deno.makeTempFileSync({ prefix: "hello", suffix: "world" }); // Check that both dirs are different. @@ -105,7 +105,7 @@ unitTest({ perms: { write: true } }, function makeTempFileSyncSuccess(): void { unitTest( { perms: { read: true, write: true } }, - function makeTempFileSyncMode(): void { + function makeTempFileSyncMode() { const path = Deno.makeTempFileSync(); const pathInfo = Deno.statSync(path); if (Deno.build.os !== "windows") { @@ -114,7 +114,7 @@ unitTest( }, ); -unitTest(function makeTempFileSyncPerm(): void { +unitTest(function makeTempFileSyncPerm() { // makeTempFileSync should require write permissions (for now). assertThrows(() => { Deno.makeTempFileSync({ dir: "/baddir" }); @@ -123,7 +123,7 @@ unitTest(function makeTempFileSyncPerm(): void { unitTest( { perms: { write: true } }, - async function makeTempFileSuccess(): Promise { + async function makeTempFileSuccess() { const file1 = await Deno.makeTempFile({ prefix: "hello", suffix: "world" }); const file2 = await Deno.makeTempFile({ prefix: "hello", suffix: "world" }); // Check that both dirs are different. @@ -148,7 +148,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function makeTempFileMode(): Promise { + async function makeTempFileMode() { const path = await Deno.makeTempFile(); const pathInfo = Deno.statSync(path); if (Deno.build.os !== "windows") { diff --git a/cli/tests/unit/metrics_test.ts b/cli/tests/unit/metrics_test.ts index f041cf1c9e..d6a312e505 100644 --- a/cli/tests/unit/metrics_test.ts +++ b/cli/tests/unit/metrics_test.ts @@ -1,7 +1,7 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. import { assert, unitTest } from "./test_util.ts"; -unitTest(async function metrics(): Promise { +unitTest(async function metrics() { // Write to stdout to ensure a "data" message gets sent instead of just // control messages. const dataMsg = new Uint8Array([13, 13, 13]); // "\r\r\r", @@ -41,7 +41,7 @@ unitTest(async function metrics(): Promise { unitTest( { perms: { write: true } }, - function metricsUpdatedIfNoResponseSync(): void { + function metricsUpdatedIfNoResponseSync() { const filename = Deno.makeTempDirSync() + "/test.txt"; const data = new Uint8Array([41, 42, 43]); @@ -55,7 +55,7 @@ unitTest( unitTest( { perms: { write: true } }, - async function metricsUpdatedIfNoResponseAsync(): Promise { + async function metricsUpdatedIfNoResponseAsync() { const filename = Deno.makeTempDirSync() + "/test.txt"; const data = new Uint8Array([41, 42, 43]); @@ -69,7 +69,7 @@ unitTest( ); // Test that ops from extensions have metrics (via OpMiddleware) -unitTest(function metricsForOpCrates(): void { +unitTest(function metricsForOpCrates() { const _ = new URL("https://deno.land"); const m1 = Deno.metrics().ops["op_url_parse"]; diff --git a/cli/tests/unit/mkdir_test.ts b/cli/tests/unit/mkdir_test.ts index fd0328f57c..586c1ebe38 100644 --- a/cli/tests/unit/mkdir_test.ts +++ b/cli/tests/unit/mkdir_test.ts @@ -8,7 +8,7 @@ import { unitTest, } from "./test_util.ts"; -function assertDirectory(path: string, mode?: number): void { +function assertDirectory(path: string, mode?: number) { const info = Deno.lstatSync(path); assert(info.isDirectory); if (Deno.build.os !== "windows" && mode !== undefined) { @@ -18,7 +18,7 @@ function assertDirectory(path: string, mode?: number): void { unitTest( { perms: { read: true, write: true } }, - function mkdirSyncSuccess(): void { + function mkdirSyncSuccess() { const path = Deno.makeTempDirSync() + "/dir"; Deno.mkdirSync(path); assertDirectory(path); @@ -27,14 +27,14 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - function mkdirSyncMode(): void { + function mkdirSyncMode() { const path = Deno.makeTempDirSync() + "/dir"; Deno.mkdirSync(path, { mode: 0o737 }); assertDirectory(path, 0o737); }, ); -unitTest({ perms: { write: false } }, function mkdirSyncPerm(): void { +unitTest({ perms: { write: false } }, function mkdirSyncPerm() { assertThrows(() => { Deno.mkdirSync("/baddir"); }, Deno.errors.PermissionDenied); @@ -42,7 +42,7 @@ unitTest({ perms: { write: false } }, function mkdirSyncPerm(): void { unitTest( { perms: { read: true, write: true } }, - async function mkdirSuccess(): Promise { + async function mkdirSuccess() { const path = Deno.makeTempDirSync() + "/dir"; await Deno.mkdir(path); assertDirectory(path); @@ -51,22 +51,20 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function mkdirMode(): Promise { + async function mkdirMode() { const path = Deno.makeTempDirSync() + "/dir"; await Deno.mkdir(path, { mode: 0o737 }); assertDirectory(path, 0o737); }, ); -unitTest({ perms: { write: true } }, function mkdirErrSyncIfExists(): void { +unitTest({ perms: { write: true } }, function mkdirErrSyncIfExists() { assertThrows(() => { Deno.mkdirSync("."); }, Deno.errors.AlreadyExists); }); -unitTest({ perms: { write: true } }, async function mkdirErrIfExists(): Promise< - void -> { +unitTest({ perms: { write: true } }, async function mkdirErrIfExists() { await assertThrowsAsync(async () => { await Deno.mkdir("."); }, Deno.errors.AlreadyExists); @@ -74,7 +72,7 @@ unitTest({ perms: { write: true } }, async function mkdirErrIfExists(): Promise< unitTest( { perms: { read: true, write: true } }, - function mkdirSyncRecursive(): void { + function mkdirSyncRecursive() { const path = Deno.makeTempDirSync() + "/nested/directory"; Deno.mkdirSync(path, { recursive: true }); assertDirectory(path); @@ -83,7 +81,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function mkdirRecursive(): Promise { + async function mkdirRecursive() { const path = Deno.makeTempDirSync() + "/nested/directory"; await Deno.mkdir(path, { recursive: true }); assertDirectory(path); @@ -92,7 +90,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - function mkdirSyncRecursiveMode(): void { + function mkdirSyncRecursiveMode() { const nested = Deno.makeTempDirSync() + "/nested"; const path = nested + "/dir"; Deno.mkdirSync(path, { mode: 0o737, recursive: true }); @@ -103,7 +101,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function mkdirRecursiveMode(): Promise { + async function mkdirRecursiveMode() { const nested = Deno.makeTempDirSync() + "/nested"; const path = nested + "/dir"; await Deno.mkdir(path, { mode: 0o737, recursive: true }); @@ -114,7 +112,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - function mkdirSyncRecursiveIfExists(): void { + function mkdirSyncRecursiveIfExists() { const path = Deno.makeTempDirSync() + "/dir"; Deno.mkdirSync(path, { mode: 0o737 }); Deno.mkdirSync(path, { recursive: true }); @@ -132,7 +130,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function mkdirRecursiveIfExists(): Promise { + async function mkdirRecursiveIfExists() { const path = Deno.makeTempDirSync() + "/dir"; await Deno.mkdir(path, { mode: 0o737 }); await Deno.mkdir(path, { recursive: true }); @@ -150,7 +148,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - function mkdirSyncErrors(): void { + function mkdirSyncErrors() { const testDir = Deno.makeTempDirSync(); const emptydir = testDir + "/empty"; const fulldir = testDir + "/dir"; @@ -159,16 +157,16 @@ unitTest( Deno.mkdirSync(fulldir); Deno.createSync(file).close(); - assertThrows((): void => { + assertThrows(() => { Deno.mkdirSync(emptydir, { recursive: false }); }, Deno.errors.AlreadyExists); - assertThrows((): void => { + assertThrows(() => { Deno.mkdirSync(fulldir, { recursive: false }); }, Deno.errors.AlreadyExists); - assertThrows((): void => { + assertThrows(() => { Deno.mkdirSync(file, { recursive: false }); }, Deno.errors.AlreadyExists); - assertThrows((): void => { + assertThrows(() => { Deno.mkdirSync(file, { recursive: true }); }, Deno.errors.AlreadyExists); @@ -180,19 +178,19 @@ unitTest( Deno.symlinkSync(emptydir, dirLink); Deno.symlinkSync(testDir + "/nonexistent", danglingLink); - assertThrows((): void => { + assertThrows(() => { Deno.mkdirSync(dirLink, { recursive: false }); }, Deno.errors.AlreadyExists); - assertThrows((): void => { + assertThrows(() => { Deno.mkdirSync(fileLink, { recursive: false }); }, Deno.errors.AlreadyExists); - assertThrows((): void => { + assertThrows(() => { Deno.mkdirSync(fileLink, { recursive: true }); }, Deno.errors.AlreadyExists); - assertThrows((): void => { + assertThrows(() => { Deno.mkdirSync(danglingLink, { recursive: false }); }, Deno.errors.AlreadyExists); - assertThrows((): void => { + assertThrows(() => { Deno.mkdirSync(danglingLink, { recursive: true }); }, Deno.errors.AlreadyExists); } @@ -201,7 +199,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - function mkdirSyncRelativeUrlPath(): void { + function mkdirSyncRelativeUrlPath() { const testDir = Deno.makeTempDirSync(); const nestedDir = testDir + "/nested"; // Add trailing slash so base path is treated as a directory. pathToAbsoluteFileUrl removes trailing slashes. @@ -216,7 +214,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function mkdirRelativeUrlPath(): Promise { + async function mkdirRelativeUrlPath() { const testDir = Deno.makeTempDirSync(); const nestedDir = testDir + "/nested"; // Add trailing slash so base path is treated as a directory. pathToAbsoluteFileUrl removes trailing slashes. diff --git a/cli/tests/unit/navigator_test.ts b/cli/tests/unit/navigator_test.ts index 10475d9733..6357d4c560 100644 --- a/cli/tests/unit/navigator_test.ts +++ b/cli/tests/unit/navigator_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. import { assert, unitTest } from "./test_util.ts"; -unitTest(function navigatorNumCpus(): void { +unitTest(function navigatorNumCpus() { assert(navigator.hardwareConcurrency > 0); }); diff --git a/cli/tests/unit/net_test.ts b/cli/tests/unit/net_test.ts index a7a9454c03..26175f1214 100644 --- a/cli/tests/unit/net_test.ts +++ b/cli/tests/unit/net_test.ts @@ -10,7 +10,7 @@ import { unitTest, } from "./test_util.ts"; -unitTest({ perms: { net: true } }, function netTcpListenClose(): void { +unitTest({ perms: { net: true } }, function netTcpListenClose() { const listener = Deno.listen({ hostname: "127.0.0.1", port: 3500 }); assert(listener.addr.transport === "tcp"); assertEquals(listener.addr.hostname, "127.0.0.1"); @@ -23,7 +23,7 @@ unitTest( { perms: { net: true }, }, - function netUdpListenClose(): void { + function netUdpListenClose() { const socket = Deno.listenDatagram({ hostname: "127.0.0.1", port: 3500, @@ -38,7 +38,7 @@ unitTest( unitTest( { ignore: Deno.build.os === "windows", perms: { read: true, write: true } }, - function netUnixListenClose(): void { + function netUnixListenClose() { const filePath = Deno.makeTempFileSync(); const socket = Deno.listen({ path: filePath, @@ -52,7 +52,7 @@ unitTest( unitTest( { ignore: Deno.build.os === "windows", perms: { read: true, write: true } }, - function netUnixPacketListenClose(): void { + function netUnixPacketListenClose() { const filePath = Deno.makeTempFileSync(); const socket = Deno.listenDatagram({ path: filePath, @@ -66,7 +66,7 @@ unitTest( unitTest( { ignore: Deno.build.os === "windows", perms: { read: true } }, - function netUnixListenWritePermission(): void { + function netUnixListenWritePermission() { assertThrows(() => { const filePath = Deno.makeTempFileSync(); const socket = Deno.listen({ @@ -82,7 +82,7 @@ unitTest( unitTest( { ignore: Deno.build.os === "windows", perms: { read: true } }, - function netUnixPacketListenWritePermission(): void { + function netUnixPacketListenWritePermission() { assertThrows(() => { const filePath = Deno.makeTempFileSync(); const socket = Deno.listenDatagram({ @@ -100,12 +100,12 @@ unitTest( { perms: { net: true }, }, - async function netTcpCloseWhileAccept(): Promise { + async function netTcpCloseWhileAccept() { const listener = Deno.listen({ port: 4501 }); const p = listener.accept(); listener.close(); await assertThrowsAsync( - async (): Promise => { + async () => { await p; }, Deno.errors.BadResource, @@ -116,7 +116,7 @@ unitTest( unitTest( { ignore: Deno.build.os === "windows", perms: { read: true, write: true } }, - async function netUnixCloseWhileAccept(): Promise { + async function netUnixCloseWhileAccept() { const filePath = await Deno.makeTempFile(); const listener = Deno.listen({ path: filePath, @@ -125,7 +125,7 @@ unitTest( const p = listener.accept(); listener.close(); await assertThrowsAsync( - async (): Promise => { + async () => { await p; }, Deno.errors.BadResource, @@ -136,10 +136,10 @@ unitTest( unitTest( { perms: { net: true } }, - async function netTcpConcurrentAccept(): Promise { + async function netTcpConcurrentAccept() { const listener = Deno.listen({ port: 4502 }); let acceptErrCount = 0; - const checkErr = (e: Error): void => { + const checkErr = (e: Error) => { if (e.message === "Listener has been closed") { assertEquals(acceptErrCount, 1); } else if (e.message === "Another accept task is ongoing") { @@ -160,11 +160,11 @@ unitTest( // TODO(jsouto): Enable when tokio updates mio to v0.7! unitTest( { ignore: true, perms: { read: true, write: true } }, - async function netUnixConcurrentAccept(): Promise { + async function netUnixConcurrentAccept() { const filePath = await Deno.makeTempFile(); const listener = Deno.listen({ transport: "unix", path: filePath }); let acceptErrCount = 0; - const checkErr = (e: Error): void => { + const checkErr = (e: Error) => { if (e.message === "Listener has been closed") { assertEquals(acceptErrCount, 1); } else if (e.message === "Another accept task is ongoing") { @@ -182,12 +182,10 @@ unitTest( }, ); -unitTest({ perms: { net: true } }, async function netTcpDialListen(): Promise< - void -> { +unitTest({ perms: { net: true } }, async function netTcpDialListen() { const listener = Deno.listen({ port: 3500 }); listener.accept().then( - async (conn): Promise => { + async (conn) => { assert(conn.remoteAddr != null); assert(conn.localAddr.transport === "tcp"); assertEquals(conn.localAddr.hostname, "127.0.0.1"); @@ -221,11 +219,11 @@ unitTest({ perms: { net: true } }, async function netTcpDialListen(): Promise< unitTest( { ignore: Deno.build.os === "windows", perms: { read: true, write: true } }, - async function netUnixDialListen(): Promise { + async function netUnixDialListen() { const filePath = await Deno.makeTempFile(); const listener = Deno.listen({ path: filePath, transport: "unix" }); listener.accept().then( - async (conn): Promise => { + async (conn) => { assert(conn.remoteAddr != null); assert(conn.localAddr.transport === "unix"); assertEquals(conn.localAddr.path, filePath); @@ -257,7 +255,7 @@ unitTest( unitTest( { perms: { net: true } }, - async function netUdpSendReceive(): Promise { + async function netUdpSendReceive() { const alice = Deno.listenDatagram({ port: 3500, transport: "udp" }); assert(alice.addr.transport === "udp"); assertEquals(alice.addr.port, 3500); @@ -287,7 +285,7 @@ unitTest( unitTest( { perms: { net: true } }, - async function netUdpConcurrentSendReceive(): Promise { + async function netUdpConcurrentSendReceive() { const socket = Deno.listenDatagram({ port: 3500, transport: "udp" }); assert(socket.addr.transport === "udp"); assertEquals(socket.addr.port, 3500); @@ -311,7 +309,7 @@ unitTest( unitTest( { perms: { net: true } }, - async function netUdpBorrowMutError(): Promise { + async function netUdpBorrowMutError() { const socket = Deno.listenDatagram({ port: 4501, transport: "udp", @@ -326,7 +324,7 @@ unitTest( unitTest( { ignore: Deno.build.os === "windows", perms: { read: true, write: true } }, - async function netUnixPacketSendReceive(): Promise { + async function netUnixPacketSendReceive() { const filePath = await Deno.makeTempFile(); const alice = Deno.listenDatagram({ path: filePath, @@ -361,7 +359,7 @@ unitTest( // TODO(piscisaureus): Enable after Tokio v0.3/v1.0 upgrade. unitTest( { ignore: true, perms: { read: true, write: true } }, - async function netUnixPacketConcurrentSendReceive(): Promise { + async function netUnixPacketConcurrentSendReceive() { const filePath = await Deno.makeTempFile(); const socket = Deno.listenDatagram({ path: filePath, @@ -388,10 +386,10 @@ unitTest( unitTest( { perms: { net: true } }, - async function netTcpListenIteratorBreakClosesResource(): Promise { + async function netTcpListenIteratorBreakClosesResource() { const promise = deferred(); - async function iterate(listener: Deno.Listener): Promise { + async function iterate(listener: Deno.Listener) { let i = 0; for await (const conn of listener) { @@ -422,7 +420,7 @@ unitTest( unitTest( { perms: { net: true } }, - async function netTcpListenCloseWhileIterating(): Promise { + async function netTcpListenCloseWhileIterating() { const listener = Deno.listen({ port: 8001 }); const nextWhileClosing = listener[Symbol.asyncIterator]().next(); listener.close(); @@ -435,7 +433,7 @@ unitTest( unitTest( { perms: { net: true } }, - async function netUdpListenCloseWhileIterating(): Promise { + async function netUdpListenCloseWhileIterating() { const socket = Deno.listenDatagram({ port: 8000, transport: "udp" }); const nextWhileClosing = socket[Symbol.asyncIterator]().next(); socket.close(); @@ -448,7 +446,7 @@ unitTest( unitTest( { ignore: Deno.build.os === "windows", perms: { read: true, write: true } }, - async function netUnixListenCloseWhileIterating(): Promise { + async function netUnixListenCloseWhileIterating() { const filePath = Deno.makeTempFileSync(); const socket = Deno.listen({ path: filePath, transport: "unix" }); const nextWhileClosing = socket[Symbol.asyncIterator]().next(); @@ -462,7 +460,7 @@ unitTest( unitTest( { ignore: Deno.build.os === "windows", perms: { read: true, write: true } }, - async function netUnixPacketListenCloseWhileIterating(): Promise { + async function netUnixPacketListenCloseWhileIterating() { const filePath = Deno.makeTempFileSync(); const socket = Deno.listenDatagram({ path: filePath, @@ -483,10 +481,10 @@ unitTest( ignore: true, perms: { net: true }, }, - async function netListenAsyncIterator(): Promise { + async function netListenAsyncIterator() { const addr = { hostname: "127.0.0.1", port: 3500 }; const listener = Deno.listen(addr); - const runAsyncIterator = async (): Promise => { + const runAsyncIterator = async () => { for await (const conn of listener) { await conn.write(new Uint8Array([1, 2, 3])); conn.close(); @@ -552,7 +550,7 @@ unitTest( async function netHangsOnClose() { let acceptedConn: Deno.Conn; - async function iteratorReq(listener: Deno.Listener): Promise { + async function iteratorReq(listener: Deno.Listener) { const p = new Uint8Array(10); const conn = await listener.accept(); acceptedConn = conn; diff --git a/cli/tests/unit/opcall_test.ts b/cli/tests/unit/opcall_test.ts index bd549570e8..9c0d39d2ed 100644 --- a/cli/tests/unit/opcall_test.ts +++ b/cli/tests/unit/opcall_test.ts @@ -21,7 +21,7 @@ declare global { } } -unitTest(async function opsAsyncBadResource(): Promise { +unitTest(async function opsAsyncBadResource() { try { const nonExistingRid = 9999; await Deno.core.opAsync( @@ -36,7 +36,7 @@ unitTest(async function opsAsyncBadResource(): Promise { } }); -unitTest(function opsSyncBadResource(): void { +unitTest(function opsSyncBadResource() { try { const nonExistingRid = 9999; Deno.core.opSync("op_read_sync", nonExistingRid, new Uint8Array(0)); diff --git a/cli/tests/unit/os_test.ts b/cli/tests/unit/os_test.ts index daa7a1ca27..d7fb88882d 100644 --- a/cli/tests/unit/os_test.ts +++ b/cli/tests/unit/os_test.ts @@ -7,7 +7,7 @@ import { unitTest, } from "./test_util.ts"; -unitTest({ perms: { env: true } }, function envSuccess(): void { +unitTest({ perms: { env: true } }, function envSuccess() { Deno.env.set("TEST_VAR", "A"); const env = Deno.env.toObject(); Deno.env.set("TEST_VAR", "B"); @@ -15,19 +15,19 @@ unitTest({ perms: { env: true } }, function envSuccess(): void { assertNotEquals(Deno.env.get("TEST_VAR"), env["TEST_VAR"]); }); -unitTest({ perms: { env: true } }, function envNotFound(): void { +unitTest({ perms: { env: true } }, function envNotFound() { const r = Deno.env.get("env_var_does_not_exist!"); assertEquals(r, undefined); }); -unitTest({ perms: { env: true } }, function deleteEnv(): void { +unitTest({ perms: { env: true } }, function deleteEnv() { Deno.env.set("TEST_VAR", "A"); assertEquals(Deno.env.get("TEST_VAR"), "A"); assertEquals(Deno.env.delete("TEST_VAR"), undefined); assertEquals(Deno.env.get("TEST_VAR"), undefined); }); -unitTest({ perms: { env: true } }, function avoidEmptyNamedEnv(): void { +unitTest({ perms: { env: true } }, function avoidEmptyNamedEnv() { assertThrows(() => Deno.env.set("", "v"), TypeError); assertThrows(() => Deno.env.set("a=a", "v"), TypeError); assertThrows(() => Deno.env.set("a\0a", "v"), TypeError); @@ -42,13 +42,13 @@ unitTest({ perms: { env: true } }, function avoidEmptyNamedEnv(): void { assertThrows(() => Deno.env.delete("a\0a"), TypeError); }); -unitTest(function envPermissionDenied1(): void { +unitTest(function envPermissionDenied1() { assertThrows(() => { Deno.env.toObject(); }, Deno.errors.PermissionDenied); }); -unitTest(function envPermissionDenied2(): void { +unitTest(function envPermissionDenied2() { assertThrows(() => { Deno.env.get("PATH"); }, Deno.errors.PermissionDenied); @@ -70,7 +70,7 @@ unitTest( const checkChildEnv = async ( inputEnv: Record, expectedEnv: Record, - ): Promise => { + ) => { const src = ` console.log( ${JSON.stringify(Object.keys(expectedEnv))}.map(k => Deno.env.get(k)) @@ -122,17 +122,17 @@ unitTest( }, ); -unitTest(function osPid(): void { +unitTest(function osPid() { assert(Deno.pid > 0); }); -unitTest(function osPpid(): void { +unitTest(function osPpid() { assert(Deno.ppid > 0); }); unitTest( { perms: { run: true, read: true } }, - async function osPpidIsEqualToPidOfParentProcess(): Promise { + async function osPpidIsEqualToPidOfParentProcess() { const decoder = new TextDecoder(); const process = Deno.run({ cmd: [Deno.execPath(), "eval", "-p", "--unstable", "Deno.ppid"], @@ -148,11 +148,11 @@ unitTest( }, ); -unitTest({ perms: { read: true } }, function execPath(): void { +unitTest({ perms: { read: true } }, function execPath() { assertNotEquals(Deno.execPath(), ""); }); -unitTest({ perms: { read: false } }, function execPathPerm(): void { +unitTest({ perms: { read: false } }, function execPathPerm() { assertThrows( () => { Deno.execPath(); @@ -162,38 +162,38 @@ unitTest({ perms: { read: false } }, function execPathPerm(): void { ); }); -unitTest({ perms: { env: true } }, function loadavgSuccess(): void { +unitTest({ perms: { env: true } }, function loadavgSuccess() { const load = Deno.loadavg(); assertEquals(load.length, 3); }); -unitTest({ perms: { env: false } }, function loadavgPerm(): void { +unitTest({ perms: { env: false } }, function loadavgPerm() { assertThrows(() => { Deno.loadavg(); }, Deno.errors.PermissionDenied); }); -unitTest({ perms: { env: true } }, function hostnameDir(): void { +unitTest({ perms: { env: true } }, function hostnameDir() { assertNotEquals(Deno.hostname(), ""); }); -unitTest({ perms: { env: false } }, function hostnamePerm(): void { +unitTest({ perms: { env: false } }, function hostnamePerm() { assertThrows(() => { Deno.hostname(); }, Deno.errors.PermissionDenied); }); -unitTest({ perms: { env: true } }, function releaseDir(): void { +unitTest({ perms: { env: true } }, function releaseDir() { assertNotEquals(Deno.osRelease(), ""); }); -unitTest({ perms: { env: false } }, function releasePerm(): void { +unitTest({ perms: { env: false } }, function releasePerm() { assertThrows(() => { Deno.osRelease(); }, Deno.errors.PermissionDenied); }); -unitTest({ perms: { env: true } }, function systemMemoryInfo(): void { +unitTest({ perms: { env: true } }, function systemMemoryInfo() { const info = Deno.systemMemoryInfo(); assert(info.total >= 0); assert(info.free >= 0); diff --git a/cli/tests/unit/path_from_url_test.ts b/cli/tests/unit/path_from_url_test.ts index d086ce1dc5..887b423665 100644 --- a/cli/tests/unit/path_from_url_test.ts +++ b/cli/tests/unit/path_from_url_test.ts @@ -5,7 +5,7 @@ const { pathFromURL } = Deno[Deno.internal]; unitTest( { ignore: Deno.build.os === "windows" }, - function pathFromURLPosix(): void { + function pathFromURLPosix() { assertEquals( pathFromURL(new URL("file:///test/directory")), "/test/directory", @@ -17,7 +17,7 @@ unitTest( unitTest( { ignore: Deno.build.os !== "windows" }, - function pathFromURLWin32(): void { + function pathFromURLWin32() { assertEquals( pathFromURL(new URL("file:///c:/windows/test")), "c:\\windows\\test", diff --git a/cli/tests/unit/performance_test.ts b/cli/tests/unit/performance_test.ts index 94af0731c8..989d221d87 100644 --- a/cli/tests/unit/performance_test.ts +++ b/cli/tests/unit/performance_test.ts @@ -8,12 +8,10 @@ import { unitTest, } from "./test_util.ts"; -unitTest({ perms: { hrtime: false } }, async function performanceNow(): Promise< - void -> { +unitTest({ perms: { hrtime: false } }, async function performanceNow() { const resolvable = deferred(); const start = performance.now(); - setTimeout((): void => { + setTimeout(() => { const end = performance.now(); assert(end - start >= 10); resolvable.resolve(); @@ -82,7 +80,7 @@ unitTest(function performanceMeasure() { }); }); -unitTest(function performanceCustomInspectFunction(): void { +unitTest(function performanceCustomInspectFunction() { assertStringIncludes(Deno.inspect(performance), "Performance"); assertStringIncludes( Deno.inspect(Performance.prototype), @@ -90,7 +88,7 @@ unitTest(function performanceCustomInspectFunction(): void { ); }); -unitTest(function performanceMarkCustomInspectFunction(): void { +unitTest(function performanceMarkCustomInspectFunction() { const mark1 = performance.mark("mark1"); assertStringIncludes(Deno.inspect(mark1), "PerformanceMark"); assertStringIncludes( @@ -99,7 +97,7 @@ unitTest(function performanceMarkCustomInspectFunction(): void { ); }); -unitTest(function performanceMeasureCustomInspectFunction(): void { +unitTest(function performanceMeasureCustomInspectFunction() { const measure1 = performance.measure("measure1"); assertStringIncludes(Deno.inspect(measure1), "PerformanceMeasure"); assertStringIncludes( diff --git a/cli/tests/unit/permissions_test.ts b/cli/tests/unit/permissions_test.ts index 8a6d7e9aa1..d89b1e3555 100644 --- a/cli/tests/unit/permissions_test.ts +++ b/cli/tests/unit/permissions_test.ts @@ -7,14 +7,14 @@ import { unitTest, } from "./test_util.ts"; -unitTest(async function permissionInvalidName(): Promise { +unitTest(async function permissionInvalidName() { await assertThrowsAsync(async () => { // deno-lint-ignore no-explicit-any await Deno.permissions.query({ name: "foo" as any }); }, TypeError); }); -unitTest(async function permissionNetInvalidHost(): Promise { +unitTest(async function permissionNetInvalidHost() { await assertThrowsAsync(async () => { await Deno.permissions.query({ name: "net", host: ":" }); }, URIError); diff --git a/cli/tests/unit/process_test.ts b/cli/tests/unit/process_test.ts index f187efe71c..2d0a15b160 100644 --- a/cli/tests/unit/process_test.ts +++ b/cli/tests/unit/process_test.ts @@ -7,7 +7,7 @@ import { unitTest, } from "./test_util.ts"; -unitTest({ perms: { read: true } }, function runPermissions(): void { +unitTest({ perms: { read: true } }, function runPermissions() { assertThrows(() => { Deno.run({ cmd: [Deno.execPath(), "eval", "console.log('hello world')"] }); }, Deno.errors.PermissionDenied); @@ -15,7 +15,7 @@ unitTest({ perms: { read: true } }, function runPermissions(): void { unitTest( { perms: { run: true, read: true } }, - async function runSuccess(): Promise { + async function runSuccess() { const p = Deno.run({ cmd: [Deno.execPath(), "eval", "console.log('hello world')"], stdout: "piped", @@ -32,7 +32,7 @@ unitTest( unitTest( { perms: { run: true, read: true } }, - async function runUrl(): Promise { + async function runUrl() { const p = Deno.run({ cmd: [ new URL(`file:///${Deno.execPath()}`), @@ -73,7 +73,7 @@ unitTest( unitTest( { perms: { run: true, read: true } }, - function runInvalidStdio(): void { + function runInvalidStdio() { assertThrows(() => Deno.run({ cmd: [Deno.execPath(), "eval", "console.log('hello world')"], @@ -100,7 +100,7 @@ unitTest( unitTest( { perms: { run: true, read: true } }, - async function runCommandFailedWithCode(): Promise { + async function runCommandFailedWithCode() { const p = Deno.run({ cmd: [Deno.execPath(), "eval", "Deno.exit(41 + 1)"], }); @@ -118,7 +118,7 @@ unitTest( ignore: Deno.build.os === "windows", perms: { run: true, read: true }, }, - async function runCommandFailedWithSignal(): Promise { + async function runCommandFailedWithSignal() { const p = Deno.run({ cmd: [Deno.execPath(), "eval", "--unstable", "Deno.kill(Deno.pid, 9)"], }); @@ -130,7 +130,7 @@ unitTest( }, ); -unitTest({ perms: { run: true } }, function runNotFound(): void { +unitTest({ perms: { run: true } }, function runNotFound() { let error; try { Deno.run({ cmd: ["this file hopefully doesn't exist"] }); @@ -143,7 +143,7 @@ unitTest({ perms: { run: true } }, function runNotFound(): void { unitTest( { perms: { write: true, run: true, read: true } }, - async function runWithCwdIsAsync(): Promise { + async function runWithCwdIsAsync() { const enc = new TextEncoder(); const cwd = await Deno.makeTempDir({ prefix: "deno_command_test" }); @@ -287,7 +287,7 @@ unitTest( unitTest( { perms: { run: true, read: true } }, - async function runOutput(): Promise { + async function runOutput() { const p = Deno.run({ cmd: [ Deno.execPath(), @@ -325,7 +325,7 @@ unitTest( unitTest( { perms: { run: true, write: true, read: true } }, - async function runRedirectStdoutStderr(): Promise { + async function runRedirectStdoutStderr() { const tempDir = await Deno.makeTempDir(); const fileName = tempDir + "/redirected_stdio.txt"; const file = await Deno.open(fileName, { @@ -358,7 +358,7 @@ unitTest( unitTest( { perms: { run: true, write: true, read: true } }, - async function runRedirectStdin(): Promise { + async function runRedirectStdin() { const tempDir = await Deno.makeTempDir(); const fileName = tempDir + "/redirected_stdio.txt"; const encoder = new TextEncoder(); @@ -383,7 +383,7 @@ unitTest( unitTest( { perms: { run: true, read: true } }, - async function runEnv(): Promise { + async function runEnv() { const p = Deno.run({ cmd: [ Deno.execPath(), @@ -405,7 +405,7 @@ unitTest( unitTest( { perms: { run: true, read: true } }, - async function runClose(): Promise { + async function runClose() { const p = Deno.run({ cmd: [ Deno.execPath(), @@ -428,7 +428,7 @@ unitTest( unitTest( { perms: { run: true, read: true } }, - async function runKillAfterStatus(): Promise { + async function runKillAfterStatus() { const p = Deno.run({ cmd: [Deno.execPath(), "eval", 'console.log("hello")'], }); @@ -454,7 +454,7 @@ unitTest( }, ); -unitTest(function signalNumbers(): void { +unitTest(function signalNumbers() { if (Deno.build.os === "darwin") { assertEquals(Deno.Signal.SIGSTOP, 17); } else if (Deno.build.os === "linux") { @@ -462,7 +462,7 @@ unitTest(function signalNumbers(): void { } }); -unitTest(function killPermissions(): void { +unitTest(function killPermissions() { assertThrows(() => { // Unlike the other test cases, we don't have permission to spawn a // subprocess we can safely kill. Instead we send SIGCONT to the current @@ -474,7 +474,7 @@ unitTest(function killPermissions(): void { unitTest( { perms: { run: true, read: true } }, - async function killSuccess(): Promise { + async function killSuccess() { const p = Deno.run({ cmd: [Deno.execPath(), "eval", "setTimeout(() => {}, 10000)"], }); @@ -497,7 +497,7 @@ unitTest( }, ); -unitTest({ perms: { run: true, read: true } }, function killFailed(): void { +unitTest({ perms: { run: true, read: true } }, function killFailed() { const p = Deno.run({ cmd: [Deno.execPath(), "eval", "setTimeout(() => {}, 10000)"], }); diff --git a/cli/tests/unit/progressevent_test.ts b/cli/tests/unit/progressevent_test.ts index 6f165de2cf..4d6b4c08f8 100644 --- a/cli/tests/unit/progressevent_test.ts +++ b/cli/tests/unit/progressevent_test.ts @@ -1,7 +1,7 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. import { assertEquals, unitTest } from "./test_util.ts"; -unitTest(function progressEventConstruct(): void { +unitTest(function progressEventConstruct() { const progressEventDefs = new ProgressEvent("progressEventType", {}); assertEquals(progressEventDefs.lengthComputable, false); assertEquals(progressEventDefs.loaded, 0); diff --git a/cli/tests/unit/read_dir_test.ts b/cli/tests/unit/read_dir_test.ts index 829f7bfa22..2e4370153c 100644 --- a/cli/tests/unit/read_dir_test.ts +++ b/cli/tests/unit/read_dir_test.ts @@ -8,7 +8,7 @@ import { unitTest, } from "./test_util.ts"; -function assertSameContent(files: Deno.DirEntry[]): void { +function assertSameContent(files: Deno.DirEntry[]) { let counter = 0; for (const entry of files) { @@ -21,37 +21,35 @@ function assertSameContent(files: Deno.DirEntry[]): void { assertEquals(counter, 1); } -unitTest({ perms: { read: true } }, function readDirSyncSuccess(): void { +unitTest({ perms: { read: true } }, function readDirSyncSuccess() { const files = [...Deno.readDirSync("cli/tests/")]; assertSameContent(files); }); -unitTest({ perms: { read: true } }, function readDirSyncWithUrl(): void { +unitTest({ perms: { read: true } }, function readDirSyncWithUrl() { const files = [...Deno.readDirSync(pathToAbsoluteFileUrl("cli/tests"))]; assertSameContent(files); }); -unitTest({ perms: { read: false } }, function readDirSyncPerm(): void { +unitTest({ perms: { read: false } }, function readDirSyncPerm() { assertThrows(() => { Deno.readDirSync("tests/"); }, Deno.errors.PermissionDenied); }); -unitTest({ perms: { read: true } }, function readDirSyncNotDir(): void { +unitTest({ perms: { read: true } }, function readDirSyncNotDir() { assertThrows(() => { Deno.readDirSync("cli/tests/fixture.json"); }, Error); }); -unitTest({ perms: { read: true } }, function readDirSyncNotFound(): void { +unitTest({ perms: { read: true } }, function readDirSyncNotFound() { assertThrows(() => { Deno.readDirSync("bad_dir_name"); }, Deno.errors.NotFound); }); -unitTest({ perms: { read: true } }, async function readDirSuccess(): Promise< - void -> { +unitTest({ perms: { read: true } }, async function readDirSuccess() { const files = []; for await (const dirEntry of Deno.readDir("cli/tests/")) { files.push(dirEntry); @@ -59,9 +57,7 @@ unitTest({ perms: { read: true } }, async function readDirSuccess(): Promise< assertSameContent(files); }); -unitTest({ perms: { read: true } }, async function readDirWithUrl(): Promise< - void -> { +unitTest({ perms: { read: true } }, async function readDirWithUrl() { const files = []; for await ( const dirEntry of Deno.readDir(pathToAbsoluteFileUrl("cli/tests")) @@ -71,9 +67,7 @@ unitTest({ perms: { read: true } }, async function readDirWithUrl(): Promise< assertSameContent(files); }); -unitTest({ perms: { read: false } }, async function readDirPerm(): Promise< - void -> { +unitTest({ perms: { read: false } }, async function readDirPerm() { await assertThrowsAsync(async () => { await Deno.readDir("tests/")[Symbol.asyncIterator]().next(); }, Deno.errors.PermissionDenied); @@ -92,7 +86,7 @@ unitTest( unitTest( { perms: { read: true }, ignore: Deno.build.os == "windows" }, - function readDirDevFdSync(): void { + function readDirDevFdSync() { for (const _ of Deno.readDirSync("/dev/fd")) { // We don't actually care whats in here; just that we don't panic on non regular file entries } diff --git a/cli/tests/unit/read_file_test.ts b/cli/tests/unit/read_file_test.ts index d8d1cddf22..f638c7a7ce 100644 --- a/cli/tests/unit/read_file_test.ts +++ b/cli/tests/unit/read_file_test.ts @@ -8,7 +8,7 @@ import { unitTest, } from "./test_util.ts"; -unitTest({ perms: { read: true } }, function readFileSyncSuccess(): void { +unitTest({ perms: { read: true } }, function readFileSyncSuccess() { const data = Deno.readFileSync("cli/tests/fixture.json"); assert(data.byteLength > 0); const decoder = new TextDecoder("utf-8"); @@ -17,7 +17,7 @@ unitTest({ perms: { read: true } }, function readFileSyncSuccess(): void { assertEquals(pkg.name, "deno"); }); -unitTest({ perms: { read: true } }, function readFileSyncUrl(): void { +unitTest({ perms: { read: true } }, function readFileSyncUrl() { const data = Deno.readFileSync( pathToAbsoluteFileUrl("cli/tests/fixture.json"), ); @@ -28,21 +28,19 @@ unitTest({ perms: { read: true } }, function readFileSyncUrl(): void { assertEquals(pkg.name, "deno"); }); -unitTest({ perms: { read: false } }, function readFileSyncPerm(): void { +unitTest({ perms: { read: false } }, function readFileSyncPerm() { assertThrows(() => { Deno.readFileSync("cli/tests/fixture.json"); }, Deno.errors.PermissionDenied); }); -unitTest({ perms: { read: true } }, function readFileSyncNotFound(): void { +unitTest({ perms: { read: true } }, function readFileSyncNotFound() { assertThrows(() => { Deno.readFileSync("bad_filename"); }, Deno.errors.NotFound); }); -unitTest({ perms: { read: true } }, async function readFileUrl(): Promise< - void -> { +unitTest({ perms: { read: true } }, async function readFileUrl() { const data = await Deno.readFile( pathToAbsoluteFileUrl("cli/tests/fixture.json"), ); @@ -53,9 +51,7 @@ unitTest({ perms: { read: true } }, async function readFileUrl(): Promise< assertEquals(pkg.name, "deno"); }); -unitTest({ perms: { read: true } }, async function readFileSuccess(): Promise< - void -> { +unitTest({ perms: { read: true } }, async function readFileSuccess() { const data = await Deno.readFile("cli/tests/fixture.json"); assert(data.byteLength > 0); const decoder = new TextDecoder("utf-8"); @@ -64,15 +60,13 @@ unitTest({ perms: { read: true } }, async function readFileSuccess(): Promise< assertEquals(pkg.name, "deno"); }); -unitTest({ perms: { read: false } }, async function readFilePerm(): Promise< - void -> { +unitTest({ perms: { read: false } }, async function readFilePerm() { await assertThrowsAsync(async () => { await Deno.readFile("cli/tests/fixture.json"); }, Deno.errors.PermissionDenied); }); -unitTest({ perms: { read: true } }, function readFileSyncLoop(): void { +unitTest({ perms: { read: true } }, function readFileSyncLoop() { for (let i = 0; i < 256; i++) { Deno.readFileSync("cli/tests/fixture.json"); } @@ -80,7 +74,7 @@ unitTest({ perms: { read: true } }, function readFileSyncLoop(): void { unitTest( { perms: { read: true } }, - async function readFileDoesNotLeakResources(): Promise { + async function readFileDoesNotLeakResources() { const resourcesBefore = Deno.resources(); await assertThrowsAsync(async () => await Deno.readFile("cli")); assertEquals(resourcesBefore, Deno.resources()); @@ -89,7 +83,7 @@ unitTest( unitTest( { perms: { read: true } }, - function readFileSyncDoesNotLeakResources(): void { + function readFileSyncDoesNotLeakResources() { const resourcesBefore = Deno.resources(); assertThrows(() => Deno.readFileSync("cli")); assertEquals(resourcesBefore, Deno.resources()); @@ -98,7 +92,7 @@ unitTest( unitTest( { perms: { read: true } }, - async function readFileWithAbortSignal(): Promise { + async function readFileWithAbortSignal() { const ac = new AbortController(); queueMicrotask(() => ac.abort()); await assertThrowsAsync(async () => { @@ -109,7 +103,7 @@ unitTest( unitTest( { perms: { read: true } }, - async function readTextileWithAbortSignal(): Promise { + async function readTextileWithAbortSignal() { const ac = new AbortController(); queueMicrotask(() => ac.abort()); await assertThrowsAsync(async () => { diff --git a/cli/tests/unit/read_link_test.ts b/cli/tests/unit/read_link_test.ts index cab27cbdcf..3d00cda1ac 100644 --- a/cli/tests/unit/read_link_test.ts +++ b/cli/tests/unit/read_link_test.ts @@ -9,7 +9,7 @@ import { unitTest( { perms: { write: true, read: true } }, - function readLinkSyncSuccess(): void { + function readLinkSyncSuccess() { const testDir = Deno.makeTempDirSync(); const target = testDir + (Deno.build.os == "windows" ? "\\target" : "/target"); @@ -24,7 +24,7 @@ unitTest( unitTest( { perms: { write: true, read: true } }, - function readLinkSyncUrlSuccess(): void { + function readLinkSyncUrlSuccess() { const testDir = Deno.makeTempDirSync(); const target = testDir + (Deno.build.os == "windows" ? "\\target" : "/target"); @@ -37,13 +37,13 @@ unitTest( }, ); -unitTest({ perms: { read: false } }, function readLinkSyncPerm(): void { +unitTest({ perms: { read: false } }, function readLinkSyncPerm() { assertThrows(() => { Deno.readLinkSync("/symlink"); }, Deno.errors.PermissionDenied); }); -unitTest({ perms: { read: true } }, function readLinkSyncNotFound(): void { +unitTest({ perms: { read: true } }, function readLinkSyncNotFound() { assertThrows(() => { Deno.readLinkSync("bad_filename"); }, Deno.errors.NotFound); @@ -51,7 +51,7 @@ unitTest({ perms: { read: true } }, function readLinkSyncNotFound(): void { unitTest( { perms: { write: true, read: true } }, - async function readLinkSuccess(): Promise { + async function readLinkSuccess() { const testDir = Deno.makeTempDirSync(); const target = testDir + (Deno.build.os == "windows" ? "\\target" : "/target"); @@ -66,7 +66,7 @@ unitTest( unitTest( { perms: { write: true, read: true } }, - async function readLinkUrlSuccess(): Promise { + async function readLinkUrlSuccess() { const testDir = Deno.makeTempDirSync(); const target = testDir + (Deno.build.os == "windows" ? "\\target" : "/target"); @@ -79,9 +79,7 @@ unitTest( }, ); -unitTest({ perms: { read: false } }, async function readLinkPerm(): Promise< - void -> { +unitTest({ perms: { read: false } }, async function readLinkPerm() { await assertThrowsAsync(async () => { await Deno.readLink("/symlink"); }, Deno.errors.PermissionDenied); diff --git a/cli/tests/unit/read_text_file_test.ts b/cli/tests/unit/read_text_file_test.ts index 2223d9c185..a7eb1a7303 100644 --- a/cli/tests/unit/read_text_file_test.ts +++ b/cli/tests/unit/read_text_file_test.ts @@ -7,14 +7,14 @@ import { unitTest, } from "./test_util.ts"; -unitTest({ perms: { read: true } }, function readTextFileSyncSuccess(): void { +unitTest({ perms: { read: true } }, function readTextFileSyncSuccess() { const data = Deno.readTextFileSync("cli/tests/fixture.json"); assert(data.length > 0); const pkg = JSON.parse(data); assertEquals(pkg.name, "deno"); }); -unitTest({ perms: { read: true } }, function readTextFileSyncByUrl(): void { +unitTest({ perms: { read: true } }, function readTextFileSyncByUrl() { const data = Deno.readTextFileSync( pathToAbsoluteFileUrl("cli/tests/fixture.json"), ); @@ -23,13 +23,13 @@ unitTest({ perms: { read: true } }, function readTextFileSyncByUrl(): void { assertEquals(pkg.name, "deno"); }); -unitTest({ perms: { read: false } }, function readTextFileSyncPerm(): void { +unitTest({ perms: { read: false } }, function readTextFileSyncPerm() { assertThrows(() => { Deno.readTextFileSync("cli/tests/fixture.json"); }, Deno.errors.PermissionDenied); }); -unitTest({ perms: { read: true } }, function readTextFileSyncNotFound(): void { +unitTest({ perms: { read: true } }, function readTextFileSyncNotFound() { assertThrows(() => { Deno.readTextFileSync("bad_filename"); }, Deno.errors.NotFound); @@ -37,7 +37,7 @@ unitTest({ perms: { read: true } }, function readTextFileSyncNotFound(): void { unitTest( { perms: { read: true } }, - async function readTextFileSuccess(): Promise { + async function readTextFileSuccess() { const data = await Deno.readTextFile("cli/tests/fixture.json"); assert(data.length > 0); const pkg = JSON.parse(data); @@ -45,9 +45,7 @@ unitTest( }, ); -unitTest({ perms: { read: true } }, async function readTextFileByUrl(): Promise< - void -> { +unitTest({ perms: { read: true } }, async function readTextFileByUrl() { const data = await Deno.readTextFile( pathToAbsoluteFileUrl("cli/tests/fixture.json"), ); @@ -56,15 +54,13 @@ unitTest({ perms: { read: true } }, async function readTextFileByUrl(): Promise< assertEquals(pkg.name, "deno"); }); -unitTest({ perms: { read: false } }, async function readTextFilePerm(): Promise< - void -> { +unitTest({ perms: { read: false } }, async function readTextFilePerm() { await assertThrowsAsync(async () => { await Deno.readTextFile("cli/tests/fixture.json"); }, Deno.errors.PermissionDenied); }); -unitTest({ perms: { read: true } }, function readTextFileSyncLoop(): void { +unitTest({ perms: { read: true } }, function readTextFileSyncLoop() { for (let i = 0; i < 256; i++) { Deno.readTextFileSync("cli/tests/fixture.json"); } @@ -72,7 +68,7 @@ unitTest({ perms: { read: true } }, function readTextFileSyncLoop(): void { unitTest( { perms: { read: true } }, - async function readTextFileDoesNotLeakResources(): Promise { + async function readTextFileDoesNotLeakResources() { const resourcesBefore = Deno.resources(); await assertThrowsAsync(async () => await Deno.readTextFile("cli")); assertEquals(resourcesBefore, Deno.resources()); @@ -81,7 +77,7 @@ unitTest( unitTest( { perms: { read: true } }, - function readTextFileSyncDoesNotLeakResources(): void { + function readTextFileSyncDoesNotLeakResources() { const resourcesBefore = Deno.resources(); assertThrows(() => Deno.readTextFileSync("cli")); assertEquals(resourcesBefore, Deno.resources()); diff --git a/cli/tests/unit/real_path_test.ts b/cli/tests/unit/real_path_test.ts index 10e060578c..b84b0c0df2 100644 --- a/cli/tests/unit/real_path_test.ts +++ b/cli/tests/unit/real_path_test.ts @@ -9,7 +9,7 @@ import { unitTest, } from "./test_util.ts"; -unitTest({ perms: { read: true } }, function realPathSyncSuccess(): void { +unitTest({ perms: { read: true } }, function realPathSyncSuccess() { const relative = "cli/tests/fixture.json"; const realPath = Deno.realPathSync(relative); if (Deno.build.os !== "windows") { @@ -21,7 +21,7 @@ unitTest({ perms: { read: true } }, function realPathSyncSuccess(): void { } }); -unitTest({ perms: { read: true } }, function realPathSyncUrl(): void { +unitTest({ perms: { read: true } }, function realPathSyncUrl() { const relative = "cli/tests/fixture.json"; const url = pathToAbsoluteFileUrl(relative); assertEquals(Deno.realPathSync(relative), Deno.realPathSync(url)); @@ -31,7 +31,7 @@ unitTest( { perms: { read: true, write: true }, }, - function realPathSyncSymlink(): void { + function realPathSyncSymlink() { const testDir = Deno.makeTempDirSync(); const target = testDir + "/target"; const symlink = testDir + "/symln"; @@ -48,21 +48,19 @@ unitTest( }, ); -unitTest({ perms: { read: false } }, function realPathSyncPerm(): void { +unitTest({ perms: { read: false } }, function realPathSyncPerm() { assertThrows(() => { Deno.realPathSync("some_file"); }, Deno.errors.PermissionDenied); }); -unitTest({ perms: { read: true } }, function realPathSyncNotFound(): void { +unitTest({ perms: { read: true } }, function realPathSyncNotFound() { assertThrows(() => { Deno.realPathSync("bad_filename"); }, Deno.errors.NotFound); }); -unitTest({ perms: { read: true } }, async function realPathSuccess(): Promise< - void -> { +unitTest({ perms: { read: true } }, async function realPathSuccess() { const relativePath = "cli/tests/fixture.json"; const realPath = await Deno.realPath(relativePath); if (Deno.build.os !== "windows") { @@ -76,7 +74,7 @@ unitTest({ perms: { read: true } }, async function realPathSuccess(): Promise< unitTest( { perms: { read: true } }, - async function realPathUrl(): Promise { + async function realPathUrl() { const relative = "cli/tests/fixture.json"; const url = pathToAbsoluteFileUrl(relative); assertEquals(await Deno.realPath(relative), await Deno.realPath(url)); @@ -87,7 +85,7 @@ unitTest( { perms: { read: true, write: true }, }, - async function realPathSymlink(): Promise { + async function realPathSymlink() { const testDir = Deno.makeTempDirSync(); const target = testDir + "/target"; const symlink = testDir + "/symln"; @@ -104,17 +102,13 @@ unitTest( }, ); -unitTest({ perms: { read: false } }, async function realPathPerm(): Promise< - void -> { +unitTest({ perms: { read: false } }, async function realPathPerm() { await assertThrowsAsync(async () => { await Deno.realPath("some_file"); }, Deno.errors.PermissionDenied); }); -unitTest({ perms: { read: true } }, async function realPathNotFound(): Promise< - void -> { +unitTest({ perms: { read: true } }, async function realPathNotFound() { await assertThrowsAsync(async () => { await Deno.realPath("bad_filename"); }, Deno.errors.NotFound); diff --git a/cli/tests/unit/remove_test.ts b/cli/tests/unit/remove_test.ts index 087cc3a73b..5f39b1c79e 100644 --- a/cli/tests/unit/remove_test.ts +++ b/cli/tests/unit/remove_test.ts @@ -10,7 +10,7 @@ const REMOVE_METHODS = ["remove", "removeSync"] as const; unitTest( { perms: { write: true, read: true } }, - async function removeDirSuccess(): Promise { + async function removeDirSuccess() { for (const method of REMOVE_METHODS) { // REMOVE EMPTY DIRECTORY const path = Deno.makeTempDirSync() + "/subdir"; @@ -28,7 +28,7 @@ unitTest( unitTest( { perms: { write: true, read: true } }, - async function removeFileSuccess(): Promise { + async function removeFileSuccess() { for (const method of REMOVE_METHODS) { // REMOVE FILE const enc = new TextEncoder(); @@ -48,7 +48,7 @@ unitTest( unitTest( { perms: { write: true, read: true } }, - async function removeFileByUrl(): Promise { + async function removeFileByUrl() { for (const method of REMOVE_METHODS) { // REMOVE FILE const enc = new TextEncoder(); @@ -73,7 +73,7 @@ unitTest( unitTest( { perms: { write: true, read: true } }, - async function removeFail(): Promise { + async function removeFail() { for (const method of REMOVE_METHODS) { // NON-EMPTY DIRECTORY const path = Deno.makeTempDirSync() + "/dir/subdir"; @@ -100,7 +100,7 @@ unitTest( unitTest( { perms: { write: true, read: true } }, - async function removeDanglingSymlinkSuccess(): Promise { + async function removeDanglingSymlinkSuccess() { for (const method of REMOVE_METHODS) { const danglingSymlinkPath = Deno.makeTempDirSync() + "/dangling_symlink"; if (Deno.build.os === "windows") { @@ -122,7 +122,7 @@ unitTest( unitTest( { perms: { write: true, read: true } }, - async function removeValidSymlinkSuccess(): Promise { + async function removeValidSymlinkSuccess() { for (const method of REMOVE_METHODS) { const encoder = new TextEncoder(); const data = encoder.encode("Test"); @@ -146,9 +146,7 @@ unitTest( }, ); -unitTest({ perms: { write: false } }, async function removePerm(): Promise< - void -> { +unitTest({ perms: { write: false } }, async function removePerm() { for (const method of REMOVE_METHODS) { await assertThrowsAsync(async () => { await Deno[method]("/baddir"); @@ -158,7 +156,7 @@ unitTest({ perms: { write: false } }, async function removePerm(): Promise< unitTest( { perms: { write: true, read: true } }, - async function removeAllDirSuccess(): Promise { + async function removeAllDirSuccess() { for (const method of REMOVE_METHODS) { // REMOVE EMPTY DIRECTORY let path = Deno.makeTempDirSync() + "/dir/subdir"; @@ -195,7 +193,7 @@ unitTest( unitTest( { perms: { write: true, read: true } }, - async function removeAllFileSuccess(): Promise { + async function removeAllFileSuccess() { for (const method of REMOVE_METHODS) { // REMOVE FILE const enc = new TextEncoder(); @@ -214,9 +212,7 @@ unitTest( }, ); -unitTest({ perms: { write: true } }, async function removeAllFail(): Promise< - void -> { +unitTest({ perms: { write: true } }, async function removeAllFail() { for (const method of REMOVE_METHODS) { // NON-EXISTENT DIRECTORY/FILE await assertThrowsAsync(async () => { @@ -226,9 +222,7 @@ unitTest({ perms: { write: true } }, async function removeAllFail(): Promise< } }); -unitTest({ perms: { write: false } }, async function removeAllPerm(): Promise< - void -> { +unitTest({ perms: { write: false } }, async function removeAllPerm() { for (const method of REMOVE_METHODS) { await assertThrowsAsync(async () => { await Deno[method]("/baddir", { recursive: true }); @@ -241,7 +235,7 @@ unitTest( ignore: Deno.build.os === "windows", perms: { write: true, read: true }, }, - async function removeUnixSocketSuccess(): Promise { + async function removeUnixSocketSuccess() { for (const method of REMOVE_METHODS) { // MAKE TEMPORARY UNIX SOCKET const path = Deno.makeTempDirSync() + "/test.sock"; @@ -260,7 +254,7 @@ unitTest( if (Deno.build.os === "windows") { unitTest( { perms: { run: true, write: true, read: true } }, - async function removeFileSymlink(): Promise { + async function removeFileSymlink() { const symlink = Deno.run({ cmd: ["cmd", "/c", "mklink", "file_link", "bar"], stdout: "null", @@ -277,7 +271,7 @@ if (Deno.build.os === "windows") { unitTest( { perms: { run: true, write: true, read: true } }, - async function removeDirSymlink(): Promise { + async function removeDirSymlink() { const symlink = Deno.run({ cmd: ["cmd", "/c", "mklink", "/d", "dir_link", "bar"], stdout: "null", diff --git a/cli/tests/unit/rename_test.ts b/cli/tests/unit/rename_test.ts index 711b63aa73..c5df8e4a42 100644 --- a/cli/tests/unit/rename_test.ts +++ b/cli/tests/unit/rename_test.ts @@ -7,7 +7,7 @@ import { unitTest, } from "./test_util.ts"; -function assertMissing(path: string): void { +function assertMissing(path: string) { let caughtErr = false; let info; try { @@ -20,12 +20,12 @@ function assertMissing(path: string): void { assertEquals(info, undefined); } -function assertFile(path: string): void { +function assertFile(path: string) { const info = Deno.lstatSync(path); assert(info.isFile); } -function assertDirectory(path: string, mode?: number): void { +function assertDirectory(path: string, mode?: number) { const info = Deno.lstatSync(path); assert(info.isDirectory); if (Deno.build.os !== "windows" && mode !== undefined) { @@ -35,7 +35,7 @@ function assertDirectory(path: string, mode?: number): void { unitTest( { perms: { read: true, write: true } }, - function renameSyncSuccess(): void { + function renameSyncSuccess() { const testDir = Deno.makeTempDirSync(); const oldpath = testDir + "/oldpath"; const newpath = testDir + "/newpath"; @@ -48,7 +48,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - function renameSyncWithURL(): void { + function renameSyncWithURL() { const testDir = Deno.makeTempDirSync(); const oldpath = testDir + "/oldpath"; const newpath = testDir + "/newpath"; @@ -64,7 +64,7 @@ unitTest( unitTest( { perms: { read: false, write: true } }, - function renameSyncReadPerm(): void { + function renameSyncReadPerm() { assertThrows(() => { const oldpath = "/oldbaddir"; const newpath = "/newbaddir"; @@ -75,7 +75,7 @@ unitTest( unitTest( { perms: { read: true, write: false } }, - function renameSyncWritePerm(): void { + function renameSyncWritePerm() { assertThrows(() => { const oldpath = "/oldbaddir"; const newpath = "/newbaddir"; @@ -86,7 +86,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function renameSuccess(): Promise { + async function renameSuccess() { const testDir = Deno.makeTempDirSync(); const oldpath = testDir + "/oldpath"; const newpath = testDir + "/newpath"; @@ -99,7 +99,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function renameWithURL(): Promise { + async function renameWithURL() { const testDir = Deno.makeTempDirSync(); const oldpath = testDir + "/oldpath"; const newpath = testDir + "/newpath"; @@ -119,7 +119,7 @@ function readFileString(filename: string): string { return dec.decode(dataRead); } -function writeFileString(filename: string, s: string): void { +function writeFileString(filename: string, s: string) { const enc = new TextEncoder(); const data = enc.encode(s); Deno.writeFileSync(filename, data, { mode: 0o666 }); @@ -127,7 +127,7 @@ function writeFileString(filename: string, s: string): void { unitTest( { ignore: Deno.build.os === "windows", perms: { read: true, write: true } }, - function renameSyncErrorsUnix(): void { + function renameSyncErrorsUnix() { const testDir = Deno.makeTempDirSync(); const oldfile = testDir + "/oldfile"; const olddir = testDir + "/olddir"; @@ -141,21 +141,21 @@ unitTest( writeFileString(file, "world"); assertThrows( - (): void => { + () => { Deno.renameSync(oldfile, emptydir); }, Error, "Is a directory", ); assertThrows( - (): void => { + () => { Deno.renameSync(olddir, fulldir); }, Error, "Directory not empty", ); assertThrows( - (): void => { + () => { Deno.renameSync(olddir, file); }, Error, @@ -170,21 +170,21 @@ unitTest( Deno.symlinkSync(testDir + "/nonexistent", danglingLink); assertThrows( - (): void => { + () => { Deno.renameSync(olddir, fileLink); }, Error, "Not a directory", ); assertThrows( - (): void => { + () => { Deno.renameSync(olddir, dirLink); }, Error, "Not a directory", ); assertThrows( - (): void => { + () => { Deno.renameSync(olddir, danglingLink); }, Error, @@ -202,7 +202,7 @@ unitTest( unitTest( { ignore: Deno.build.os !== "windows", perms: { read: true, write: true } }, - function renameSyncErrorsWin(): void { + function renameSyncErrorsWin() { const testDir = Deno.makeTempDirSync(); const oldfile = testDir + "/oldfile"; const olddir = testDir + "/olddir"; @@ -216,21 +216,21 @@ unitTest( writeFileString(file, "world"); assertThrows( - (): void => { + () => { Deno.renameSync(oldfile, emptydir); }, Deno.errors.PermissionDenied, "Access is denied", ); assertThrows( - (): void => { + () => { Deno.renameSync(olddir, fulldir); }, Deno.errors.PermissionDenied, "Access is denied", ); assertThrows( - (): void => { + () => { Deno.renameSync(olddir, emptydir); }, Deno.errors.PermissionDenied, diff --git a/cli/tests/unit/request_test.ts b/cli/tests/unit/request_test.ts index dca9e4a73d..8f31d7d5d9 100644 --- a/cli/tests/unit/request_test.ts +++ b/cli/tests/unit/request_test.ts @@ -1,7 +1,7 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. import { assertEquals, assertStringIncludes, unitTest } from "./test_util.ts"; -unitTest(async function fromInit(): Promise { +unitTest(async function fromInit() { const req = new Request("http://foo/", { body: "ahoyhoy", method: "POST", @@ -15,7 +15,7 @@ unitTest(async function fromInit(): Promise { assertEquals(req.headers.get("test-header"), "value"); }); -unitTest(function requestNonString(): void { +unitTest(function requestNonString() { const nonString = { toString() { return "http://foo/"; @@ -26,18 +26,18 @@ unitTest(function requestNonString(): void { assertEquals(new Request(nonString).url, "http://foo/"); }); -unitTest(function methodNonString(): void { +unitTest(function methodNonString() { assertEquals(new Request("http://foo/", { method: undefined }).method, "GET"); }); -unitTest(function requestRelativeUrl(): void { +unitTest(function requestRelativeUrl() { assertEquals( new Request("relative-url").url, "http://js-unit-tests/foo/relative-url", ); }); -unitTest(async function cloneRequestBodyStream(): Promise { +unitTest(async function cloneRequestBodyStream() { // hack to get a stream const stream = new Request("http://foo/", { body: "a test body", method: "POST" }).body; @@ -54,7 +54,7 @@ unitTest(async function cloneRequestBodyStream(): Promise { assertEquals(b1, b2); }); -unitTest(function customInspectFunction(): void { +unitTest(function customInspectFunction() { const request = new Request("https://example.com"); assertEquals( Deno.inspect(request), diff --git a/cli/tests/unit/resources_test.ts b/cli/tests/unit/resources_test.ts index 96fd4ff2c0..ea183a0687 100644 --- a/cli/tests/unit/resources_test.ts +++ b/cli/tests/unit/resources_test.ts @@ -1,13 +1,13 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. import { assert, assertEquals, assertThrows, unitTest } from "./test_util.ts"; -unitTest(function resourcesCloseBadArgs(): void { +unitTest(function resourcesCloseBadArgs() { assertThrows(() => { Deno.close((null as unknown) as number); }, TypeError); }); -unitTest(function resourcesStdio(): void { +unitTest(function resourcesStdio() { const res = Deno.resources(); assertEquals(res[0], "stdin"); @@ -15,9 +15,7 @@ unitTest(function resourcesStdio(): void { assertEquals(res[2], "stderr"); }); -unitTest({ perms: { net: true } }, async function resourcesNet(): Promise< - void -> { +unitTest({ perms: { net: true } }, async function resourcesNet() { const listener = Deno.listen({ port: 4501 }); const dialerConn = await Deno.connect({ port: 4501 }); const listenerConn = await listener.accept(); @@ -37,9 +35,7 @@ unitTest({ perms: { net: true } }, async function resourcesNet(): Promise< listener.close(); }); -unitTest({ perms: { read: true } }, async function resourcesFile(): Promise< - void -> { +unitTest({ perms: { read: true } }, async function resourcesFile() { const resourcesBefore = Deno.resources(); const f = await Deno.open("cli/tests/hello.txt"); const resourcesAfter = Deno.resources(); diff --git a/cli/tests/unit/response_test.ts b/cli/tests/unit/response_test.ts index c1ef80fb63..3f6197e1f8 100644 --- a/cli/tests/unit/response_test.ts +++ b/cli/tests/unit/response_test.ts @@ -56,7 +56,7 @@ unitTest(async function responseFormData() { assertEquals([...formData], [...input]); }); -unitTest(function customInspectFunction(): void { +unitTest(function customInspectFunction() { const response = new Response(); assertEquals( Deno.inspect(response), diff --git a/cli/tests/unit/signal_test.ts b/cli/tests/unit/signal_test.ts index 340ec43eb8..d0cd40950a 100644 --- a/cli/tests/unit/signal_test.ts +++ b/cli/tests/unit/signal_test.ts @@ -10,7 +10,7 @@ import { unitTest( { ignore: Deno.build.os !== "windows" }, - function signalsNotImplemented(): void { + function signalsNotImplemented() { assertThrows( () => { Deno.signal(1); @@ -100,7 +100,7 @@ unitTest( unitTest( { ignore: Deno.build.os === "windows", perms: { run: true, net: true } }, - async function signalStreamTest(): Promise { + async function signalStreamTest() { const resolvable = deferred(); // This prevents the program from exiting. const t = setInterval(() => {}, 1000); @@ -132,7 +132,7 @@ unitTest( // This tests that pending op_signal_poll doesn't block the runtime from exiting the process. unitTest( { ignore: Deno.build.os === "windows", perms: { run: true, read: true } }, - async function signalStreamExitTest(): Promise { + async function signalStreamExitTest() { const p = Deno.run({ cmd: [ Deno.execPath(), @@ -149,7 +149,7 @@ unitTest( unitTest( { ignore: Deno.build.os === "windows", perms: { run: true } }, - async function signalPromiseTest(): Promise { + async function signalPromiseTest() { const resolvable = deferred(); // This prevents the program from exiting. const t = setInterval(() => {}, 1000); @@ -170,7 +170,7 @@ unitTest( // https://github.com/denoland/deno/issues/9806 unitTest( { ignore: Deno.build.os === "windows", perms: { run: true } }, - async function signalPromiseTest2(): Promise { + async function signalPromiseTest2() { const resolvable = deferred(); // This prevents the program from exiting. const t = setInterval(() => {}, 1000); @@ -198,7 +198,7 @@ unitTest( unitTest( { ignore: Deno.build.os === "windows", perms: { run: true } }, - function signalShorthandsTest(): void { + function signalShorthandsTest() { let s: Deno.SignalStream; s = Deno.signals.alarm(); // for SIGALRM assert(s instanceof Deno.SignalStream); diff --git a/cli/tests/unit/stat_test.ts b/cli/tests/unit/stat_test.ts index d75eb22ebc..4b663e5b92 100644 --- a/cli/tests/unit/stat_test.ts +++ b/cli/tests/unit/stat_test.ts @@ -8,7 +8,7 @@ import { unitTest, } from "./test_util.ts"; -unitTest({ perms: { read: true } }, function fstatSyncSuccess(): void { +unitTest({ perms: { read: true } }, function fstatSyncSuccess() { const file = Deno.openSync("README.md"); const fileInfo = Deno.fstatSync(file.rid); assert(fileInfo.isFile); @@ -23,9 +23,7 @@ unitTest({ perms: { read: true } }, function fstatSyncSuccess(): void { Deno.close(file.rid); }); -unitTest({ perms: { read: true } }, async function fstatSuccess(): Promise< - void -> { +unitTest({ perms: { read: true } }, async function fstatSuccess() { const file = await Deno.open("README.md"); const fileInfo = await Deno.fstat(file.rid); assert(fileInfo.isFile); @@ -42,7 +40,7 @@ unitTest({ perms: { read: true } }, async function fstatSuccess(): Promise< unitTest( { perms: { read: true, write: true } }, - function statSyncSuccess(): void { + function statSyncSuccess() { const packageInfo = Deno.statSync("README.md"); assert(packageInfo.isFile); assert(!packageInfo.isSymlink); @@ -103,19 +101,19 @@ unitTest( }, ); -unitTest({ perms: { read: false } }, function statSyncPerm(): void { +unitTest({ perms: { read: false } }, function statSyncPerm() { assertThrows(() => { Deno.statSync("README.md"); }, Deno.errors.PermissionDenied); }); -unitTest({ perms: { read: true } }, function statSyncNotFound(): void { +unitTest({ perms: { read: true } }, function statSyncNotFound() { assertThrows(() => { Deno.statSync("bad_file_name"); }, Deno.errors.NotFound); }); -unitTest({ perms: { read: true } }, function lstatSyncSuccess(): void { +unitTest({ perms: { read: true } }, function lstatSyncSuccess() { const packageInfo = Deno.lstatSync("README.md"); assert(packageInfo.isFile); assert(!packageInfo.isSymlink); @@ -143,13 +141,13 @@ unitTest({ perms: { read: true } }, function lstatSyncSuccess(): void { assert(!coreInfoByUrl.isSymlink); }); -unitTest({ perms: { read: false } }, function lstatSyncPerm(): void { +unitTest({ perms: { read: false } }, function lstatSyncPerm() { assertThrows(() => { Deno.lstatSync("README.md"); }, Deno.errors.PermissionDenied); }); -unitTest({ perms: { read: true } }, function lstatSyncNotFound(): void { +unitTest({ perms: { read: true } }, function lstatSyncNotFound() { assertThrows(() => { Deno.lstatSync("bad_file_name"); }, Deno.errors.NotFound); @@ -157,7 +155,7 @@ unitTest({ perms: { read: true } }, function lstatSyncNotFound(): void { unitTest( { perms: { read: true, write: true } }, - async function statSuccess(): Promise { + async function statSuccess() { const packageInfo = await Deno.stat("README.md"); assert(packageInfo.isFile); assert(!packageInfo.isSymlink); @@ -221,25 +219,21 @@ unitTest( }, ); -unitTest({ perms: { read: false } }, async function statPerm(): Promise { +unitTest({ perms: { read: false } }, async function statPerm() { await assertThrowsAsync(async () => { await Deno.stat("README.md"); }, Deno.errors.PermissionDenied); }); -unitTest({ perms: { read: true } }, async function statNotFound(): Promise< - void -> { +unitTest({ perms: { read: true } }, async function statNotFound() { await assertThrowsAsync( - async (): Promise => { + async () => { await Deno.stat("bad_file_name"), Deno.errors.NotFound; }, ); }); -unitTest({ perms: { read: true } }, async function lstatSuccess(): Promise< - void -> { +unitTest({ perms: { read: true } }, async function lstatSuccess() { const packageInfo = await Deno.lstat("README.md"); assert(packageInfo.isFile); assert(!packageInfo.isSymlink); @@ -267,15 +261,13 @@ unitTest({ perms: { read: true } }, async function lstatSuccess(): Promise< assert(!coreInfoByUrl.isSymlink); }); -unitTest({ perms: { read: false } }, async function lstatPerm(): Promise { +unitTest({ perms: { read: false } }, async function lstatPerm() { await assertThrowsAsync(async () => { await Deno.lstat("README.md"); }, Deno.errors.PermissionDenied); }); -unitTest({ perms: { read: true } }, async function lstatNotFound(): Promise< - void -> { +unitTest({ perms: { read: true } }, async function lstatNotFound() { await assertThrowsAsync(async () => { await Deno.lstat("bad_file_name"); }, Deno.errors.NotFound); @@ -283,7 +275,7 @@ unitTest({ perms: { read: true } }, async function lstatNotFound(): Promise< unitTest( { ignore: Deno.build.os !== "windows", perms: { read: true, write: true } }, - function statNoUnixFields(): void { + function statNoUnixFields() { const enc = new TextEncoder(); const data = enc.encode("Hello"); const tempDir = Deno.makeTempDirSync(); @@ -304,7 +296,7 @@ unitTest( unitTest( { ignore: Deno.build.os === "windows", perms: { read: true, write: true } }, - function statUnixFields(): void { + function statUnixFields() { const enc = new TextEncoder(); const data = enc.encode("Hello"); const tempDir = Deno.makeTempDirSync(); diff --git a/cli/tests/unit/symlink_test.ts b/cli/tests/unit/symlink_test.ts index eef993d17b..b9fcd9e7a4 100644 --- a/cli/tests/unit/symlink_test.ts +++ b/cli/tests/unit/symlink_test.ts @@ -8,7 +8,7 @@ import { unitTest( { perms: { read: true, write: true } }, - function symlinkSyncSuccess(): void { + function symlinkSyncSuccess() { const testDir = Deno.makeTempDirSync(); const oldname = testDir + "/oldname"; const newname = testDir + "/newname"; @@ -23,7 +23,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - function symlinkSyncURL(): void { + function symlinkSyncURL() { const testDir = Deno.makeTempDirSync(); const oldname = testDir + "/oldname"; const newname = testDir + "/newname"; @@ -39,7 +39,7 @@ unitTest( }, ); -unitTest(function symlinkSyncPerm(): void { +unitTest(function symlinkSyncPerm() { assertThrows(() => { Deno.symlinkSync("oldbaddir", "newbaddir"); }, Deno.errors.PermissionDenied); @@ -47,7 +47,7 @@ unitTest(function symlinkSyncPerm(): void { unitTest( { perms: { read: true, write: true } }, - async function symlinkSuccess(): Promise { + async function symlinkSuccess() { const testDir = Deno.makeTempDirSync(); const oldname = testDir + "/oldname"; const newname = testDir + "/newname"; @@ -62,7 +62,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function symlinkURL(): Promise { + async function symlinkURL() { const testDir = Deno.makeTempDirSync(); const oldname = testDir + "/oldname"; const newname = testDir + "/newname"; diff --git a/cli/tests/unit/sync_test.ts b/cli/tests/unit/sync_test.ts index 98b2f4bd98..c359513ebd 100644 --- a/cli/tests/unit/sync_test.ts +++ b/cli/tests/unit/sync_test.ts @@ -3,7 +3,7 @@ import { assertEquals, unitTest } from "./test_util.ts"; unitTest( { perms: { read: true, write: true } }, - function fdatasyncSyncSuccess(): void { + function fdatasyncSyncSuccess() { const filename = Deno.makeTempDirSync() + "/test_fdatasyncSync.txt"; const file = Deno.openSync(filename, { read: true, @@ -21,7 +21,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function fdatasyncSuccess(): Promise { + async function fdatasyncSuccess() { const filename = (await Deno.makeTempDir()) + "/test_fdatasync.txt"; const file = await Deno.open(filename, { read: true, @@ -39,7 +39,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - function fsyncSyncSuccess(): void { + function fsyncSyncSuccess() { const filename = Deno.makeTempDirSync() + "/test_fsyncSync.txt"; const file = Deno.openSync(filename, { read: true, @@ -57,7 +57,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function fsyncSuccess(): Promise { + async function fsyncSuccess() { const filename = (await Deno.makeTempDir()) + "/test_fsync.txt"; const file = await Deno.open(filename, { read: true, diff --git a/cli/tests/unit/testing_test.ts b/cli/tests/unit/testing_test.ts index 4789dbfa7f..89b3cc31fb 100644 --- a/cli/tests/unit/testing_test.ts +++ b/cli/tests/unit/testing_test.ts @@ -1,12 +1,12 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. import { assertThrows, unitTest } from "./test_util.ts"; -unitTest(function testFnOverloading(): void { +unitTest(function testFnOverloading() { // just verifying that you can use this test definition syntax - Deno.test("test fn overloading", (): void => {}); + Deno.test("test fn overloading", () => {}); }); -unitTest(function nameOfTestCaseCantBeEmpty(): void { +unitTest(function nameOfTestCaseCantBeEmpty() { assertThrows( () => { Deno.test("", () => {}); diff --git a/cli/tests/unit/text_encoding_test.ts b/cli/tests/unit/text_encoding_test.ts index 42c221cb21..a65a4176bd 100644 --- a/cli/tests/unit/text_encoding_test.ts +++ b/cli/tests/unit/text_encoding_test.ts @@ -1,19 +1,19 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. import { assert, assertEquals, assertThrows, unitTest } from "./test_util.ts"; -unitTest(function btoaSuccess(): void { +unitTest(function btoaSuccess() { const text = "hello world"; const encoded = btoa(text); assertEquals(encoded, "aGVsbG8gd29ybGQ="); }); -unitTest(function atobSuccess(): void { +unitTest(function atobSuccess() { const encoded = "aGVsbG8gd29ybGQ="; const decoded = atob(encoded); assertEquals(decoded, "hello world"); }); -unitTest(function atobWithAsciiWhitespace(): void { +unitTest(function atobWithAsciiWhitespace() { const encodedList = [ " aGVsbG8gd29ybGQ=", " aGVsbG8gd29ybGQ=", @@ -30,7 +30,7 @@ unitTest(function atobWithAsciiWhitespace(): void { } }); -unitTest(function atobThrows(): void { +unitTest(function atobThrows() { let threw = false; try { atob("aGVsbG8gd29ybGQ=="); @@ -40,7 +40,7 @@ unitTest(function atobThrows(): void { assert(threw); }); -unitTest(function atobThrows2(): void { +unitTest(function atobThrows2() { let threw = false; try { atob("aGVsbG8gd29ybGQ==="); @@ -50,7 +50,7 @@ unitTest(function atobThrows2(): void { assert(threw); }); -unitTest(function atobThrows3(): void { +unitTest(function atobThrows3() { let threw = false; try { atob("foobar!!"); @@ -65,14 +65,14 @@ unitTest(function atobThrows3(): void { assert(threw); }); -unitTest(function btoaFailed(): void { +unitTest(function btoaFailed() { const text = "你好"; assertThrows(() => { btoa(text); }, DOMException); }); -unitTest(function textDecoder2(): void { +unitTest(function textDecoder2() { // deno-fmt-ignore const fixture = new Uint8Array([ 0xf0, 0x9d, 0x93, 0xbd, @@ -86,13 +86,13 @@ unitTest(function textDecoder2(): void { // ignoreBOM is tested through WPT -unitTest(function textDecoderASCII(): void { +unitTest(function textDecoderASCII() { const fixture = new Uint8Array([0x89, 0x95, 0x9f, 0xbf]); const decoder = new TextDecoder("ascii"); assertEquals(decoder.decode(fixture), "‰•Ÿ¿"); }); -unitTest(function textDecoderErrorEncoding(): void { +unitTest(function textDecoderErrorEncoding() { let didThrow = false; try { new TextDecoder("Foo"); @@ -103,7 +103,7 @@ unitTest(function textDecoderErrorEncoding(): void { assert(didThrow); }); -unitTest(function textEncoder(): void { +unitTest(function textEncoder() { const fixture = "𝓽𝓮𝔁𝓽"; const encoder = new TextEncoder(); // deno-fmt-ignore @@ -115,7 +115,7 @@ unitTest(function textEncoder(): void { ]); }); -unitTest(function textEncodeInto(): void { +unitTest(function textEncodeInto() { const fixture = "text"; const encoder = new TextEncoder(); const bytes = new Uint8Array(5); @@ -128,7 +128,7 @@ unitTest(function textEncodeInto(): void { ]); }); -unitTest(function textEncodeInto2(): void { +unitTest(function textEncodeInto2() { const fixture = "𝓽𝓮𝔁𝓽"; const encoder = new TextEncoder(); const bytes = new Uint8Array(17); @@ -144,7 +144,7 @@ unitTest(function textEncodeInto2(): void { ]); }); -unitTest(function textEncodeInto3(): void { +unitTest(function textEncodeInto3() { const fixture = "𝓽𝓮𝔁𝓽"; const encoder = new TextEncoder(); const bytes = new Uint8Array(5); @@ -157,7 +157,7 @@ unitTest(function textEncodeInto3(): void { ]); }); -unitTest(function loneSurrogateEncodeInto(): void { +unitTest(function loneSurrogateEncodeInto() { const fixture = "lone𝄞\ud888surrogate"; const encoder = new TextEncoder(); const bytes = new Uint8Array(20); @@ -174,7 +174,7 @@ unitTest(function loneSurrogateEncodeInto(): void { ]); }); -unitTest(function loneSurrogateEncodeInto2(): void { +unitTest(function loneSurrogateEncodeInto2() { const fixture = "\ud800"; const encoder = new TextEncoder(); const bytes = new Uint8Array(3); @@ -187,7 +187,7 @@ unitTest(function loneSurrogateEncodeInto2(): void { ]); }); -unitTest(function loneSurrogateEncodeInto3(): void { +unitTest(function loneSurrogateEncodeInto3() { const fixture = "\udc00"; const encoder = new TextEncoder(); const bytes = new Uint8Array(3); @@ -200,7 +200,7 @@ unitTest(function loneSurrogateEncodeInto3(): void { ]); }); -unitTest(function swappedSurrogatePairEncodeInto4(): void { +unitTest(function swappedSurrogatePairEncodeInto4() { const fixture = "\udc00\ud800"; const encoder = new TextEncoder(); const bytes = new Uint8Array(8); @@ -213,7 +213,7 @@ unitTest(function swappedSurrogatePairEncodeInto4(): void { ]); }); -unitTest(function textDecoderSharedUint8Array(): void { +unitTest(function textDecoderSharedUint8Array() { const ab = new SharedArrayBuffer(6); const dataView = new DataView(ab); const charCodeA = "A".charCodeAt(0); @@ -226,7 +226,7 @@ unitTest(function textDecoderSharedUint8Array(): void { assertEquals(actual, "ABCDEF"); }); -unitTest(function textDecoderSharedInt32Array(): void { +unitTest(function textDecoderSharedInt32Array() { const ab = new SharedArrayBuffer(8); const dataView = new DataView(ab); const charCodeA = "A".charCodeAt(0); @@ -239,14 +239,14 @@ unitTest(function textDecoderSharedInt32Array(): void { assertEquals(actual, "ABCDEFGH"); }); -unitTest(function toStringShouldBeWebCompatibility(): void { +unitTest(function toStringShouldBeWebCompatibility() { const encoder = new TextEncoder(); assertEquals(encoder.toString(), "[object TextEncoder]"); const decoder = new TextDecoder(); assertEquals(decoder.toString(), "[object TextDecoder]"); }); -unitTest(function textEncoderShouldCoerceToString(): void { +unitTest(function textEncoderShouldCoerceToString() { const encoder = new TextEncoder(); const fixutreText = "text"; const fixture = { diff --git a/cli/tests/unit/timers_test.ts b/cli/tests/unit/timers_test.ts index cb5f541d76..4eb470ba9a 100644 --- a/cli/tests/unit/timers_test.ts +++ b/cli/tests/unit/timers_test.ts @@ -9,11 +9,11 @@ import { unitTest, } from "./test_util.ts"; -unitTest(async function functionParameterBindingSuccess(): Promise { +unitTest(async function functionParameterBindingSuccess() { const promise = deferred(); let count = 0; - const nullProto = (newCount: number): void => { + const nullProto = (newCount: number) => { count = newCount; promise.resolve(); }; @@ -26,7 +26,7 @@ unitTest(async function functionParameterBindingSuccess(): Promise { assertEquals(count, 1); }); -unitTest(async function stringifyAndEvalNonFunctions(): Promise { +unitTest(async function stringifyAndEvalNonFunctions() { // eval can only access global scope const global = globalThis as unknown as { globalPromise: ReturnType; @@ -50,10 +50,10 @@ unitTest(async function stringifyAndEvalNonFunctions(): Promise { Reflect.deleteProperty(global, "globalCount"); }); -unitTest(async function timeoutSuccess(): Promise { +unitTest(async function timeoutSuccess() { const promise = deferred(); let count = 0; - setTimeout((): void => { + setTimeout(() => { count++; promise.resolve(); }, 500); @@ -62,7 +62,7 @@ unitTest(async function timeoutSuccess(): Promise { assertEquals(count, 1); }); -unitTest(async function timeoutEvalNoScopeLeak(): Promise { +unitTest(async function timeoutEvalNoScopeLeak() { // eval can only access global scope const global = globalThis as unknown as { globalPromise: Deferred; @@ -83,11 +83,11 @@ unitTest(async function timeoutEvalNoScopeLeak(): Promise { Reflect.deleteProperty(global, "globalPromise"); }); -unitTest(async function timeoutArgs(): Promise { +unitTest(async function timeoutArgs() { const promise = deferred(); const arg = 1; setTimeout( - (a, b, c): void => { + (a, b, c) => { assertEquals(a, arg); assertEquals(b, arg.toString()); assertEquals(c, [arg]); @@ -101,9 +101,9 @@ unitTest(async function timeoutArgs(): Promise { await promise; }); -unitTest(async function timeoutCancelSuccess(): Promise { +unitTest(async function timeoutCancelSuccess() { let count = 0; - const id = setTimeout((): void => { + const id = setTimeout(() => { count++; }, 1); // Cancelled, count should not increment @@ -112,7 +112,7 @@ unitTest(async function timeoutCancelSuccess(): Promise { assertEquals(count, 0); }); -unitTest(async function timeoutCancelMultiple(): Promise { +unitTest(async function timeoutCancelMultiple() { function uncalled(): never { throw new Error("This function should not be called."); } @@ -137,11 +137,11 @@ unitTest(async function timeoutCancelMultiple(): Promise { await delay(50); }); -unitTest(async function timeoutCancelInvalidSilentFail(): Promise { +unitTest(async function timeoutCancelInvalidSilentFail() { // Expect no panic const promise = deferred(); let count = 0; - const id = setTimeout((): void => { + const id = setTimeout(() => { count++; // Should have no effect clearTimeout(id); @@ -154,10 +154,10 @@ unitTest(async function timeoutCancelInvalidSilentFail(): Promise { clearTimeout(2147483647); }); -unitTest(async function intervalSuccess(): Promise { +unitTest(async function intervalSuccess() { const promise = deferred(); let count = 0; - const id = setInterval((): void => { + const id = setInterval(() => { count++; clearInterval(id); promise.resolve(); @@ -172,9 +172,9 @@ unitTest(async function intervalSuccess(): Promise { await delay(0); }); -unitTest(async function intervalCancelSuccess(): Promise { +unitTest(async function intervalCancelSuccess() { let count = 0; - const id = setInterval((): void => { + const id = setInterval(() => { count++; }, 1); clearInterval(id); @@ -182,10 +182,10 @@ unitTest(async function intervalCancelSuccess(): Promise { assertEquals(count, 0); }); -unitTest(async function intervalOrdering(): Promise { +unitTest(async function intervalOrdering() { const timers: number[] = []; let timeouts = 0; - function onTimeout(): void { + function onTimeout() { ++timeouts; for (let i = 1; i < timers.length; i++) { clearTimeout(timers[i]); @@ -198,26 +198,24 @@ unitTest(async function intervalOrdering(): Promise { assertEquals(timeouts, 1); }); -unitTest(function intervalCancelInvalidSilentFail(): void { +unitTest(function intervalCancelInvalidSilentFail() { // Should silently fail (no panic) clearInterval(2147483647); }); -unitTest(async function fireCallbackImmediatelyWhenDelayOverMaxValue(): Promise< - void -> { +unitTest(async function fireCallbackImmediatelyWhenDelayOverMaxValue() { let count = 0; - setTimeout((): void => { + setTimeout(() => { count++; }, 2 ** 31); await delay(1); assertEquals(count, 1); }); -unitTest(async function timeoutCallbackThis(): Promise { +unitTest(async function timeoutCallbackThis() { const promise = deferred(); const obj = { - foo(): void { + foo() { assertEquals(this, window); promise.resolve(); }, @@ -226,7 +224,7 @@ unitTest(async function timeoutCallbackThis(): Promise { await promise; }); -unitTest(async function timeoutBindThis(): Promise { +unitTest(async function timeoutBindThis() { const thisCheckPassed = [null, undefined, window, globalThis]; const thisCheckFailed = [ @@ -237,7 +235,7 @@ unitTest(async function timeoutBindThis(): Promise { {}, [], "foo", - (): void => {}, + () => {}, Object.prototype, ]; @@ -274,7 +272,7 @@ unitTest(async function timeoutBindThis(): Promise { } }); -unitTest(function clearTimeoutShouldConvertToNumber(): void { +unitTest(function clearTimeoutShouldConvertToNumber() { let called = false; const obj = { valueOf(): number { @@ -286,10 +284,10 @@ unitTest(function clearTimeoutShouldConvertToNumber(): void { assert(called); }); -unitTest(function setTimeoutShouldThrowWithBigint(): void { +unitTest(function setTimeoutShouldThrowWithBigint() { let hasThrown = 0; try { - setTimeout((): void => {}, (1n as unknown) as number); + setTimeout(() => {}, (1n as unknown) as number); hasThrown = 1; } catch (err) { if (err instanceof TypeError) { @@ -301,7 +299,7 @@ unitTest(function setTimeoutShouldThrowWithBigint(): void { assertEquals(hasThrown, 2); }); -unitTest(function clearTimeoutShouldThrowWithBigint(): void { +unitTest(function clearTimeoutShouldThrowWithBigint() { let hasThrown = 0; try { clearTimeout((1n as unknown) as number); @@ -316,23 +314,23 @@ unitTest(function clearTimeoutShouldThrowWithBigint(): void { assertEquals(hasThrown, 2); }); -unitTest(function testFunctionName(): void { +unitTest(function testFunctionName() { assertEquals(clearTimeout.name, "clearTimeout"); assertEquals(clearInterval.name, "clearInterval"); }); -unitTest(function testFunctionParamsLength(): void { +unitTest(function testFunctionParamsLength() { assertEquals(setTimeout.length, 1); assertEquals(setInterval.length, 1); assertEquals(clearTimeout.length, 0); assertEquals(clearInterval.length, 0); }); -unitTest(function clearTimeoutAndClearIntervalNotBeEquals(): void { +unitTest(function clearTimeoutAndClearIntervalNotBeEquals() { assertNotEquals(clearTimeout, clearInterval); }); -unitTest(async function timerMaxCpuBug(): Promise { +unitTest(async function timerMaxCpuBug() { // There was a bug where clearing a timeout would cause Deno to use 100% CPU. clearTimeout(setTimeout(() => {}, 1000)); // We can check this by counting how many ops have triggered in the interim. @@ -343,7 +341,7 @@ unitTest(async function timerMaxCpuBug(): Promise { assert(opsDispatched_ - opsDispatched < 10); }); -unitTest(async function timerBasicMicrotaskOrdering(): Promise { +unitTest(async function timerBasicMicrotaskOrdering() { let s = ""; let count = 0; const promise = deferred(); @@ -367,7 +365,7 @@ unitTest(async function timerBasicMicrotaskOrdering(): Promise { assertEquals(s, "deno"); }); -unitTest(async function timerNestedMicrotaskOrdering(): Promise { +unitTest(async function timerNestedMicrotaskOrdering() { let s = ""; const promise = deferred(); s += "0"; @@ -407,7 +405,7 @@ unitTest(function testQueueMicrotask() { assertEquals(typeof queueMicrotask, "function"); }); -unitTest(async function timerIgnoresDateOverride(): Promise { +unitTest(async function timerIgnoresDateOverride() { const OriginalDate = Date; const promise = deferred(); let hasThrown = 0; @@ -416,7 +414,7 @@ unitTest(async function timerIgnoresDateOverride(): Promise { promise.reject("global Date override used over original Date object"); return 0; }; - const DateOverride = (): void => { + const DateOverride = () => { overrideCalled(); }; globalThis.Date = DateOverride as DateConstructor; @@ -441,7 +439,7 @@ unitTest(async function timerIgnoresDateOverride(): Promise { assertEquals(hasThrown, 1); }); -unitTest({ perms: { hrtime: true } }, function sleepSync(): void { +unitTest({ perms: { hrtime: true } }, function sleepSync() { const start = performance.now(); Deno.sleepSync(10); const after = performance.now(); @@ -450,7 +448,7 @@ unitTest({ perms: { hrtime: true } }, function sleepSync(): void { unitTest( { perms: { hrtime: true } }, - async function sleepSyncShorterPromise(): Promise { + async function sleepSyncShorterPromise() { const perf = performance; const short = 5; const long = 10; @@ -469,7 +467,7 @@ unitTest( unitTest( { perms: { hrtime: true } }, - async function sleepSyncLongerPromise(): Promise { + async function sleepSyncLongerPromise() { const perf = performance; const short = 5; const long = 10; diff --git a/cli/tests/unit/tls_test.ts b/cli/tests/unit/tls_test.ts index cedcf467de..46a27b7f08 100644 --- a/cli/tests/unit/tls_test.ts +++ b/cli/tests/unit/tls_test.ts @@ -16,7 +16,7 @@ import { TextProtoReader } from "../../../test_util/std/textproto/mod.ts"; const encoder = new TextEncoder(); const decoder = new TextDecoder(); -async function sleep(msec: number): Promise { +async function sleep(msec: number) { await new Promise((res, _rej) => setTimeout(res, msec)); } @@ -24,7 +24,7 @@ function unreachable(): never { throw new Error("Unreachable code reached"); } -unitTest(async function connectTLSNoPerm(): Promise { +unitTest(async function connectTLSNoPerm() { await assertThrowsAsync(async () => { await Deno.connectTls({ hostname: "github.com", port: 443 }); }, Deno.errors.PermissionDenied); @@ -32,7 +32,7 @@ unitTest(async function connectTLSNoPerm(): Promise { unitTest( { perms: { read: true, net: true } }, - async function connectTLSInvalidHost(): Promise { + async function connectTLSInvalidHost() { const listener = await Deno.listenTls({ hostname: "localhost", port: 3567, @@ -48,7 +48,7 @@ unitTest( }, ); -unitTest(async function connectTLSCertFileNoReadPerm(): Promise { +unitTest(async function connectTLSCertFileNoReadPerm() { await assertThrowsAsync(async () => { await Deno.connectTls({ hostname: "github.com", @@ -60,7 +60,7 @@ unitTest(async function connectTLSCertFileNoReadPerm(): Promise { unitTest( { perms: { read: true, net: true } }, - function listenTLSNonExistentCertKeyFiles(): void { + function listenTLSNonExistentCertKeyFiles() { const options = { hostname: "localhost", port: 3500, @@ -84,7 +84,7 @@ unitTest( }, ); -unitTest({ perms: { net: true } }, function listenTLSNoReadPerm(): void { +unitTest({ perms: { net: true } }, function listenTLSNoReadPerm() { assertThrows(() => { Deno.listenTls({ hostname: "localhost", @@ -99,7 +99,7 @@ unitTest( { perms: { read: true, write: true, net: true }, }, - function listenTLSEmptyKeyFile(): void { + function listenTLSEmptyKeyFile() { const options = { hostname: "localhost", port: 3500, @@ -124,7 +124,7 @@ unitTest( unitTest( { perms: { read: true, write: true, net: true } }, - function listenTLSEmptyCertFile(): void { + function listenTLSEmptyCertFile() { const options = { hostname: "localhost", port: 3500, @@ -149,7 +149,7 @@ unitTest( unitTest( { perms: { read: true, net: true } }, - async function dialAndListenTLS(): Promise { + async function dialAndListenTLS() { const resolvable = deferred(); const hostname = "localhost"; const port = 3500; @@ -166,7 +166,7 @@ unitTest( ); listener.accept().then( - async (conn): Promise => { + async (conn) => { assert(conn.remoteAddr != null); assert(conn.localAddr != null); await conn.write(response); @@ -242,7 +242,7 @@ async function sendThenCloseWriteThenReceive( conn: Deno.Conn, chunkCount: number, chunkSize: number, -): Promise { +) { const byteCount = chunkCount * chunkSize; const buf = new Uint8Array(chunkSize); // Note: buf is size of _chunk_. let n: number; @@ -274,7 +274,7 @@ async function receiveThenSend( conn: Deno.Conn, chunkCount: number, chunkSize: number, -): Promise { +) { const byteCount = chunkCount * chunkSize; const buf = new Uint8Array(byteCount); // Note: buf size equals `byteCount`. let n: number; @@ -301,7 +301,7 @@ async function receiveThenSend( unitTest( { perms: { read: true, net: true } }, - async function tlsServerStreamHalfCloseSendOneByte(): Promise { + async function tlsServerStreamHalfCloseSendOneByte() { const [serverConn, clientConn] = await tlsPair(); await Promise.all([ sendThenCloseWriteThenReceive(serverConn, 1, 1), @@ -312,7 +312,7 @@ unitTest( unitTest( { perms: { read: true, net: true } }, - async function tlsClientStreamHalfCloseSendOneByte(): Promise { + async function tlsClientStreamHalfCloseSendOneByte() { const [serverConn, clientConn] = await tlsPair(); await Promise.all([ sendThenCloseWriteThenReceive(clientConn, 1, 1), @@ -323,7 +323,7 @@ unitTest( unitTest( { perms: { read: true, net: true } }, - async function tlsServerStreamHalfCloseSendOneChunk(): Promise { + async function tlsServerStreamHalfCloseSendOneChunk() { const [serverConn, clientConn] = await tlsPair(); await Promise.all([ sendThenCloseWriteThenReceive(serverConn, 1, 1 << 20 /* 1 MB */), @@ -334,7 +334,7 @@ unitTest( unitTest( { perms: { read: true, net: true } }, - async function tlsClientStreamHalfCloseSendOneChunk(): Promise { + async function tlsClientStreamHalfCloseSendOneChunk() { const [serverConn, clientConn] = await tlsPair(); await Promise.all([ sendThenCloseWriteThenReceive(clientConn, 1, 1 << 20 /* 1 MB */), @@ -345,7 +345,7 @@ unitTest( unitTest( { perms: { read: true, net: true } }, - async function tlsServerStreamHalfCloseSendManyBytes(): Promise { + async function tlsServerStreamHalfCloseSendManyBytes() { const [serverConn, clientConn] = await tlsPair(); await Promise.all([ sendThenCloseWriteThenReceive(serverConn, 100, 1), @@ -356,7 +356,7 @@ unitTest( unitTest( { perms: { read: true, net: true } }, - async function tlsClientStreamHalfCloseSendManyBytes(): Promise { + async function tlsClientStreamHalfCloseSendManyBytes() { const [serverConn, clientConn] = await tlsPair(); await Promise.all([ sendThenCloseWriteThenReceive(clientConn, 100, 1), @@ -367,7 +367,7 @@ unitTest( unitTest( { perms: { read: true, net: true } }, - async function tlsServerStreamHalfCloseSendManyChunks(): Promise { + async function tlsServerStreamHalfCloseSendManyChunks() { const [serverConn, clientConn] = await tlsPair(); await Promise.all([ sendThenCloseWriteThenReceive(serverConn, 100, 1 << 16 /* 64 kB */), @@ -378,7 +378,7 @@ unitTest( unitTest( { perms: { read: true, net: true } }, - async function tlsClientStreamHalfCloseSendManyChunks(): Promise { + async function tlsClientStreamHalfCloseSendManyChunks() { const [serverConn, clientConn] = await tlsPair(); await Promise.all([ sendThenCloseWriteThenReceive(clientConn, 100, 1 << 16 /* 64 kB */), @@ -387,7 +387,7 @@ unitTest( }, ); -async function sendAlotReceiveNothing(conn: Deno.Conn): Promise { +async function sendAlotReceiveNothing(conn: Deno.Conn) { // Start receive op. const readBuf = new Uint8Array(1024); const readPromise = conn.read(readBuf); @@ -410,7 +410,7 @@ async function sendAlotReceiveNothing(conn: Deno.Conn): Promise { ); } -async function receiveAlotSendNothing(conn: Deno.Conn): Promise { +async function receiveAlotSendNothing(conn: Deno.Conn) { const readBuf = new Uint8Array(1024); let n: number | null; @@ -428,7 +428,7 @@ async function receiveAlotSendNothing(conn: Deno.Conn): Promise { unitTest( { perms: { read: true, net: true } }, - async function tlsServerStreamCancelRead(): Promise { + async function tlsServerStreamCancelRead() { const [serverConn, clientConn] = await tlsPair(); await Promise.all([ sendAlotReceiveNothing(serverConn), @@ -439,7 +439,7 @@ unitTest( unitTest( { perms: { read: true, net: true } }, - async function tlsClientStreamCancelRead(): Promise { + async function tlsClientStreamCancelRead() { const [serverConn, clientConn] = await tlsPair(); await Promise.all([ sendAlotReceiveNothing(clientConn), @@ -448,7 +448,7 @@ unitTest( }, ); -async function sendReceiveEmptyBuf(conn: Deno.Conn): Promise { +async function sendReceiveEmptyBuf(conn: Deno.Conn) { const byteBuf = new Uint8Array([1]); const emptyBuf = new Uint8Array(0); let n: number | null; @@ -485,7 +485,7 @@ async function sendReceiveEmptyBuf(conn: Deno.Conn): Promise { unitTest( { perms: { read: true, net: true } }, - async function tlsStreamSendReceiveEmptyBuf(): Promise { + async function tlsStreamSendReceiveEmptyBuf() { const [serverConn, clientConn] = await tlsPair(); await Promise.all([ sendReceiveEmptyBuf(serverConn), @@ -494,12 +494,12 @@ unitTest( }, ); -function immediateClose(conn: Deno.Conn): Promise { +function immediateClose(conn: Deno.Conn) { conn.close(); return Promise.resolve(); } -async function closeWriteAndClose(conn: Deno.Conn): Promise { +async function closeWriteAndClose(conn: Deno.Conn) { await conn.closeWrite(); if (await conn.read(new Uint8Array(1)) !== null) { @@ -511,7 +511,7 @@ async function closeWriteAndClose(conn: Deno.Conn): Promise { unitTest( { perms: { read: true, net: true } }, - async function tlsServerStreamImmediateClose(): Promise { + async function tlsServerStreamImmediateClose() { const [serverConn, clientConn] = await tlsPair(); await Promise.all([ immediateClose(serverConn), @@ -522,7 +522,7 @@ unitTest( unitTest( { perms: { read: true, net: true } }, - async function tlsClientStreamImmediateClose(): Promise { + async function tlsClientStreamImmediateClose() { const [serverConn, clientConn] = await tlsPair(); await Promise.all([ closeWriteAndClose(serverConn), @@ -533,7 +533,7 @@ unitTest( unitTest( { perms: { read: true, net: true } }, - async function tlsClientAndServerStreamImmediateClose(): Promise { + async function tlsClientAndServerStreamImmediateClose() { const [serverConn, clientConn] = await tlsPair(); await Promise.all([ immediateClose(serverConn), @@ -547,7 +547,7 @@ async function tlsWithTcpFailureTestImpl( cipherByteCount: number, failureMode: "corruption" | "shutdown", reverse: boolean, -): Promise { +) { const tlsPort = getPort(); const tlsListener = Deno.listenTls({ hostname: "localhost", @@ -723,7 +723,7 @@ async function tlsWithTcpFailureTestImpl( conn: Deno.Conn, byte: number, count: number, - ): Promise { + ) { let buf = new Uint8Array(1 << 12 /* 4 kB */); buf.fill(byte); @@ -739,7 +739,7 @@ async function tlsWithTcpFailureTestImpl( conn: Deno.Conn, byte: number, count: number, - ): Promise { + ) { let buf = new Uint8Array(1 << 12 /* 4 kB */); while (count > 0) { buf = buf.subarray(0, Math.min(buf.length, count)); @@ -761,7 +761,7 @@ async function tlsWithTcpFailureTestImpl( sink: Deno.Conn, count: number, interruptPromise: Deferred, - ): Promise { + ) { let buf = new Uint8Array(1 << 12 /* 4 kB */); while (count > 0) { buf = buf.subarray(0, Math.min(buf.length, count)); @@ -913,7 +913,7 @@ async function curl(url: string): Promise { unitTest( { perms: { read: true, net: true, run: true } }, - async function curlFakeHttpsServer(): Promise { + async function curlFakeHttpsServer() { const port = getPort(); const listener = createHttpsListener(port); @@ -937,7 +937,7 @@ unitTest( unitTest( { perms: { read: true, net: true } }, - async function startTls(): Promise { + async function startTls() { const hostname = "smtp.gmail.com"; const port = 587; const encoder = new TextEncoder(); diff --git a/cli/tests/unit/truncate_test.ts b/cli/tests/unit/truncate_test.ts index 19cb9328a4..14309d0c16 100644 --- a/cli/tests/unit/truncate_test.ts +++ b/cli/tests/unit/truncate_test.ts @@ -8,7 +8,7 @@ import { unitTest( { perms: { read: true, write: true } }, - function ftruncateSyncSuccess(): void { + function ftruncateSyncSuccess() { const filename = Deno.makeTempDirSync() + "/test_ftruncateSync.txt"; const file = Deno.openSync(filename, { create: true, @@ -30,7 +30,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function ftruncateSuccess(): Promise { + async function ftruncateSuccess() { const filename = Deno.makeTempDirSync() + "/test_ftruncate.txt"; const file = await Deno.open(filename, { create: true, @@ -52,7 +52,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - function truncateSyncSuccess(): void { + function truncateSyncSuccess() { const filename = Deno.makeTempDirSync() + "/test_truncateSync.txt"; Deno.writeFileSync(filename, new Uint8Array(5)); Deno.truncateSync(filename, 20); @@ -67,7 +67,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function truncateSuccess(): Promise { + async function truncateSuccess() { const filename = Deno.makeTempDirSync() + "/test_truncate.txt"; await Deno.writeFile(filename, new Uint8Array(5)); await Deno.truncate(filename, 20); @@ -80,15 +80,13 @@ unitTest( }, ); -unitTest({ perms: { write: false } }, function truncateSyncPerm(): void { +unitTest({ perms: { write: false } }, function truncateSyncPerm() { assertThrows(() => { Deno.truncateSync("/test_truncateSyncPermission.txt"); }, Deno.errors.PermissionDenied); }); -unitTest({ perms: { write: false } }, async function truncatePerm(): Promise< - void -> { +unitTest({ perms: { write: false } }, async function truncatePerm() { await assertThrowsAsync(async () => { await Deno.truncate("/test_truncatePermission.txt"); }, Deno.errors.PermissionDenied); diff --git a/cli/tests/unit/tty_test.ts b/cli/tests/unit/tty_test.ts index 8f9b953729..a9f1105f64 100644 --- a/cli/tests/unit/tty_test.ts +++ b/cli/tests/unit/tty_test.ts @@ -3,7 +3,7 @@ import { assert, assertThrows, unitTest } from "./test_util.ts"; // Note tests for Deno.setRaw is in integration tests. -unitTest({ perms: { read: true } }, function consoleSizeFile(): void { +unitTest({ perms: { read: true } }, function consoleSizeFile() { const file = Deno.openSync("cli/tests/hello.txt"); assertThrows(() => { Deno.consoleSize(file.rid); @@ -11,21 +11,21 @@ unitTest({ perms: { read: true } }, function consoleSizeFile(): void { file.close(); }); -unitTest(function consoleSizeError(): void { +unitTest(function consoleSizeError() { assertThrows(() => { // Absurdly large rid. Deno.consoleSize(0x7fffffff); }, Deno.errors.BadResource); }); -unitTest({ perms: { read: true } }, function isatty(): void { +unitTest({ perms: { read: true } }, function isatty() { // CI not under TTY, so cannot test stdin/stdout/stderr. const f = Deno.openSync("cli/tests/hello.txt"); assert(!Deno.isatty(f.rid)); f.close(); }); -unitTest(function isattyError(): void { +unitTest(function isattyError() { let caught = false; try { // Absurdly large rid. diff --git a/cli/tests/unit/umask_test.ts b/cli/tests/unit/umask_test.ts index aa10b15eb8..579208ee0d 100644 --- a/cli/tests/unit/umask_test.ts +++ b/cli/tests/unit/umask_test.ts @@ -5,7 +5,7 @@ unitTest( { ignore: Deno.build.os === "windows", }, - function umaskSuccess(): void { + function umaskSuccess() { const prevMask = Deno.umask(0o020); const newMask = Deno.umask(prevMask); const finalMask = Deno.umask(); diff --git a/cli/tests/unit/url_search_params_test.ts b/cli/tests/unit/url_search_params_test.ts index c4df86a7f1..0d6e1f2362 100644 --- a/cli/tests/unit/url_search_params_test.ts +++ b/cli/tests/unit/url_search_params_test.ts @@ -1,13 +1,13 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. import { assert, assertEquals, unitTest } from "./test_util.ts"; -unitTest(function urlSearchParamsWithMultipleSpaces(): void { +unitTest(function urlSearchParamsWithMultipleSpaces() { const init = { str: "this string has spaces in it" }; const searchParams = new URLSearchParams(init).toString(); assertEquals(searchParams, "str=this+string+has+spaces+in+it"); }); -unitTest(function urlSearchParamsWithExclamation(): void { +unitTest(function urlSearchParamsWithExclamation() { const init = [ ["str", "hello, world!"], ]; @@ -15,7 +15,7 @@ unitTest(function urlSearchParamsWithExclamation(): void { assertEquals(searchParams, "str=hello%2C+world%21"); }); -unitTest(function urlSearchParamsWithQuotes(): void { +unitTest(function urlSearchParamsWithQuotes() { const init = [ ["str", "'hello world'"], ]; @@ -23,7 +23,7 @@ unitTest(function urlSearchParamsWithQuotes(): void { assertEquals(searchParams, "str=%27hello+world%27"); }); -unitTest(function urlSearchParamsWithBraket(): void { +unitTest(function urlSearchParamsWithBraket() { const init = [ ["str", "(hello world)"], ]; @@ -31,7 +31,7 @@ unitTest(function urlSearchParamsWithBraket(): void { assertEquals(searchParams, "str=%28hello+world%29"); }); -unitTest(function urlSearchParamsWithTilde(): void { +unitTest(function urlSearchParamsWithTilde() { const init = [ ["str", "hello~world"], ]; @@ -39,7 +39,7 @@ unitTest(function urlSearchParamsWithTilde(): void { assertEquals(searchParams, "str=hello%7Eworld"); }); -unitTest(function urlSearchParamsInitString(): void { +unitTest(function urlSearchParamsInitString() { const init = "c=4&a=2&b=3&%C3%A1=1"; const searchParams = new URLSearchParams(init); assert( @@ -48,7 +48,7 @@ unitTest(function urlSearchParamsInitString(): void { ); }); -unitTest(function urlSearchParamsInitStringWithPlusCharacter(): void { +unitTest(function urlSearchParamsInitStringWithPlusCharacter() { let params = new URLSearchParams("q=a+b"); assertEquals(params.toString(), "q=a+b"); assertEquals(params.get("q"), "a b"); @@ -58,7 +58,7 @@ unitTest(function urlSearchParamsInitStringWithPlusCharacter(): void { assertEquals(params.get("q"), "a b c"); }); -unitTest(function urlSearchParamsInitStringWithMalformedParams(): void { +unitTest(function urlSearchParamsInitStringWithMalformedParams() { // These test cases are copied from Web Platform Tests // https://github.com/web-platform-tests/wpt/blob/54c6d64/url/urlsearchparams-constructor.any.js#L60-L80 let params = new URLSearchParams("id=0&value=%"); @@ -84,7 +84,7 @@ unitTest(function urlSearchParamsInitStringWithMalformedParams(): void { assertEquals(params.get("b"), "%*"); }); -unitTest(function urlSearchParamsInitIterable(): void { +unitTest(function urlSearchParamsInitIterable() { const init = [ ["a", "54"], ["b", "true"], @@ -93,13 +93,13 @@ unitTest(function urlSearchParamsInitIterable(): void { assertEquals(searchParams.toString(), "a=54&b=true"); }); -unitTest(function urlSearchParamsInitRecord(): void { +unitTest(function urlSearchParamsInitRecord() { const init = { a: "54", b: "true" }; const searchParams = new URLSearchParams(init); assertEquals(searchParams.toString(), "a=54&b=true"); }); -unitTest(function urlSearchParamsInit(): void { +unitTest(function urlSearchParamsInit() { const params1 = new URLSearchParams("a=b"); assertEquals(params1.toString(), "a=b"); // deno-lint-ignore no-explicit-any @@ -107,20 +107,20 @@ unitTest(function urlSearchParamsInit(): void { assertEquals(params2.toString(), "a=b"); }); -unitTest(function urlSearchParamsAppendSuccess(): void { +unitTest(function urlSearchParamsAppendSuccess() { const searchParams = new URLSearchParams(); searchParams.append("a", "true"); assertEquals(searchParams.toString(), "a=true"); }); -unitTest(function urlSearchParamsDeleteSuccess(): void { +unitTest(function urlSearchParamsDeleteSuccess() { const init = "a=54&b=true"; const searchParams = new URLSearchParams(init); searchParams.delete("b"); assertEquals(searchParams.toString(), "a=54"); }); -unitTest(function urlSearchParamsGetAllSuccess(): void { +unitTest(function urlSearchParamsGetAllSuccess() { const init = "a=54&b=true&a=true"; const searchParams = new URLSearchParams(init); assertEquals(searchParams.getAll("a"), ["54", "true"]); @@ -128,7 +128,7 @@ unitTest(function urlSearchParamsGetAllSuccess(): void { assertEquals(searchParams.getAll("c"), []); }); -unitTest(function urlSearchParamsGetSuccess(): void { +unitTest(function urlSearchParamsGetSuccess() { const init = "a=54&b=true&a=true"; const searchParams = new URLSearchParams(init); assertEquals(searchParams.get("a"), "54"); @@ -136,7 +136,7 @@ unitTest(function urlSearchParamsGetSuccess(): void { assertEquals(searchParams.get("c"), null); }); -unitTest(function urlSearchParamsHasSuccess(): void { +unitTest(function urlSearchParamsHasSuccess() { const init = "a=54&b=true&a=true"; const searchParams = new URLSearchParams(init); assert(searchParams.has("a")); @@ -144,35 +144,35 @@ unitTest(function urlSearchParamsHasSuccess(): void { assert(!searchParams.has("c")); }); -unitTest(function urlSearchParamsSetReplaceFirstAndRemoveOthers(): void { +unitTest(function urlSearchParamsSetReplaceFirstAndRemoveOthers() { const init = "a=54&b=true&a=true"; const searchParams = new URLSearchParams(init); searchParams.set("a", "false"); assertEquals(searchParams.toString(), "a=false&b=true"); }); -unitTest(function urlSearchParamsSetAppendNew(): void { +unitTest(function urlSearchParamsSetAppendNew() { const init = "a=54&b=true&a=true"; const searchParams = new URLSearchParams(init); searchParams.set("c", "foo"); assertEquals(searchParams.toString(), "a=54&b=true&a=true&c=foo"); }); -unitTest(function urlSearchParamsSortSuccess(): void { +unitTest(function urlSearchParamsSortSuccess() { const init = "c=4&a=2&b=3&a=1"; const searchParams = new URLSearchParams(init); searchParams.sort(); assertEquals(searchParams.toString(), "a=2&a=1&b=3&c=4"); }); -unitTest(function urlSearchParamsForEachSuccess(): void { +unitTest(function urlSearchParamsForEachSuccess() { const init = [ ["a", "54"], ["b", "true"], ]; const searchParams = new URLSearchParams(init); let callNum = 0; - searchParams.forEach((value, key, parent): void => { + searchParams.forEach((value, key, parent) => { assertEquals(searchParams, parent); assertEquals(value, init[callNum][1]); assertEquals(key, init[callNum][0]); @@ -181,34 +181,34 @@ unitTest(function urlSearchParamsForEachSuccess(): void { assertEquals(callNum, init.length); }); -unitTest(function urlSearchParamsMissingName(): void { +unitTest(function urlSearchParamsMissingName() { const init = "=4"; const searchParams = new URLSearchParams(init); assertEquals(searchParams.get(""), "4"); assertEquals(searchParams.toString(), "=4"); }); -unitTest(function urlSearchParamsMissingValue(): void { +unitTest(function urlSearchParamsMissingValue() { const init = "4="; const searchParams = new URLSearchParams(init); assertEquals(searchParams.get("4"), ""); assertEquals(searchParams.toString(), "4="); }); -unitTest(function urlSearchParamsMissingEqualSign(): void { +unitTest(function urlSearchParamsMissingEqualSign() { const init = "4"; const searchParams = new URLSearchParams(init); assertEquals(searchParams.get("4"), ""); assertEquals(searchParams.toString(), "4="); }); -unitTest(function urlSearchParamsMissingPair(): void { +unitTest(function urlSearchParamsMissingPair() { const init = "c=4&&a=54&"; const searchParams = new URLSearchParams(init); assertEquals(searchParams.toString(), "c=4&a=54"); }); -unitTest(function urlSearchParamsForShortEncodedChar(): void { +unitTest(function urlSearchParamsForShortEncodedChar() { const init = { linefeed: "\n", tab: "\t" }; const searchParams = new URLSearchParams(init); assertEquals(searchParams.toString(), "linefeed=%0A&tab=%09"); @@ -216,7 +216,7 @@ unitTest(function urlSearchParamsForShortEncodedChar(): void { // If pair does not contain exactly two items, then throw a TypeError. // ref https://url.spec.whatwg.org/#interface-urlsearchparams -unitTest(function urlSearchParamsShouldThrowTypeError(): void { +unitTest(function urlSearchParamsShouldThrowTypeError() { let hasThrown = 0; try { @@ -246,14 +246,14 @@ unitTest(function urlSearchParamsShouldThrowTypeError(): void { assertEquals(hasThrown, 2); }); -unitTest(function urlSearchParamsAppendArgumentsCheck(): void { +unitTest(function urlSearchParamsAppendArgumentsCheck() { const methodRequireOneParam = ["delete", "getAll", "get", "has", "forEach"]; const methodRequireTwoParams = ["append", "set"]; methodRequireOneParam .concat(methodRequireTwoParams) - .forEach((method: string): void => { + .forEach((method: string) => { const searchParams = new URLSearchParams(); let hasThrown = 0; try { @@ -270,7 +270,7 @@ unitTest(function urlSearchParamsAppendArgumentsCheck(): void { assertEquals(hasThrown, 2); }); - methodRequireTwoParams.forEach((method: string): void => { + methodRequireTwoParams.forEach((method: string) => { const searchParams = new URLSearchParams(); let hasThrown = 0; try { @@ -289,7 +289,7 @@ unitTest(function urlSearchParamsAppendArgumentsCheck(): void { }); // ref: https://github.com/web-platform-tests/wpt/blob/master/url/urlsearchparams-delete.any.js -unitTest(function urlSearchParamsDeletingAppendedMultiple(): void { +unitTest(function urlSearchParamsDeletingAppendedMultiple() { const params = new URLSearchParams(); params.append("first", (1 as unknown) as string); assert(params.has("first")); @@ -303,7 +303,7 @@ unitTest(function urlSearchParamsDeletingAppendedMultiple(): void { }); // ref: https://github.com/web-platform-tests/wpt/blob/master/url/urlsearchparams-constructor.any.js#L176-L182 -unitTest(function urlSearchParamsCustomSymbolIterator(): void { +unitTest(function urlSearchParamsCustomSymbolIterator() { const params = new URLSearchParams(); params[Symbol.iterator] = function* (): IterableIterator<[string, string]> { yield ["a", "b"]; @@ -313,7 +313,7 @@ unitTest(function urlSearchParamsCustomSymbolIterator(): void { }); unitTest( - function urlSearchParamsCustomSymbolIteratorWithNonStringParams(): void { + function urlSearchParamsCustomSymbolIteratorWithNonStringParams() { const params = {}; // deno-lint-ignore no-explicit-any (params as any)[Symbol.iterator] = function* (): IterableIterator< @@ -328,10 +328,10 @@ unitTest( // If a class extends URLSearchParams, override one method should not change another's behavior. unitTest( - function urlSearchParamsOverridingAppendNotChangeConstructorAndSet(): void { + function urlSearchParamsOverridingAppendNotChangeConstructorAndSet() { let overridedAppendCalled = 0; class CustomSearchParams extends URLSearchParams { - append(name: string, value: string): void { + append(name: string, value: string) { ++overridedAppendCalled; super.append(name, value); } @@ -344,7 +344,7 @@ unitTest( }, ); -unitTest(function urlSearchParamsOverridingEntriesNotChangeForEach(): void { +unitTest(function urlSearchParamsOverridingEntriesNotChangeForEach() { class CustomSearchParams extends URLSearchParams { *entries(): IterableIterator<[string, string]> { yield* []; diff --git a/cli/tests/unit/url_test.ts b/cli/tests/unit/url_test.ts index 8d280ccb5a..9f32445a94 100644 --- a/cli/tests/unit/url_test.ts +++ b/cli/tests/unit/url_test.ts @@ -7,7 +7,7 @@ import { unitTest, } from "./test_util.ts"; -unitTest(function urlParsing(): void { +unitTest(function urlParsing() { const url = new URL( "https://foo:bar@baz.qat:8000/qux/quux?foo=bar&baz=12#qat", ); @@ -33,7 +33,7 @@ unitTest(function urlParsing(): void { ); }); -unitTest(function urlProtocolParsing(): void { +unitTest(function urlProtocolParsing() { assertEquals(new URL("Aa+-.1://foo").protocol, "aa+-.1:"); assertEquals(new URL("aA+-.1://foo").protocol, "aa+-.1:"); assertThrows(() => new URL("1://foo"), TypeError, "Invalid URL"); @@ -50,7 +50,7 @@ unitTest(function urlProtocolParsing(): void { assertThrows(() => new URL("*://foo"), TypeError, "Invalid URL"); }); -unitTest(function urlAuthenticationParsing(): void { +unitTest(function urlAuthenticationParsing() { const specialUrl = new URL("http://foo:bar@baz"); assertEquals(specialUrl.username, "foo"); assertEquals(specialUrl.password, "bar"); @@ -62,7 +62,7 @@ unitTest(function urlAuthenticationParsing(): void { assertEquals(nonSpecialUrl.hostname, "baz"); }); -unitTest(function urlHostnameParsing(): void { +unitTest(function urlHostnameParsing() { // IPv6. assertEquals(new URL("http://[::1]").hostname, "[::1]"); assertEquals(new URL("file://[::1]").hostname, "[::1]"); @@ -102,7 +102,7 @@ unitTest(function urlHostnameParsing(): void { assertThrows(() => new URL("http://4294967296"), TypeError, "Invalid URL"); }); -unitTest(function urlPortParsing(): void { +unitTest(function urlPortParsing() { const specialUrl = new URL("http://foo:8000"); assertEquals(specialUrl.hostname, "foo"); assertEquals(specialUrl.port, "8000"); @@ -112,7 +112,7 @@ unitTest(function urlPortParsing(): void { assertEquals(nonSpecialUrl.port, "8000"); }); -unitTest(function urlModifications(): void { +unitTest(function urlModifications() { const url = new URL( "https://foo:bar@baz.qat:8000/qux/quux?foo=bar&baz=12#qat", ); @@ -167,7 +167,7 @@ unitTest(function urlModifications(): void { ); }); -unitTest(function urlModifyHref(): void { +unitTest(function urlModifyHref() { const url = new URL("http://example.com/"); url.href = "https://foo:bar@example.com:8080/baz/qat#qux"; assertEquals(url.protocol, "https:"); @@ -179,13 +179,13 @@ unitTest(function urlModifyHref(): void { assertEquals(url.hash, "#qux"); }); -unitTest(function urlNormalize(): void { +unitTest(function urlNormalize() { const url = new URL("http://example.com"); assertEquals(url.pathname, "/"); assertEquals(url.href, "http://example.com/"); }); -unitTest(function urlModifyPathname(): void { +unitTest(function urlModifyPathname() { const url = new URL("http://foo.bar/baz%qat/qux%quux"); assertEquals(url.pathname, "/baz%qat/qux%quux"); // Self-assignment is to invoke the setter. @@ -201,7 +201,7 @@ unitTest(function urlModifyPathname(): void { assertEquals(url.pathname, "/a/b/c"); }); -unitTest(function urlModifyHash(): void { +unitTest(function urlModifyHash() { const url = new URL("http://foo.bar"); url.hash = "%foo bar/qat%qux#bar"; assertEquals(url.hash, "#%foo%20bar/qat%qux#bar"); @@ -210,7 +210,7 @@ unitTest(function urlModifyHash(): void { assertEquals(url.hash, "#%foo%20bar/qat%qux#bar"); }); -unitTest(function urlSearchParamsReuse(): void { +unitTest(function urlSearchParamsReuse() { const url = new URL( "https://foo:bar@baz.qat:8000/qux/quux?foo=bar&baz=12#qat", ); @@ -219,7 +219,7 @@ unitTest(function urlSearchParamsReuse(): void { assert(sp === url.searchParams, "Search params should be reused."); }); -unitTest(function urlBackSlashes(): void { +unitTest(function urlBackSlashes() { const url = new URL( "https:\\\\foo:bar@baz.qat:8000\\qux\\quux?foo=bar&baz=12#qat", ); @@ -229,7 +229,7 @@ unitTest(function urlBackSlashes(): void { ); }); -unitTest(function urlProtocolSlashes(): void { +unitTest(function urlProtocolSlashes() { assertEquals(new URL("http:foo").href, "http://foo/"); assertEquals(new URL("http://foo").href, "http://foo/"); assertEquals(new URL("file:foo").href, "file:///foo"); @@ -238,7 +238,7 @@ unitTest(function urlProtocolSlashes(): void { assertEquals(new URL("abcd://foo").href, "abcd://foo"); }); -unitTest(function urlRequireHost(): void { +unitTest(function urlRequireHost() { assertEquals(new URL("file:///").href, "file:///"); assertThrows(() => new URL("ftp:///"), TypeError, "Invalid URL"); assertThrows(() => new URL("http:///"), TypeError, "Invalid URL"); @@ -320,7 +320,7 @@ unitTest(function urlEncoding() { ); }); -unitTest(function urlBase(): void { +unitTest(function urlBase() { assertEquals(new URL("d", new URL("http://foo/a?b#c")).href, "http://foo/d"); assertEquals(new URL("", "http://foo/a/b?c#d").href, "http://foo/a/b?c"); @@ -377,7 +377,7 @@ unitTest(function urlSameProtocolBase() { assertEquals(new URL("abcd:b", "abcd://foo/a").href, "abcd:b"); }); -unitTest(function deletingAllParamsRemovesQuestionMarkFromURL(): void { +unitTest(function deletingAllParamsRemovesQuestionMarkFromURL() { const url = new URL("http://example.com/?param1¶m2"); url.searchParams.delete("param1"); url.searchParams.delete("param2"); @@ -385,7 +385,7 @@ unitTest(function deletingAllParamsRemovesQuestionMarkFromURL(): void { assertEquals(url.search, ""); }); -unitTest(function removingNonExistentParamRemovesQuestionMarkFromURL(): void { +unitTest(function removingNonExistentParamRemovesQuestionMarkFromURL() { const url = new URL("http://example.com/?"); assertEquals(url.href, "http://example.com/?"); url.searchParams.delete("param1"); @@ -393,7 +393,7 @@ unitTest(function removingNonExistentParamRemovesQuestionMarkFromURL(): void { assertEquals(url.search, ""); }); -unitTest(function sortingNonExistentParamRemovesQuestionMarkFromURL(): void { +unitTest(function sortingNonExistentParamRemovesQuestionMarkFromURL() { const url = new URL("http://example.com/?"); assertEquals(url.href, "http://example.com/?"); url.searchParams.sort(); @@ -401,7 +401,7 @@ unitTest(function sortingNonExistentParamRemovesQuestionMarkFromURL(): void { assertEquals(url.search, ""); }); -unitTest(function customInspectFunction(): void { +unitTest(function customInspectFunction() { const url = new URL("http://example.com/?"); assertEquals( Deno.inspect(url), @@ -428,7 +428,7 @@ unitTest(function protocolNotHttpOrFile() { assertEquals(url.origin, "null"); }); -unitTest(function throwForInvalidPortConstructor(): void { +unitTest(function throwForInvalidPortConstructor() { const urls = [ // If port is greater than 2^16 − 1, validation error, return failure. `https://baz.qat:${2 ** 16}`, @@ -447,7 +447,7 @@ unitTest(function throwForInvalidPortConstructor(): void { new URL("https://baz.qat:0"); }); -unitTest(function doNotOverridePortIfInvalid(): void { +unitTest(function doNotOverridePortIfInvalid() { const initialPort = "3000"; const url = new URL(`https://deno.land:${initialPort}`); // If port is greater than 2^16 − 1, validation error, return failure. @@ -455,7 +455,7 @@ unitTest(function doNotOverridePortIfInvalid(): void { assertEquals(url.port, initialPort); }); -unitTest(function emptyPortForSchemeDefaultPort(): void { +unitTest(function emptyPortForSchemeDefaultPort() { const nonDefaultPort = "3500"; const url = new URL("ftp://baz.qat:21"); diff --git a/cli/tests/unit/utime_test.ts b/cli/tests/unit/utime_test.ts index 32b631406b..f5647d2201 100644 --- a/cli/tests/unit/utime_test.ts +++ b/cli/tests/unit/utime_test.ts @@ -9,7 +9,7 @@ import { unitTest( { perms: { read: true, write: true } }, - async function futimeSyncSuccess(): Promise { + async function futimeSyncSuccess() { const testDir = await Deno.makeTempDir(); const filename = testDir + "/file.txt"; const file = await Deno.open(filename, { @@ -31,7 +31,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - function futimeSyncSuccess(): void { + function futimeSyncSuccess() { const testDir = Deno.makeTempDirSync(); const filename = testDir + "/file.txt"; const file = Deno.openSync(filename, { @@ -53,7 +53,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - function utimeSyncFileSuccess(): void { + function utimeSyncFileSuccess() { const testDir = Deno.makeTempDirSync(); const filename = testDir + "/file.txt"; Deno.writeFileSync(filename, new TextEncoder().encode("hello"), { @@ -72,7 +72,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - function utimeSyncUrlSuccess(): void { + function utimeSyncUrlSuccess() { const testDir = Deno.makeTempDirSync(); const filename = testDir + "/file.txt"; Deno.writeFileSync(filename, new TextEncoder().encode("hello"), { @@ -91,7 +91,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - function utimeSyncDirectorySuccess(): void { + function utimeSyncDirectorySuccess() { const testDir = Deno.makeTempDirSync(); const atime = 1000; @@ -106,7 +106,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - function utimeSyncDateSuccess(): void { + function utimeSyncDateSuccess() { const testDir = Deno.makeTempDirSync(); const atime = new Date(1000_000); @@ -139,7 +139,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - function utimeSyncLargeNumberSuccess(): void { + function utimeSyncLargeNumberSuccess() { const testDir = Deno.makeTempDirSync(); // There are Rust side caps (might be fs relate), @@ -156,7 +156,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - function utimeSyncNotFound(): void { + function utimeSyncNotFound() { const atime = 1000; const mtime = 50000; @@ -168,7 +168,7 @@ unitTest( unitTest( { perms: { read: true, write: false } }, - function utimeSyncPerm(): void { + function utimeSyncPerm() { const atime = 1000; const mtime = 50000; @@ -180,7 +180,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function utimeFileSuccess(): Promise { + async function utimeFileSuccess() { const testDir = Deno.makeTempDirSync(); const filename = testDir + "/file.txt"; Deno.writeFileSync(filename, new TextEncoder().encode("hello"), { @@ -199,7 +199,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function utimeUrlSuccess(): Promise { + async function utimeUrlSuccess() { const testDir = Deno.makeTempDirSync(); const filename = testDir + "/file.txt"; Deno.writeFileSync(filename, new TextEncoder().encode("hello"), { @@ -218,7 +218,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function utimeDirectorySuccess(): Promise { + async function utimeDirectorySuccess() { const testDir = Deno.makeTempDirSync(); const atime = 1000; @@ -233,7 +233,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function utimeDateSuccess(): Promise { + async function utimeDateSuccess() { const testDir = Deno.makeTempDirSync(); const atime = new Date(100_000); @@ -248,7 +248,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function utimeFileDateSuccess(): Promise { + async function utimeFileDateSuccess() { const testDir = Deno.makeTempDirSync(); const filename = testDir + "/file.txt"; Deno.writeFileSync(filename, new TextEncoder().encode("hello"), { @@ -267,7 +267,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function utimeNotFound(): Promise { + async function utimeNotFound() { const atime = 1000; const mtime = 50000; @@ -279,7 +279,7 @@ unitTest( unitTest( { perms: { read: true, write: false } }, - async function utimeSyncPerm(): Promise { + async function utimeSyncPerm() { const atime = 1000; const mtime = 50000; diff --git a/cli/tests/unit/version_test.ts b/cli/tests/unit/version_test.ts index d3a5270c95..e6e95ff076 100644 --- a/cli/tests/unit/version_test.ts +++ b/cli/tests/unit/version_test.ts @@ -1,6 +1,6 @@ import { assert, unitTest } from "./test_util.ts"; -unitTest(function version(): void { +unitTest(function version() { const pattern = /^\d+\.\d+\.\d+/; assert(pattern.test(Deno.version.deno)); assert(pattern.test(Deno.version.v8)); diff --git a/cli/tests/unit/wasm_test.ts b/cli/tests/unit/wasm_test.ts index 27391cbf28..66fcacade1 100644 --- a/cli/tests/unit/wasm_test.ts +++ b/cli/tests/unit/wasm_test.ts @@ -22,7 +22,7 @@ const simpleWasm = new Uint8Array([ 0x00, 0x20, 0x01, 0x6a, 0x0b ]); -unitTest(async function wasmInstantiateWorksWithBuffer(): Promise { +unitTest(async function wasmInstantiateWorksWithBuffer() { const { module, instance } = await WebAssembly.instantiate(simpleWasm); assertEquals(WebAssembly.Module.exports(module), [{ name: "add", @@ -38,7 +38,7 @@ unitTest(async function wasmInstantiateWorksWithBuffer(): Promise { // don't set the WASM streaming callback, is to take a byte source. Here we // check that our implementation of the callback disallows it. unitTest( - async function wasmInstantiateStreamingFailsWithBuffer(): Promise { + async function wasmInstantiateStreamingFailsWithBuffer() { await assertThrowsAsync(async () => { await WebAssembly.instantiateStreaming( // Bypassing the type system @@ -48,7 +48,7 @@ unitTest( }, ); -unitTest(async function wasmInstantiateStreaming(): Promise { +unitTest(async function wasmInstantiateStreaming() { let isomorphic = ""; for (const byte of simpleWasm) { isomorphic += String.fromCharCode(byte); @@ -70,7 +70,7 @@ unitTest(async function wasmInstantiateStreaming(): Promise { unitTest( { perms: { net: true } }, - async function wasmStreamingNonTrivial(): Promise { + async function wasmStreamingNonTrivial() { // deno-dom's WASM file is a real-world non-trivial case that gave us // trouble when implementing this. await WebAssembly.instantiateStreaming(fetch( diff --git a/cli/tests/unit/write_file_test.ts b/cli/tests/unit/write_file_test.ts index e63183c4c3..4c4cecf430 100644 --- a/cli/tests/unit/write_file_test.ts +++ b/cli/tests/unit/write_file_test.ts @@ -8,7 +8,7 @@ import { unitTest( { perms: { read: true, write: true } }, - function writeFileSyncSuccess(): void { + function writeFileSyncSuccess() { const enc = new TextEncoder(); const data = enc.encode("Hello"); const filename = Deno.makeTempDirSync() + "/test.txt"; @@ -22,7 +22,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - function writeFileSyncUrl(): void { + function writeFileSyncUrl() { const enc = new TextEncoder(); const data = enc.encode("Hello"); const tempDir = Deno.makeTempDirSync(); @@ -39,7 +39,7 @@ unitTest( }, ); -unitTest({ perms: { write: true } }, function writeFileSyncFail(): void { +unitTest({ perms: { write: true } }, function writeFileSyncFail() { const enc = new TextEncoder(); const data = enc.encode("Hello"); const filename = "/baddir/test.txt"; @@ -49,7 +49,7 @@ unitTest({ perms: { write: true } }, function writeFileSyncFail(): void { }, Deno.errors.NotFound); }); -unitTest({ perms: { write: false } }, function writeFileSyncPerm(): void { +unitTest({ perms: { write: false } }, function writeFileSyncPerm() { const enc = new TextEncoder(); const data = enc.encode("Hello"); const filename = "/baddir/test.txt"; @@ -61,7 +61,7 @@ unitTest({ perms: { write: false } }, function writeFileSyncPerm(): void { unitTest( { perms: { read: true, write: true } }, - function writeFileSyncUpdateMode(): void { + function writeFileSyncUpdateMode() { if (Deno.build.os !== "windows") { const enc = new TextEncoder(); const data = enc.encode("Hello"); @@ -76,7 +76,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - function writeFileSyncCreate(): void { + function writeFileSyncCreate() { const enc = new TextEncoder(); const data = enc.encode("Hello"); const filename = Deno.makeTempDirSync() + "/test.txt"; @@ -97,7 +97,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - function writeFileSyncAppend(): void { + function writeFileSyncAppend() { const enc = new TextEncoder(); const data = enc.encode("Hello"); const filename = Deno.makeTempDirSync() + "/test.txt"; @@ -122,7 +122,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function writeFileSuccess(): Promise { + async function writeFileSuccess() { const enc = new TextEncoder(); const data = enc.encode("Hello"); const filename = Deno.makeTempDirSync() + "/test.txt"; @@ -136,7 +136,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function writeFileUrl(): Promise { + async function writeFileUrl() { const enc = new TextEncoder(); const data = enc.encode("Hello"); const tempDir = await Deno.makeTempDir(); @@ -155,7 +155,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function writeFileNotFound(): Promise { + async function writeFileNotFound() { const enc = new TextEncoder(); const data = enc.encode("Hello"); const filename = "/baddir/test.txt"; @@ -168,7 +168,7 @@ unitTest( unitTest( { perms: { read: true, write: false } }, - async function writeFilePerm(): Promise { + async function writeFilePerm() { const enc = new TextEncoder(); const data = enc.encode("Hello"); const filename = "/baddir/test.txt"; @@ -181,7 +181,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function writeFileUpdateMode(): Promise { + async function writeFileUpdateMode() { if (Deno.build.os !== "windows") { const enc = new TextEncoder(); const data = enc.encode("Hello"); @@ -196,7 +196,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function writeFileCreate(): Promise { + async function writeFileCreate() { const enc = new TextEncoder(); const data = enc.encode("Hello"); const filename = Deno.makeTempDirSync() + "/test.txt"; @@ -217,7 +217,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function writeFileAppend(): Promise { + async function writeFileAppend() { const enc = new TextEncoder(); const data = enc.encode("Hello"); const filename = Deno.makeTempDirSync() + "/test.txt"; diff --git a/cli/tests/unit/write_text_file_test.ts b/cli/tests/unit/write_text_file_test.ts index f41f8f6633..2d14dc7127 100644 --- a/cli/tests/unit/write_text_file_test.ts +++ b/cli/tests/unit/write_text_file_test.ts @@ -8,7 +8,7 @@ import { unitTest( { perms: { read: true, write: true } }, - function writeTextFileSyncSuccess(): void { + function writeTextFileSyncSuccess() { const filename = Deno.makeTempDirSync() + "/test.txt"; Deno.writeTextFileSync(filename, "Hello"); const dataRead = Deno.readTextFileSync(filename); @@ -18,7 +18,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - function writeTextFileSyncByUrl(): void { + function writeTextFileSyncByUrl() { const tempDir = Deno.makeTempDirSync(); const fileUrl = new URL( `file://${Deno.build.os === "windows" ? "/" : ""}${tempDir}/test.txt`, @@ -31,7 +31,7 @@ unitTest( }, ); -unitTest({ perms: { write: true } }, function writeTextFileSyncFail(): void { +unitTest({ perms: { write: true } }, function writeTextFileSyncFail() { const filename = "/baddir/test.txt"; // The following should fail because /baddir doesn't exist (hopefully). assertThrows(() => { @@ -39,7 +39,7 @@ unitTest({ perms: { write: true } }, function writeTextFileSyncFail(): void { }, Deno.errors.NotFound); }); -unitTest({ perms: { write: false } }, function writeTextFileSyncPerm(): void { +unitTest({ perms: { write: false } }, function writeTextFileSyncPerm() { const filename = "/baddir/test.txt"; // The following should fail due to no write permission assertThrows(() => { @@ -49,7 +49,7 @@ unitTest({ perms: { write: false } }, function writeTextFileSyncPerm(): void { unitTest( { perms: { read: true, write: true } }, - function writeTextFileSyncUpdateMode(): void { + function writeTextFileSyncUpdateMode() { if (Deno.build.os !== "windows") { const data = "Hello"; const filename = Deno.makeTempDirSync() + "/test.txt"; @@ -63,7 +63,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - function writeTextFileSyncCreate(): void { + function writeTextFileSyncCreate() { const data = "Hello"; const filename = Deno.makeTempDirSync() + "/test.txt"; let caughtError = false; @@ -85,7 +85,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - function writeTextFileSyncAppend(): void { + function writeTextFileSyncAppend() { const data = "Hello"; const filename = Deno.makeTempDirSync() + "/test.txt"; Deno.writeTextFileSync(filename, data); @@ -102,7 +102,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function writeTextFileSuccess(): Promise { + async function writeTextFileSuccess() { const filename = Deno.makeTempDirSync() + "/test.txt"; await Deno.writeTextFile(filename, "Hello"); const dataRead = Deno.readTextFileSync(filename); @@ -112,7 +112,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function writeTextFileByUrl(): Promise { + async function writeTextFileByUrl() { const tempDir = Deno.makeTempDirSync(); const fileUrl = new URL( `file://${Deno.build.os === "windows" ? "/" : ""}${tempDir}/test.txt`, @@ -127,7 +127,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function writeTextFileNotFound(): Promise { + async function writeTextFileNotFound() { const filename = "/baddir/test.txt"; // The following should fail because /baddir doesn't exist (hopefully). await assertThrowsAsync(async () => { @@ -138,7 +138,7 @@ unitTest( unitTest( { perms: { write: false } }, - async function writeTextFilePerm(): Promise { + async function writeTextFilePerm() { const filename = "/baddir/test.txt"; // The following should fail due to no write permission await assertThrowsAsync(async () => { @@ -149,7 +149,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function writeTextFileUpdateMode(): Promise { + async function writeTextFileUpdateMode() { if (Deno.build.os !== "windows") { const data = "Hello"; const filename = Deno.makeTempDirSync() + "/test.txt"; @@ -163,7 +163,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function writeTextFileCreate(): Promise { + async function writeTextFileCreate() { const data = "Hello"; const filename = Deno.makeTempDirSync() + "/test.txt"; let caughtError = false; @@ -185,7 +185,7 @@ unitTest( unitTest( { perms: { read: true, write: true } }, - async function writeTextFileAppend(): Promise { + async function writeTextFileAppend() { const data = "Hello"; const filename = Deno.makeTempDirSync() + "/test.txt"; await Deno.writeTextFile(filename, data); diff --git a/cli/tests/websocket_test.ts b/cli/tests/websocket_test.ts index 8a7fc812c2..7d62679fea 100644 --- a/cli/tests/websocket_test.ts +++ b/cli/tests/websocket_test.ts @@ -24,28 +24,28 @@ Deno.test("invalid server", async () => { const promise = deferred(); const ws = new WebSocket("ws://localhost:2121"); let err = false; - ws.onerror = (): void => { + ws.onerror = () => { err = true; }; - ws.onclose = (): void => { + ws.onclose = () => { if (err) { promise.resolve(); } else { fail(); } }; - ws.onopen = (): void => fail(); + ws.onopen = () => fail(); await promise; }); Deno.test("connect & close", async () => { const promise = deferred(); const ws = new WebSocket("ws://localhost:4242"); - ws.onerror = (): void => fail(); - ws.onopen = (): void => { + ws.onerror = () => fail(); + ws.onopen = () => { ws.close(); }; - ws.onclose = (): void => { + ws.onclose = () => { promise.resolve(); }; await promise; @@ -56,26 +56,26 @@ Deno.test("connect & abort", async () => { const ws = new WebSocket("ws://localhost:4242"); ws.close(); let err = false; - ws.onerror = (): void => { + ws.onerror = () => { err = true; }; - ws.onclose = (): void => { + ws.onclose = () => { if (err) { promise.resolve(); } else { fail(); } }; - ws.onopen = (): void => fail(); + ws.onopen = () => fail(); await promise; }); Deno.test("connect & close custom valid code", async () => { const promise = deferred(); const ws = new WebSocket("ws://localhost:4242"); - ws.onerror = (): void => fail(); - ws.onopen = (): void => ws.close(1000); - ws.onclose = (): void => { + ws.onerror = () => fail(); + ws.onopen = () => ws.close(1000); + ws.onclose = () => { promise.resolve(); }; await promise; @@ -84,12 +84,12 @@ Deno.test("connect & close custom valid code", async () => { Deno.test("connect & close custom invalid code", async () => { const promise = deferred(); const ws = new WebSocket("ws://localhost:4242"); - ws.onerror = (): void => fail(); - ws.onopen = (): void => { + ws.onerror = () => fail(); + ws.onopen = () => { assertThrows(() => ws.close(1001)); ws.close(); }; - ws.onclose = (): void => { + ws.onclose = () => { promise.resolve(); }; await promise; @@ -98,9 +98,9 @@ Deno.test("connect & close custom invalid code", async () => { Deno.test("connect & close custom valid reason", async () => { const promise = deferred(); const ws = new WebSocket("ws://localhost:4242"); - ws.onerror = (): void => fail(); - ws.onopen = (): void => ws.close(1000, "foo"); - ws.onclose = (): void => { + ws.onerror = () => fail(); + ws.onopen = () => ws.close(1000, "foo"); + ws.onclose = () => { promise.resolve(); }; await promise; @@ -109,12 +109,12 @@ Deno.test("connect & close custom valid reason", async () => { Deno.test("connect & close custom invalid reason", async () => { const promise = deferred(); const ws = new WebSocket("ws://localhost:4242"); - ws.onerror = (): void => fail(); - ws.onopen = (): void => { + ws.onerror = () => fail(); + ws.onopen = () => { assertThrows(() => ws.close(1000, "".padEnd(124, "o"))); ws.close(); }; - ws.onclose = (): void => { + ws.onclose = () => { promise.resolve(); }; await promise; @@ -123,13 +123,13 @@ Deno.test("connect & close custom invalid reason", async () => { Deno.test("echo string", async () => { const promise = deferred(); const ws = new WebSocket("ws://localhost:4242"); - ws.onerror = (): void => fail(); - ws.onopen = (): void => ws.send("foo"); - ws.onmessage = (e): void => { + ws.onerror = () => fail(); + ws.onopen = () => ws.send("foo"); + ws.onmessage = (e) => { assertEquals(e.data, "foo"); ws.close(); }; - ws.onclose = (): void => { + ws.onclose = () => { promise.resolve(); }; await promise; @@ -139,14 +139,14 @@ Deno.test("echo string tls", async () => { const promise1 = deferred(); const promise2 = deferred(); const ws = new WebSocket("wss://localhost:4243"); - ws.onerror = (): void => fail(); - ws.onopen = (): void => ws.send("foo"); - ws.onmessage = (e): void => { + ws.onerror = () => fail(); + ws.onopen = () => ws.send("foo"); + ws.onmessage = (e) => { assertEquals(e.data, "foo"); ws.close(); promise1.resolve(); }; - ws.onclose = (): void => { + ws.onclose = () => { promise2.resolve(); }; await promise1; @@ -157,7 +157,7 @@ Deno.test("websocket error", async () => { const promise1 = deferred(); const ws = new WebSocket("wss://localhost:4242"); ws.onopen = () => fail(); - ws.onerror = (err): void => { + ws.onerror = (err) => { assert(err instanceof ErrorEvent); // Error message got changed because we don't use warp in test_util @@ -171,9 +171,9 @@ Deno.test("echo blob with binaryType blob", async () => { const promise = deferred(); const ws = new WebSocket("ws://localhost:4242"); const blob = new Blob(["foo"]); - ws.onerror = (): void => fail(); - ws.onopen = (): void => ws.send(blob); - ws.onmessage = (e): void => { + ws.onerror = () => fail(); + ws.onopen = () => ws.send(blob); + ws.onmessage = (e) => { e.data.text().then((actual: string) => { blob.text().then((expected) => { assertEquals(actual, expected); @@ -181,7 +181,7 @@ Deno.test("echo blob with binaryType blob", async () => { }); ws.close(); }; - ws.onclose = (): void => { + ws.onclose = () => { promise.resolve(); }; await promise; @@ -192,15 +192,15 @@ Deno.test("echo blob with binaryType arraybuffer", async () => { const ws = new WebSocket("ws://localhost:4242"); ws.binaryType = "arraybuffer"; const blob = new Blob(["foo"]); - ws.onerror = (): void => fail(); - ws.onopen = (): void => ws.send(blob); - ws.onmessage = (e): void => { + ws.onerror = () => fail(); + ws.onopen = () => ws.send(blob); + ws.onmessage = (e) => { blob.arrayBuffer().then((expected) => { assertEquals(e.data, expected); }); ws.close(); }; - ws.onclose = (): void => { + ws.onclose = () => { promise.resolve(); }; await promise; @@ -210,15 +210,15 @@ Deno.test("echo uint8array with binaryType blob", async () => { const promise = deferred(); const ws = new WebSocket("ws://localhost:4242"); const uint = new Uint8Array([102, 111, 111]); - ws.onerror = (): void => fail(); - ws.onopen = (): void => ws.send(uint); - ws.onmessage = (e): void => { + ws.onerror = () => fail(); + ws.onopen = () => ws.send(uint); + ws.onmessage = (e) => { e.data.arrayBuffer().then((actual: ArrayBuffer) => { assertEquals(actual, uint.buffer); }); ws.close(); }; - ws.onclose = (): void => { + ws.onclose = () => { promise.resolve(); }; await promise; @@ -229,13 +229,13 @@ Deno.test("echo uint8array with binaryType arraybuffer", async () => { const ws = new WebSocket("ws://localhost:4242"); ws.binaryType = "arraybuffer"; const uint = new Uint8Array([102, 111, 111]); - ws.onerror = (): void => fail(); - ws.onopen = (): void => ws.send(uint); - ws.onmessage = (e): void => { + ws.onerror = () => fail(); + ws.onopen = () => ws.send(uint); + ws.onmessage = (e) => { assertEquals(e.data, uint.buffer); ws.close(); }; - ws.onclose = (): void => { + ws.onclose = () => { promise.resolve(); }; await promise; @@ -245,15 +245,15 @@ Deno.test("echo arraybuffer with binaryType blob", async () => { const promise = deferred(); const ws = new WebSocket("ws://localhost:4242"); const buffer = new ArrayBuffer(3); - ws.onerror = (): void => fail(); - ws.onopen = (): void => ws.send(buffer); - ws.onmessage = (e): void => { + ws.onerror = () => fail(); + ws.onopen = () => ws.send(buffer); + ws.onmessage = (e) => { e.data.arrayBuffer().then((actual: ArrayBuffer) => { assertEquals(actual, buffer); }); ws.close(); }; - ws.onclose = (): void => { + ws.onclose = () => { promise.resolve(); }; await promise; @@ -264,13 +264,13 @@ Deno.test("echo arraybuffer with binaryType arraybuffer", async () => { const ws = new WebSocket("ws://localhost:4242"); ws.binaryType = "arraybuffer"; const buffer = new ArrayBuffer(3); - ws.onerror = (): void => fail(); - ws.onopen = (): void => ws.send(buffer); - ws.onmessage = (e): void => { + ws.onerror = () => fail(); + ws.onopen = () => ws.send(buffer); + ws.onmessage = (e) => { assertEquals(e.data, buffer); ws.close(); }; - ws.onclose = (): void => { + ws.onclose = () => { promise.resolve(); }; await promise; @@ -280,7 +280,7 @@ Deno.test("Event Handlers order", async () => { const promise = deferred(); const ws = new WebSocket("ws://localhost:4242"); const arr: number[] = []; - ws.onerror = (): void => fail(); + ws.onerror = () => fail(); ws.addEventListener("message", () => arr.push(1)); ws.onmessage = () => fail(); ws.addEventListener("message", () => { @@ -289,8 +289,8 @@ Deno.test("Event Handlers order", async () => { assertEquals(arr, [1, 2, 3]); }); ws.onmessage = () => arr.push(2); - ws.onopen = (): void => ws.send("Echo"); - ws.onclose = (): void => { + ws.onopen = () => ws.send("Echo"); + ws.onclose = () => { promise.resolve(); }; await promise; @@ -299,8 +299,8 @@ Deno.test("Event Handlers order", async () => { Deno.test("Close without frame", async () => { const promise = deferred(); const ws = new WebSocket("ws://localhost:4244"); - ws.onerror = (): void => fail(); - ws.onclose = (e): void => { + ws.onerror = () => fail(); + ws.onclose = (e) => { assertEquals(e.code, 1005); promise.resolve(); }; diff --git a/cli/tests/workers/bench_large_message.ts b/cli/tests/workers/bench_large_message.ts index 7f6cb26ce0..a89ea9a78f 100644 --- a/cli/tests/workers/bench_large_message.ts +++ b/cli/tests/workers/bench_large_message.ts @@ -7,7 +7,7 @@ function oneWorker(i: number) { new URL("worker_large_message.js", import.meta.url).href, { type: "module" }, ); - worker.onmessage = (_e): void => { + worker.onmessage = (_e) => { if (countDown > 0) { countDown--; return; diff --git a/cli/tests/workers/bench_round_robin.ts b/cli/tests/workers/bench_round_robin.ts index 7974760af5..a39f7ec6f2 100644 --- a/cli/tests/workers/bench_round_robin.ts +++ b/cli/tests/workers/bench_round_robin.ts @@ -10,7 +10,7 @@ import { Deferred, deferred } from "../../../test_util/std/async/deferred.ts"; function handleAsyncMsgFromWorker( promiseTable: Map>, msg: { cmdId: number; data: string }, -): void { +) { const promise = promiseTable.get(msg.cmdId); if (promise === null) { throw new Error(`Failed to find promise: cmdId: ${msg.cmdId}, msg: ${msg}`); @@ -18,7 +18,7 @@ function handleAsyncMsgFromWorker( promise?.resolve(data); } -async function main(): Promise { +async function main() { const workers: Array<[Map>, Worker]> = []; for (let i = 1; i <= workerCount; ++i) { const worker = new Worker( @@ -26,7 +26,7 @@ async function main(): Promise { { type: "module" }, ); const promise = deferred(); - worker.onmessage = (e): void => { + worker.onmessage = (e) => { if (e.data.cmdId === 0) promise.resolve(); }; worker.postMessage({ cmdId: 0, action: 2 }); @@ -35,7 +35,7 @@ async function main(): Promise { } // assign callback function for (const [promiseTable, worker] of workers) { - worker.onmessage = (e): void => { + worker.onmessage = (e) => { handleAsyncMsgFromWorker(promiseTable, e.data); }; } @@ -53,7 +53,7 @@ async function main(): Promise { } for (const [, worker] of workers) { const promise = deferred(); - worker.onmessage = (e): void => { + worker.onmessage = (e) => { if (e.data.cmdId === 3) promise.resolve(); }; worker.postMessage({ action: 3 }); diff --git a/cli/tests/workers/bench_startup.ts b/cli/tests/workers/bench_startup.ts index 5fbf23b453..bcf21ef44d 100644 --- a/cli/tests/workers/bench_startup.ts +++ b/cli/tests/workers/bench_startup.ts @@ -1,15 +1,15 @@ // Benchmark measures time it takes to start and stop a number of workers. const workerCount = 50; -async function bench(): Promise { +async function bench() { const workers: Worker[] = []; for (let i = 1; i <= workerCount; ++i) { const worker = new Worker( new URL("bench_worker.ts", import.meta.url).href, { type: "module" }, ); - const promise = new Promise((resolve): void => { - worker.onmessage = (e): void => { + const promise = new Promise((resolve) => { + worker.onmessage = (e) => { if (e.data.cmdId === 0) resolve(); }; }); @@ -19,8 +19,8 @@ async function bench(): Promise { } console.log("Done creating workers closing workers!"); for (const worker of workers) { - const promise = new Promise((resolve): void => { - worker.onmessage = (e): void => { + const promise = new Promise((resolve) => { + worker.onmessage = (e) => { if (e.data.cmdId === 3) resolve(); }; }); diff --git a/cli/tests/workers/bench_worker.ts b/cli/tests/workers/bench_worker.ts index 7e85eed036..1edd2750f4 100644 --- a/cli/tests/workers/bench_worker.ts +++ b/cli/tests/workers/bench_worker.ts @@ -1,4 +1,4 @@ -onmessage = function (e): void { +onmessage = function (e) { const { cmdId, action, data } = e.data; switch (action) { case 0: // Static response diff --git a/cli/tests/workers/deno_worker.ts b/cli/tests/workers/deno_worker.ts index 6a57c47f0f..2a29c8c4df 100644 --- a/cli/tests/workers/deno_worker.ts +++ b/cli/tests/workers/deno_worker.ts @@ -1,4 +1,4 @@ -onmessage = function (e): void { +onmessage = function (e) { if (typeof self.Deno === "undefined") { throw new Error("Deno namespace not available in worker"); } diff --git a/cli/tests/workers/test.ts b/cli/tests/workers/test.ts index d62b644a4d..44cbca0fec 100644 --- a/cli/tests/workers/test.ts +++ b/cli/tests/workers/test.ts @@ -12,7 +12,7 @@ import { fromFileUrl } from "../../../test_util/std/path/mod.ts"; Deno.test({ name: "worker terminate", - fn: async function (): Promise { + fn: async function () { const promise = deferred(); const jsWorker = new Worker( @@ -24,17 +24,17 @@ Deno.test({ { type: "module", name: "tsWorker" }, ); - tsWorker.onmessage = (e): void => { + tsWorker.onmessage = (e) => { assertEquals(e.data, "Hello World"); promise.resolve(); }; - jsWorker.onmessage = (e): void => { + jsWorker.onmessage = (e) => { assertEquals(e.data, "Hello World"); tsWorker.postMessage("Hello World"); }; - jsWorker.onerror = (e: Event): void => { + jsWorker.onerror = (e: Event) => { e.preventDefault(); jsWorker.postMessage("Hello World"); }; @@ -55,7 +55,7 @@ Deno.test({ { type: "module", name: "tsWorker" }, ); - tsWorker.onmessage = (e): void => { + tsWorker.onmessage = (e) => { assertEquals(e.data, "Hello World"); promise.resolve(); }; @@ -69,7 +69,7 @@ Deno.test({ Deno.test({ name: "worker nested", - fn: async function (): Promise { + fn: async function () { const promise = deferred(); const nestedWorker = new Worker( @@ -77,7 +77,7 @@ Deno.test({ { type: "module", name: "nested" }, ); - nestedWorker.onmessage = (e): void => { + nestedWorker.onmessage = (e) => { assert(e.data.type !== "error"); promise.resolve(); }; @@ -90,7 +90,7 @@ Deno.test({ Deno.test({ name: "worker throws when executing", - fn: async function (): Promise { + fn: async function () { const promise = deferred(); const throwingWorker = new Worker( new URL("throwing_worker.js", import.meta.url).href, @@ -98,7 +98,7 @@ Deno.test({ ); // deno-lint-ignore no-explicit-any - throwingWorker.onerror = (e: any): void => { + throwingWorker.onerror = (e: any) => { e.preventDefault(); assert(/Uncaught Error: Thrown error/.test(e.message)); promise.resolve(); @@ -111,14 +111,14 @@ Deno.test({ Deno.test({ name: "worker globals", - fn: async function (): Promise { + fn: async function () { const promise = deferred(); const workerOptions: WorkerOptions = { type: "module" }; const w = new Worker( new URL("worker_globals.ts", import.meta.url).href, workerOptions, ); - w.onmessage = (e): void => { + w.onmessage = (e) => { assertEquals(e.data, "true, true, true, true"); promise.resolve(); }; @@ -130,7 +130,7 @@ Deno.test({ Deno.test({ name: "worker fetch API", - fn: async function (): Promise { + fn: async function () { const promise = deferred(); const fetchingWorker = new Worker( @@ -139,13 +139,13 @@ Deno.test({ ); // deno-lint-ignore no-explicit-any - fetchingWorker.onerror = (e: any): void => { + fetchingWorker.onerror = (e: any) => { e.preventDefault(); promise.reject(e.message); }; // Defer promise.resolve() to allow worker to shut down - fetchingWorker.onmessage = (e): void => { + fetchingWorker.onmessage = (e) => { assert(e.data === "Done!"); promise.resolve(); }; @@ -157,7 +157,7 @@ Deno.test({ Deno.test({ name: "worker terminate busy loop", - fn: async function (): Promise { + fn: async function () { const promise = deferred(); const busyWorker = new Worker( @@ -167,11 +167,11 @@ Deno.test({ let testResult = 0; - busyWorker.onmessage = (e): void => { + busyWorker.onmessage = (e) => { testResult = e.data; if (testResult >= 10000) { busyWorker.terminate(); - busyWorker.onmessage = (_e): void => { + busyWorker.onmessage = (_e) => { throw new Error("unreachable"); }; setTimeout(() => { @@ -188,7 +188,7 @@ Deno.test({ Deno.test({ name: "worker race condition", - fn: async function (): Promise { + fn: async function () { // See issue for details // https://github.com/denoland/deno/issues/4080 const promise = deferred(); @@ -198,7 +198,7 @@ Deno.test({ { type: "module" }, ); - racyWorker.onmessage = (_e): void => { + racyWorker.onmessage = (_e) => { setTimeout(() => { promise.resolve(); }, 100); @@ -211,7 +211,7 @@ Deno.test({ Deno.test({ name: "worker is event listener", - fn: async function (): Promise { + fn: async function () { let messageHandlersCalled = 0; let errorHandlersCalled = 0; @@ -223,7 +223,7 @@ Deno.test({ { type: "module" }, ); - worker.onmessage = (_e: Event): void => { + worker.onmessage = (_e: Event) => { messageHandlersCalled++; }; worker.addEventListener("message", (_e: Event) => { @@ -234,7 +234,7 @@ Deno.test({ promise1.resolve(); }); - worker.onerror = (e): void => { + worker.onerror = (e) => { errorHandlersCalled++; e.preventDefault(); }; @@ -259,7 +259,7 @@ Deno.test({ Deno.test({ name: "worker scope is event listener", - fn: async function (): Promise { + fn: async function () { const promise1 = deferred(); const worker = new Worker( @@ -267,14 +267,14 @@ Deno.test({ { type: "module" }, ); - worker.onmessage = (e: MessageEvent): void => { + worker.onmessage = (e: MessageEvent) => { const { messageHandlersCalled, errorHandlersCalled } = e.data; assertEquals(messageHandlersCalled, 4); assertEquals(errorHandlersCalled, 4); promise1.resolve(); }; - worker.onerror = (_e): void => { + worker.onerror = (_e) => { throw new Error("unreachable"); }; @@ -287,7 +287,7 @@ Deno.test({ Deno.test({ name: "worker with Deno namespace", - fn: async function (): Promise { + fn: async function () { const promise = deferred(); const promise2 = deferred(); @@ -306,13 +306,13 @@ Deno.test({ }, ); - regularWorker.onmessage = (e): void => { + regularWorker.onmessage = (e) => { assertEquals(e.data, "Hello World"); regularWorker.terminate(); promise.resolve(); }; - denoWorker.onmessage = (e): void => { + denoWorker.onmessage = (e) => { assertEquals(e.data, "Hello World"); denoWorker.terminate(); promise2.resolve(); @@ -327,13 +327,13 @@ Deno.test({ Deno.test({ name: "worker with crypto in scope", - fn: async function (): Promise { + fn: async function () { const promise = deferred(); const w = new Worker( new URL("worker_crypto.js", import.meta.url).href, { type: "module" }, ); - w.onmessage = (e): void => { + w.onmessage = (e) => { assertEquals(e.data, true); promise.resolve(); }; @@ -345,7 +345,7 @@ Deno.test({ Deno.test({ name: "Worker event handler order", - fn: async function (): Promise { + fn: async function () { const promise = deferred(); const w = new Worker( new URL("test_worker.ts", import.meta.url).href, @@ -353,7 +353,7 @@ Deno.test({ ); const arr: number[] = []; w.addEventListener("message", () => arr.push(1)); - w.onmessage = (_e): void => { + w.onmessage = (_e) => { arr.push(2); }; w.addEventListener("message", () => arr.push(3)); @@ -369,7 +369,7 @@ Deno.test({ Deno.test({ name: "Worker immediate close", - fn: async function (): Promise { + fn: async function () { const promise = deferred(); const w = new Worker( new URL("./immediately_close_worker.js", import.meta.url).href, @@ -385,14 +385,14 @@ Deno.test({ Deno.test({ name: "Worker post undefined", - fn: async function (): Promise { + fn: async function () { const promise = deferred(); const worker = new Worker( new URL("./post_undefined.ts", import.meta.url).href, { type: "module" }, ); - const handleWorkerMessage = (e: MessageEvent): void => { + const handleWorkerMessage = (e: MessageEvent) => { console.log("main <- worker:", e.data); worker.terminate(); promise.resolve(); @@ -650,12 +650,12 @@ Deno.test("Worker with disabled permissions", async function () { Deno.test({ name: "worker location", - fn: async function (): Promise { + fn: async function () { const promise = deferred(); const workerModuleHref = new URL("worker_location.ts", import.meta.url).href; const w = new Worker(workerModuleHref, { type: "module" }); - w.onmessage = (e): void => { + w.onmessage = (e) => { assertEquals(e.data, `${workerModuleHref}, true`); promise.resolve(); }; @@ -667,14 +667,14 @@ Deno.test({ Deno.test({ name: "worker with relative specifier", - fn: async function (): Promise { + fn: async function () { assertEquals(location.href, "http://127.0.0.1:4545/cli/tests/"); const promise = deferred(); const w = new Worker( "./workers/test_worker.ts", { type: "module", name: "tsWorker" }, ); - w.onmessage = (e): void => { + w.onmessage = (e) => { assertEquals(e.data, "Hello, world!"); promise.resolve(); }; @@ -686,13 +686,13 @@ Deno.test({ Deno.test({ name: "Worker with top-level-await", - fn: async function (): Promise { + fn: async function () { const result = deferred(); const worker = new Worker( new URL("worker_with_top_level_await.ts", import.meta.url).href, { type: "module" }, ); - worker.onmessage = (e): void => { + worker.onmessage = (e) => { if (e.data == "ready") { worker.postMessage("trigger worker handler"); } else if (e.data == "triggered worker handler") { @@ -737,14 +737,14 @@ Deno.test({ Deno.test({ name: "structured cloning postMessage", - fn: async function (): Promise { + fn: async function () { const result = deferred(); const worker = new Worker( new URL("worker_structured_cloning.ts", import.meta.url).href, { type: "module" }, ); - worker.onmessage = (e): void => { + worker.onmessage = (e) => { // self field should reference itself (circular ref) const value = e.data.self.self.self; @@ -772,14 +772,14 @@ Deno.test({ Deno.test({ name: "worker with relative specifier", - fn: async function (): Promise { + fn: async function () { assertEquals(location.href, "http://127.0.0.1:4545/cli/tests/"); const promise = deferred(); const w = new Worker( "./workers/test_worker.ts", { type: "module", name: "tsWorker" }, ); - w.onmessage = (e): void => { + w.onmessage = (e) => { assertEquals(e.data, "Hello, world!"); promise.resolve(); }; @@ -791,7 +791,7 @@ Deno.test({ Deno.test({ name: "worker SharedArrayBuffer", - fn: async function (): Promise { + fn: async function () { const promise = deferred(); const workerOptions: WorkerOptions = { type: "module" }; const w = new Worker( @@ -804,9 +804,9 @@ Deno.test({ const bytes2 = new Uint8Array(sab2); assertEquals(bytes1[0], 0); assertEquals(bytes2[0], 0); - w.onmessage = (): void => { + w.onmessage = () => { w.postMessage([sab1, sab2]); - w.onmessage = (): void => { + w.onmessage = () => { assertEquals(bytes1[0], 1); assertEquals(bytes2[0], 2); promise.resolve(); @@ -819,7 +819,7 @@ Deno.test({ Deno.test({ name: "Send MessagePorts from / to workers", - fn: async function (): Promise { + fn: async function () { const result = deferred(); const worker = new Worker( new URL("message_port.ts", import.meta.url).href, diff --git a/cli/tests/workers/test_worker.ts b/cli/tests/workers/test_worker.ts index ca79dcfe46..9964760581 100644 --- a/cli/tests/workers/test_worker.ts +++ b/cli/tests/workers/test_worker.ts @@ -2,7 +2,7 @@ if (self.name !== "tsWorker") { throw Error(`Invalid worker name: ${self.name}, expected tsWorker`); } -onmessage = function (e): void { +onmessage = function (e) { postMessage(e.data); close(); }; diff --git a/cli/tests/workers/worker_globals.ts b/cli/tests/workers/worker_globals.ts index f262423069..90e369e418 100644 --- a/cli/tests/workers/worker_globals.ts +++ b/cli/tests/workers/worker_globals.ts @@ -1,4 +1,4 @@ -onmessage = function (): void { +onmessage = function () { postMessage( [ self instanceof DedicatedWorkerGlobalScope, diff --git a/cli/tests/workers/worker_location.ts b/cli/tests/workers/worker_location.ts index 89fa83036b..c3c1bb26ff 100644 --- a/cli/tests/workers/worker_location.ts +++ b/cli/tests/workers/worker_location.ts @@ -1,4 +1,4 @@ -onmessage = function (): void { +onmessage = function () { postMessage( `${location.href}, ${location instanceof WorkerLocation}`, ); diff --git a/cli/tests/workers/worker_with_top_level_await.ts b/cli/tests/workers/worker_with_top_level_await.ts index bc77c7932e..1d20bb7362 100644 --- a/cli/tests/workers/worker_with_top_level_await.ts +++ b/cli/tests/workers/worker_with_top_level_await.ts @@ -1,4 +1,4 @@ -function delay(ms: number): Promise { +function delay(ms: number) { return new Promise((resolve) => { setTimeout(() => { resolve();