From bedb2adfb065c1b0d3bcb773fbeff91230402b6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 23 Nov 2021 17:45:18 +0100 Subject: [PATCH] refactor: remove "unitTest" wrapper from cli/tests/unit (#12750) --- cli/tests/testdata/fmt/fmt_with_config/a.ts | 2 +- cli/tests/testdata/fmt/fmt_with_config/b.ts | 2 +- cli/tests/unit/README.md | 8 +- cli/tests/unit/abort_controller_test.ts | 14 +- cli/tests/unit/blob_test.ts | 29 ++-- cli/tests/unit/body_test.ts | 12 +- cli/tests/unit/buffer_test.ts | 47 +++--- cli/tests/unit/build_test.ts | 4 +- cli/tests/unit/chmod_test.ts | 21 ++- cli/tests/unit/chown_test.ts | 29 ++-- cli/tests/unit/console_test.ts | 103 ++++++------ cli/tests/unit/copy_file_test.ts | 31 ++-- cli/tests/unit/custom_event_test.ts | 6 +- cli/tests/unit/dir_test.ts | 12 +- cli/tests/unit/dom_exception_test.ts | 4 +- cli/tests/unit/error_stack_test.ts | 8 +- cli/tests/unit/esnext_test.ts | 8 +- cli/tests/unit/event_target_test.ts | 28 ++-- cli/tests/unit/event_test.ts | 27 ++- cli/tests/unit/fetch_test.ts | 176 ++++++++++---------- cli/tests/unit/ffi_test.ts | 4 +- cli/tests/unit/file_test.ts | 46 ++--- cli/tests/unit/filereader_test.ts | 18 +- cli/tests/unit/files_test.ts | 67 ++++---- cli/tests/unit/flock_test.ts | 6 +- cli/tests/unit/format_error_test.ts | 6 +- cli/tests/unit/fs_events_test.ts | 18 +- cli/tests/unit/get_random_values_test.ts | 18 +- cli/tests/unit/globals_test.ts | 42 ++--- cli/tests/unit/headers_test.ts | 52 +++--- cli/tests/unit/http_test.ts | 69 ++++---- cli/tests/unit/internals_test.ts | 4 +- cli/tests/unit/io_test.ts | 8 +- cli/tests/unit/link_test.ts | 21 ++- cli/tests/unit/make_temp_test.ts | 21 ++- cli/tests/unit/metrics_test.ts | 10 +- cli/tests/unit/mkdir_test.ts | 33 ++-- cli/tests/unit/navigator_test.ts | 4 +- cli/tests/unit/net_test.ts | 65 ++++---- cli/tests/unit/opcall_test.ts | 13 +- cli/tests/unit/os_test.ts | 39 +++-- cli/tests/unit/path_from_url_test.ts | 6 +- cli/tests/unit/performance_test.ts | 19 +-- cli/tests/unit/permissions_test.ts | 15 +- cli/tests/unit/process_test.ts | 68 ++++---- cli/tests/unit/progressevent_test.ts | 4 +- cli/tests/unit/read_dir_test.ts | 23 ++- cli/tests/unit/read_file_test.ts | 29 ++-- cli/tests/unit/read_link_test.ts | 17 +- cli/tests/unit/read_text_file_test.ts | 25 ++- cli/tests/unit/real_path_test.ts | 21 ++- cli/tests/unit/remove_test.ts | 30 ++-- cli/tests/unit/rename_test.ts | 17 +- cli/tests/unit/request_test.ts | 14 +- cli/tests/unit/resources_test.ts | 10 +- cli/tests/unit/response_test.ts | 17 +- cli/tests/unit/signal_test.ts | 18 +- cli/tests/unit/stat_test.ts | 33 ++-- cli/tests/unit/stdio_test.ts | 14 +- cli/tests/unit/streams_deprecated.ts | 4 +- cli/tests/unit/symlink_test.ts | 30 ++-- cli/tests/unit/sync_test.ts | 10 +- cli/tests/unit/test_util.ts | 66 -------- cli/tests/unit/testing_test.ts | 8 +- cli/tests/unit/text_encoding_test.ts | 46 ++--- cli/tests/unit/timers_test.ts | 59 ++++--- cli/tests/unit/tls_test.ts | 123 +++++++------- cli/tests/unit/truncate_test.ts | 23 +-- cli/tests/unit/tty_test.ts | 10 +- cli/tests/unit/umask_test.ts | 4 +- cli/tests/unit/url_search_params_test.ts | 66 ++++---- cli/tests/unit/url_test.ts | 67 ++++---- cli/tests/unit/urlpattern_test.ts | 8 +- cli/tests/unit/utime_test.ts | 35 ++-- cli/tests/unit/version_test.ts | 4 +- cli/tests/unit/wasm_test.ts | 12 +- cli/tests/unit/webcrypto_test.ts | 42 ++--- cli/tests/unit/webgpu_test.ts | 6 +- cli/tests/unit/websocket_test.ts | 4 +- cli/tests/unit/worker_permissions_test.ts | 4 +- cli/tests/unit/worker_types.ts | 4 +- cli/tests/unit/write_file_test.ts | 33 ++-- cli/tests/unit/write_text_file_test.ts | 29 ++-- 83 files changed, 1049 insertions(+), 1163 deletions(-) diff --git a/cli/tests/testdata/fmt/fmt_with_config/a.ts b/cli/tests/testdata/fmt/fmt_with_config/a.ts index e0f32647b6..50db0d2e10 100644 --- a/cli/tests/testdata/fmt/fmt_with_config/a.ts +++ b/cli/tests/testdata/fmt/fmt_with_config/a.ts @@ -1,4 +1,4 @@ -unitTest( +Deno.test( { perms: { net: true } }, async function responseClone() { const response = diff --git a/cli/tests/testdata/fmt/fmt_with_config/b.ts b/cli/tests/testdata/fmt/fmt_with_config/b.ts index 5c37d51d28..840198d898 100644 --- a/cli/tests/testdata/fmt/fmt_with_config/b.ts +++ b/cli/tests/testdata/fmt/fmt_with_config/b.ts @@ -1,5 +1,5 @@ // This file should be excluded from formatting -unitTest( +Deno.test( { perms: { net: true } }, async function fetchBodyUsedCancelStream() { const response = await fetch( diff --git a/cli/tests/unit/README.md b/cli/tests/unit/README.md index adaa1ed0e8..0d9e175541 100644 --- a/cli/tests/unit/README.md +++ b/cli/tests/unit/README.md @@ -4,16 +4,16 @@ Files in this directory are unit tests for Deno runtime. Testing Deno runtime code requires checking API under different runtime permissions. To accomplish this all tests exercised are created using -`unitTest()` function. +`Deno.test()` function. ```ts -import { unitTest } from "./test_util.ts"; +import {} from "./test_util.ts"; -unitTest(function simpleTestFn(): void { +Deno.test(function simpleTestFn(): void { // test code here }); -unitTest( +Deno.test( { ignore: Deno.build.os === "windows", permissions: { read: true, write: true }, diff --git a/cli/tests/unit/abort_controller_test.ts b/cli/tests/unit/abort_controller_test.ts index 50a17ad240..6b7bea899b 100644 --- a/cli/tests/unit/abort_controller_test.ts +++ b/cli/tests/unit/abort_controller_test.ts @@ -1,6 +1,6 @@ -import { assert, assertEquals, unitTest } from "./test_util.ts"; +import { assert, assertEquals } from "./test_util.ts"; -unitTest(function basicAbortController() { +Deno.test(function basicAbortController() { const controller = new AbortController(); assert(controller); const { signal } = controller; @@ -10,7 +10,7 @@ unitTest(function basicAbortController() { assertEquals(signal.aborted, true); }); -unitTest(function signalCallsOnabort() { +Deno.test(function signalCallsOnabort() { const controller = new AbortController(); const { signal } = controller; let called = false; @@ -23,7 +23,7 @@ unitTest(function signalCallsOnabort() { assert(called); }); -unitTest(function signalEventListener() { +Deno.test(function signalEventListener() { const controller = new AbortController(); const { signal } = controller; let called = false; @@ -36,7 +36,7 @@ unitTest(function signalEventListener() { assert(called); }); -unitTest(function onlyAbortsOnce() { +Deno.test(function onlyAbortsOnce() { const controller = new AbortController(); const { signal } = controller; let called = 0; @@ -50,12 +50,12 @@ unitTest(function onlyAbortsOnce() { assertEquals(called, 2); }); -unitTest(function controllerHasProperToString() { +Deno.test(function controllerHasProperToString() { const actual = Object.prototype.toString.call(new AbortController()); assertEquals(actual, "[object AbortController]"); }); -unitTest(function abortReason() { +Deno.test(function abortReason() { const signal = AbortSignal.abort("hey!"); assertEquals(signal.aborted, true); assertEquals(signal.reason, "hey!"); diff --git a/cli/tests/unit/blob_test.ts b/cli/tests/unit/blob_test.ts index 8ce2791602..f9f4598d1e 100644 --- a/cli/tests/unit/blob_test.ts +++ b/cli/tests/unit/blob_test.ts @@ -1,20 +1,15 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -import { - assert, - assertEquals, - assertStringIncludes, - unitTest, -} from "./test_util.ts"; +import { assert, assertEquals, assertStringIncludes } from "./test_util.ts"; import { concat } from "../../../test_util/std/bytes/mod.ts"; -unitTest(function blobString() { +Deno.test(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() { +Deno.test(function blobBuffer() { const buffer = new ArrayBuffer(12); const u8 = new Uint8Array(buffer); const f1 = new Float32Array(buffer); @@ -24,7 +19,7 @@ unitTest(function blobBuffer() { assertEquals(b2.size, 3 * u8.length); }); -unitTest(function blobSlice() { +Deno.test(function blobSlice() { const blob = new Blob(["Deno", "Foo"]); const b1 = blob.slice(0, 3, "Text/HTML"); assert(b1 instanceof Blob); @@ -38,7 +33,7 @@ unitTest(function blobSlice() { assertEquals(b4.size, blob.size); }); -unitTest(function blobInvalidType() { +Deno.test(function blobInvalidType() { const blob = new Blob(["foo"], { type: "\u0521", }); @@ -46,7 +41,7 @@ unitTest(function blobInvalidType() { assertEquals(blob.type, ""); }); -unitTest(function blobShouldNotThrowError() { +Deno.test(function blobShouldNotThrowError() { let hasThrown = false; try { @@ -66,7 +61,7 @@ unitTest(function blobShouldNotThrowError() { }); /* TODO https://github.com/denoland/deno/issues/7540 -unitTest(function nativeEndLine() { +Deno.test(function nativeEndLine() { const options = { ending: "native", } as const; @@ -76,12 +71,12 @@ unitTest(function nativeEndLine() { }); */ -unitTest(async function blobText() { +Deno.test(async function blobText() { const blob = new Blob(["Hello World"]); assertEquals(await blob.text(), "Hello World"); }); -unitTest(async function blobStream() { +Deno.test(async function blobStream() { const blob = new Blob(["Hello World"]); const stream = blob.stream(); assert(stream instanceof ReadableStream); @@ -99,18 +94,18 @@ unitTest(async function blobStream() { assertEquals(decoder.decode(bytes), "Hello World"); }); -unitTest(async function blobArrayBuffer() { +Deno.test(async function blobArrayBuffer() { const uint = new Uint8Array([102, 111, 111]); const blob = new Blob([uint]); assertEquals(await blob.arrayBuffer(), uint.buffer); }); -unitTest(function blobConstructorNameIsBlob() { +Deno.test(function blobConstructorNameIsBlob() { const blob = new Blob(); assertEquals(blob.constructor.name, "Blob"); }); -unitTest(function blobCustomInspectFunction() { +Deno.test(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 1c12c5eda9..a95487aa45 100644 --- a/cli/tests/unit/body_test.ts +++ b/cli/tests/unit/body_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals, unitTest } from "./test_util.ts"; +import { assert, assertEquals } from "./test_util.ts"; // just a hack to get a body object // deno-lint-ignore no-explicit-any @@ -23,7 +23,7 @@ const intArrays = [ Float32Array, Float64Array, ]; -unitTest(async function arrayBufferFromByteArrays() { +Deno.test(async function arrayBufferFromByteArrays() { const buffer = new TextEncoder().encode("ahoyhoy8").buffer; for (const type of intArrays) { @@ -34,7 +34,7 @@ unitTest(async function arrayBufferFromByteArrays() { }); //FormData -unitTest( +Deno.test( { permissions: { net: true } }, async function bodyMultipartFormData() { const response = await fetch( @@ -53,7 +53,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function bodyURLEncodedFormData() { const response = await fetch( @@ -73,14 +73,14 @@ unitTest( }, ); -unitTest({ permissions: {} }, async function bodyURLSearchParams() { +Deno.test({ permissions: {} }, async function bodyURLSearchParams() { const body = buildBody(new URLSearchParams({ hello: "world" })); const text = await body.text(); assertEquals(text, "hello=world"); }); -unitTest(async function bodyArrayBufferMultipleParts() { +Deno.test(async function bodyArrayBufferMultipleParts() { const parts: Uint8Array[] = []; let size = 0; for (let i = 0; i <= 150000; i++) { diff --git a/cli/tests/unit/buffer_test.ts b/cli/tests/unit/buffer_test.ts index ceeb3fb8a9..34116e5ce8 100644 --- a/cli/tests/unit/buffer_test.ts +++ b/cli/tests/unit/buffer_test.ts @@ -10,7 +10,6 @@ import { assertEquals, assertRejects, assertThrows, - unitTest, } from "./test_util.ts"; const MAX_SIZE = 2 ** 32 - 2; @@ -87,7 +86,7 @@ function repeat(c: string, bytes: number): Uint8Array { return ui8; } -unitTest(function bufferNewBuffer() { +Deno.test(function bufferNewBuffer() { init(); assert(testBytes); assert(testString); @@ -95,7 +94,7 @@ unitTest(function bufferNewBuffer() { check(buf, testString); }); -unitTest(async function bufferBasicOperations() { +Deno.test(async function bufferBasicOperations() { init(); assert(testBytes); assert(testString); @@ -135,7 +134,7 @@ unitTest(async function bufferBasicOperations() { } }); -unitTest(async function bufferReadEmptyAtEOF() { +Deno.test(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 +143,7 @@ unitTest(async function bufferReadEmptyAtEOF() { assertEquals(result, 0); }); -unitTest(async function bufferLargeByteWrites() { +Deno.test(async function bufferLargeByteWrites() { init(); const buf = new Deno.Buffer(); const limit = 9; @@ -155,7 +154,7 @@ unitTest(async function bufferLargeByteWrites() { check(buf, ""); }); -unitTest(async function bufferTooLargeByteWrites() { +Deno.test(async function bufferTooLargeByteWrites() { init(); const tmp = new Uint8Array(72); const growLen = Number.MAX_VALUE; @@ -172,7 +171,7 @@ unitTest(async function bufferTooLargeByteWrites() { ); }); -unitTest( +Deno.test( { ignore: ignoreMaxSizeTests }, function bufferGrowWriteMaxBuffer() { const bufSize = 16 * 1024; @@ -194,7 +193,7 @@ unitTest( }, ); -unitTest( +Deno.test( { ignore: ignoreMaxSizeTests }, async function bufferGrowReadCloseMaxBufferPlus1() { const reader = new Deno.Buffer(new ArrayBuffer(MAX_SIZE + 1)); @@ -210,7 +209,7 @@ unitTest( }, ); -unitTest( +Deno.test( { ignore: ignoreMaxSizeTests }, function bufferGrowReadSyncCloseMaxBufferPlus1() { const reader = new Deno.Buffer(new ArrayBuffer(MAX_SIZE + 1)); @@ -226,7 +225,7 @@ unitTest( }, ); -unitTest( +Deno.test( { ignore: ignoreMaxSizeTests }, function bufferGrowReadSyncCloseToMaxBuffer() { const capacities = [MAX_SIZE, MAX_SIZE - 1]; @@ -240,7 +239,7 @@ unitTest( }, ); -unitTest( +Deno.test( { ignore: ignoreMaxSizeTests }, async function bufferGrowReadCloseToMaxBuffer() { const capacities = [MAX_SIZE, MAX_SIZE - 1]; @@ -253,7 +252,7 @@ unitTest( }, ); -unitTest( +Deno.test( { ignore: ignoreMaxSizeTests }, async function bufferReadCloseToMaxBufferWithInitialGrow() { const capacities = [MAX_SIZE, MAX_SIZE - 1, MAX_SIZE - 512]; @@ -267,7 +266,7 @@ unitTest( }, ); -unitTest(async function bufferLargeByteReads() { +Deno.test(async function bufferLargeByteReads() { init(); assert(testBytes); assert(testString); @@ -280,12 +279,12 @@ unitTest(async function bufferLargeByteReads() { check(buf, ""); }); -unitTest(function bufferCapWithPreallocatedSlice() { +Deno.test(function bufferCapWithPreallocatedSlice() { const buf = new Deno.Buffer(new ArrayBuffer(10)); assertEquals(buf.capacity, 10); }); -unitTest(async function bufferReadFrom() { +Deno.test(async function bufferReadFrom() { init(); assert(testBytes); assert(testString); @@ -307,7 +306,7 @@ unitTest(async function bufferReadFrom() { }); }); -unitTest(async function bufferReadFromSync() { +Deno.test(async function bufferReadFromSync() { init(); assert(testBytes); assert(testString); @@ -329,7 +328,7 @@ unitTest(async function bufferReadFromSync() { }); }); -unitTest(async function bufferTestGrow() { +Deno.test(async function bufferTestGrow() { const tmp = new Uint8Array(72); for (const startLen of [0, 100, 1000, 10000]) { const xBytes = repeat("x", startLen); @@ -353,7 +352,7 @@ unitTest(async function bufferTestGrow() { } }); -unitTest(async function testReadAll() { +Deno.test(async function testReadAll() { init(); assert(testBytes); const reader = new Deno.Buffer(testBytes.buffer as ArrayBuffer); @@ -364,7 +363,7 @@ unitTest(async function testReadAll() { } }); -unitTest(function testReadAllSync() { +Deno.test(function testReadAllSync() { init(); assert(testBytes); const reader = new Deno.Buffer(testBytes.buffer as ArrayBuffer); @@ -375,7 +374,7 @@ unitTest(function testReadAllSync() { } }); -unitTest(async function testWriteAll() { +Deno.test(async function testWriteAll() { init(); assert(testBytes); const writer = new Deno.Buffer(); @@ -387,7 +386,7 @@ unitTest(async function testWriteAll() { } }); -unitTest(function testWriteAllSync() { +Deno.test(function testWriteAllSync() { init(); assert(testBytes); const writer = new Deno.Buffer(); @@ -399,7 +398,7 @@ unitTest(function testWriteAllSync() { } }); -unitTest(function testBufferBytesArrayBufferLength() { +Deno.test(function testBufferBytesArrayBufferLength() { // defaults to copy const args = [{}, { copy: undefined }, undefined, { copy: true }]; for (const arg of args) { @@ -418,7 +417,7 @@ unitTest(function testBufferBytesArrayBufferLength() { } }); -unitTest(function testBufferBytesCopyFalse() { +Deno.test(function testBufferBytesCopyFalse() { const bufSize = 64 * 1024; const bytes = new TextEncoder().encode("a".repeat(bufSize)); const reader = new Deno.Buffer(); @@ -433,7 +432,7 @@ unitTest(function testBufferBytesCopyFalse() { assert(actualBytes.buffer.byteLength > actualBytes.byteLength); }); -unitTest(function testBufferBytesCopyFalseGrowExactBytes() { +Deno.test(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 01027d4f1d..fe16a40d46 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"; +import { assert } from "./test_util.ts"; -unitTest(function buildInfo() { +Deno.test(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 2ab4c5b0cc..f460e14c5c 100644 --- a/cli/tests/unit/chmod_test.ts +++ b/cli/tests/unit/chmod_test.ts @@ -4,10 +4,9 @@ import { assertEquals, assertRejects, assertThrows, - unitTest, } from "./test_util.ts"; -unitTest( +Deno.test( { ignore: Deno.build.os === "windows", permissions: { read: true, write: true }, @@ -27,7 +26,7 @@ unitTest( }, ); -unitTest( +Deno.test( { ignore: Deno.build.os === "windows", permissions: { read: true, write: true }, @@ -50,7 +49,7 @@ unitTest( ); // Check symlink when not on windows -unitTest( +Deno.test( { ignore: Deno.build.os === "windows", permissions: { read: true, write: true }, @@ -81,7 +80,7 @@ unitTest( }, ); -unitTest({ permissions: { write: true } }, function chmodSyncFailure() { +Deno.test({ permissions: { write: true } }, function chmodSyncFailure() { const filename = "/badfile.txt"; assertThrows( () => { @@ -92,13 +91,13 @@ unitTest({ permissions: { write: true } }, function chmodSyncFailure() { ); }); -unitTest({ permissions: { write: false } }, function chmodSyncPerm() { +Deno.test({ permissions: { write: false } }, function chmodSyncPerm() { assertThrows(() => { Deno.chmodSync("/somefile.txt", 0o777); }, Deno.errors.PermissionDenied); }); -unitTest( +Deno.test( { ignore: Deno.build.os === "windows", permissions: { read: true, write: true }, @@ -118,7 +117,7 @@ unitTest( }, ); -unitTest( +Deno.test( { ignore: Deno.build.os === "windows", permissions: { read: true, write: true }, @@ -142,7 +141,7 @@ unitTest( // Check symlink when not on windows -unitTest( +Deno.test( { ignore: Deno.build.os === "windows", permissions: { read: true, write: true }, @@ -173,7 +172,7 @@ unitTest( }, ); -unitTest({ permissions: { write: true } }, async function chmodFailure() { +Deno.test({ permissions: { write: true } }, async function chmodFailure() { const filename = "/badfile.txt"; await assertRejects( async () => { @@ -184,7 +183,7 @@ unitTest({ permissions: { write: true } }, async function chmodFailure() { ); }); -unitTest({ permissions: { write: false } }, async function chmodPerm() { +Deno.test({ permissions: { write: false } }, async function chmodPerm() { await assertRejects(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 82335a7aff..e7544442a0 100644 --- a/cli/tests/unit/chown_test.ts +++ b/cli/tests/unit/chown_test.ts @@ -1,10 +1,5 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -import { - assertEquals, - assertRejects, - assertThrows, - unitTest, -} from "./test_util.ts"; +import { assertEquals, assertRejects, assertThrows } from "./test_util.ts"; // chown on Windows is noop for now, so ignore its testing on Windows @@ -29,8 +24,8 @@ async function getUidAndGid(): Promise<{ uid: number; gid: number }> { return { uid, gid }; } -unitTest( - { ignore: Deno.build.os == "windows" }, +Deno.test( + { ignore: Deno.build.os == "windows", permissions: { write: false } }, async function chownNoWritePermission() { const filePath = "chown_test_file.txt"; await assertRejects(async () => { @@ -39,7 +34,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { run: true, write: true }, ignore: Deno.build.os == "windows", @@ -58,7 +53,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { run: true, write: true }, ignore: Deno.build.os == "windows", @@ -77,7 +72,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { write: true }, ignore: Deno.build.os == "windows" }, function chownSyncPermissionDenied() { const dirPath = Deno.makeTempDirSync(); @@ -92,7 +87,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { write: true }, ignore: Deno.build.os == "windows" }, async function chownPermissionDenied() { const dirPath = await Deno.makeTempDir(); @@ -107,7 +102,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { run: true, write: true }, ignore: Deno.build.os == "windows", @@ -130,7 +125,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { run: true, write: true }, ignore: Deno.build.os == "windows", @@ -145,7 +140,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { run: true, write: true }, ignore: Deno.build.os == "windows", @@ -160,7 +155,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { run: true, write: true }, ignore: Deno.build.os == "windows", @@ -175,7 +170,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { run: true, write: true }, ignore: Deno.build.os == "windows", diff --git a/cli/tests/unit/console_test.ts b/cli/tests/unit/console_test.ts index 4201a2a467..6319f85dc2 100644 --- a/cli/tests/unit/console_test.ts +++ b/cli/tests/unit/console_test.ts @@ -13,7 +13,6 @@ import { assertEquals, assertStringIncludes, assertThrows, - unitTest, } from "./test_util.ts"; import { stripColor } from "../../../test_util/std/fmt/colors.ts"; @@ -64,7 +63,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() { +Deno.test(function consoleShouldBeANamespace() { const prototype1 = Object.getPrototypeOf(console); const prototype2 = Object.getPrototypeOf(prototype1); @@ -72,12 +71,12 @@ unitTest(function consoleShouldBeANamespace() { assertEquals(prototype2, Object.prototype); }); -unitTest(function consoleHasRightInstance() { +Deno.test(function consoleHasRightInstance() { assert(console instanceof Console); assertEquals({} instanceof Console, false); }); -unitTest(function consoleTestAssertShouldNotThrowError() { +Deno.test(function consoleTestAssertShouldNotThrowError() { mockConsole((console) => { console.assert(true); let hasThrown = undefined; @@ -91,13 +90,13 @@ unitTest(function consoleTestAssertShouldNotThrowError() { }); }); -unitTest(function consoleTestStringifyComplexObjects() { +Deno.test(function consoleTestStringifyComplexObjects() { assertEquals(stringify("foo"), "foo"); assertEquals(stringify(["foo", "bar"]), `[ "foo", "bar" ]`); assertEquals(stringify({ foo: "bar" }), `{ foo: "bar" }`); }); -unitTest( +Deno.test( function consoleTestStringifyComplexObjectsWithEscapedSequences() { assertEquals( stringify( @@ -167,14 +166,14 @@ unitTest( }, ); -unitTest(function consoleTestStringifyQuotes() { +Deno.test(function consoleTestStringifyQuotes() { assertEquals(stringify(["\\"]), `[ "\\\\" ]`); assertEquals(stringify(['\\,"']), `[ '\\\\,"' ]`); assertEquals(stringify([`\\,",'`]), `[ \`\\\\,",'\` ]`); assertEquals(stringify(["\\,\",',`"]), `[ "\\\\,\\",',\`" ]`); }); -unitTest(function consoleTestStringifyLongStrings() { +Deno.test(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 +184,7 @@ unitTest(function consoleTestStringifyLongStrings() { assertEquals(actual, veryLongString); }); -unitTest(function consoleTestStringifyCircular() { +Deno.test(function consoleTestStringifyCircular() { class Base { a = 1; m1() {} @@ -357,7 +356,7 @@ unitTest(function consoleTestStringifyCircular() { assertEquals(stripColor(Deno.inspect(nestedObj)), nestedObjExpected); }); -unitTest(function consoleTestStringifyFunctionWithPrototypeRemoved() { +Deno.test(function consoleTestStringifyFunctionWithPrototypeRemoved() { const f = function f() {}; Reflect.setPrototypeOf(f, null); assertEquals(stringify(f), "[Function: f]"); @@ -372,7 +371,7 @@ unitTest(function consoleTestStringifyFunctionWithPrototypeRemoved() { assertEquals(stringify(agf), "[Function: agf]"); }); -unitTest(function consoleTestStringifyFunctionWithProperties() { +Deno.test(function consoleTestStringifyFunctionWithProperties() { const f = () => "test"; f.x = () => "foo"; f.y = 3; @@ -416,7 +415,7 @@ unitTest(function consoleTestStringifyFunctionWithProperties() { ); }); -unitTest(function consoleTestStringifyWithDepth() { +Deno.test(function consoleTestStringifyWithDepth() { // deno-lint-ignore no-explicit-any const nestedObj: any = { a: { b: { c: { d: { e: { f: 42 } } } } } }; assertEquals( @@ -439,7 +438,7 @@ unitTest(function consoleTestStringifyWithDepth() { ); }); -unitTest(function consoleTestStringifyLargeObject() { +Deno.test(function consoleTestStringifyLargeObject() { const obj = { a: 2, o: { @@ -475,7 +474,7 @@ unitTest(function consoleTestStringifyLargeObject() { ); }); -unitTest(function consoleTestStringifyIterable() { +Deno.test(function consoleTestStringifyIterable() { const shortArray = [1, 2, 3, 4, 5]; assertEquals(stringify(shortArray), "[ 1, 2, 3, 4, 5 ]"); @@ -771,7 +770,7 @@ unitTest(function consoleTestStringifyIterable() { */ }); -unitTest(function consoleTestStringifyIterableWhenGrouped() { +Deno.test(function consoleTestStringifyIterableWhenGrouped() { const withOddNumberOfEls = new Float64Array( [ 2.1, @@ -849,7 +848,7 @@ unitTest(function consoleTestStringifyIterableWhenGrouped() { ); }); -unitTest(async function consoleTestStringifyPromises() { +Deno.test(async function consoleTestStringifyPromises() { const pendingPromise = new Promise((_res, _rej) => {}); assertEquals(stringify(pendingPromise), "Promise { }"); @@ -872,7 +871,7 @@ unitTest(async function consoleTestStringifyPromises() { assertEquals(strLines[1], " Error: Whoops"); }); -unitTest(function consoleTestWithCustomInspector() { +Deno.test(function consoleTestWithCustomInspector() { class A { [customInspect](): string { return "b"; @@ -882,7 +881,7 @@ unitTest(function consoleTestWithCustomInspector() { assertEquals(stringify(new A()), "b"); }); -unitTest(function consoleTestWithCustomInspectorUsingInspectFunc() { +Deno.test(function consoleTestWithCustomInspectorUsingInspectFunc() { class A { [customInspect]( inspect: (v: unknown, opts?: Deno.InspectOptions) => string, @@ -894,7 +893,7 @@ unitTest(function consoleTestWithCustomInspectorUsingInspectFunc() { assertEquals(stringify(new A()), "b { c: 1 }"); }); -unitTest(function consoleTestWithCustomInspectorError() { +Deno.test(function consoleTestWithCustomInspectorError() { class A { [customInspect](): never { throw new Error("BOOM"); @@ -916,7 +915,7 @@ unitTest(function consoleTestWithCustomInspectorError() { ); }); -unitTest(function consoleTestWithCustomInspectFunction() { +Deno.test(function consoleTestWithCustomInspectFunction() { function a() {} Object.assign(a, { [customInspect]() { @@ -927,7 +926,7 @@ unitTest(function consoleTestWithCustomInspectFunction() { assertEquals(stringify(a), "b"); }); -unitTest(function consoleTestWithIntegerFormatSpecifier() { +Deno.test(function consoleTestWithIntegerFormatSpecifier() { assertEquals(stringify("%i"), "%i"); assertEquals(stringify("%i", 42.0), "42"); assertEquals(stringify("%i", 42), "42"); @@ -945,7 +944,7 @@ unitTest(function consoleTestWithIntegerFormatSpecifier() { ); }); -unitTest(function consoleTestWithFloatFormatSpecifier() { +Deno.test(function consoleTestWithFloatFormatSpecifier() { assertEquals(stringify("%f"), "%f"); assertEquals(stringify("%f", 42.0), "42"); assertEquals(stringify("%f", 42), "42"); @@ -960,7 +959,7 @@ unitTest(function consoleTestWithFloatFormatSpecifier() { assertEquals(stringify("%f %f", 42), "42 %f"); }); -unitTest(function consoleTestWithStringFormatSpecifier() { +Deno.test(function consoleTestWithStringFormatSpecifier() { assertEquals(stringify("%s"), "%s"); assertEquals(stringify("%s", undefined), "undefined"); assertEquals(stringify("%s", "foo"), "foo"); @@ -971,7 +970,7 @@ unitTest(function consoleTestWithStringFormatSpecifier() { assertEquals(stringify("%s", Symbol("foo")), "Symbol(foo)"); }); -unitTest(function consoleTestWithObjectFormatSpecifier() { +Deno.test(function consoleTestWithObjectFormatSpecifier() { assertEquals(stringify("%o"), "%o"); assertEquals(stringify("%o", 42), "42"); assertEquals(stringify("%o", "foo"), `"foo"`); @@ -983,13 +982,13 @@ unitTest(function consoleTestWithObjectFormatSpecifier() { ); }); -unitTest(function consoleTestWithStyleSpecifier() { +Deno.test(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() { +Deno.test(function consoleParseCssColor() { assertEquals(parseCssColor("black"), [0, 0, 0]); assertEquals(parseCssColor("darkmagenta"), [139, 0, 139]); assertEquals(parseCssColor("slateblue"), [106, 90, 205]); @@ -1008,7 +1007,7 @@ unitTest(function consoleParseCssColor() { ); }); -unitTest(function consoleParseCss() { +Deno.test(function consoleParseCss() { assertEquals( parseCss("background-color: red"), { ...DEFAULT_CSS, backgroundColor: [255, 0, 0] }, @@ -1062,7 +1061,7 @@ unitTest(function consoleParseCss() { ); }); -unitTest(function consoleCssToAnsi() { +Deno.test(function consoleCssToAnsi() { assertEquals( cssToAnsiEsc({ ...DEFAULT_CSS, backgroundColor: [200, 201, 202] }), "_[48;2;200;201;202m", @@ -1102,7 +1101,7 @@ unitTest(function consoleCssToAnsi() { ); }); -unitTest(function consoleTestWithVariousOrInvalidFormatSpecifier() { +Deno.test(function consoleTestWithVariousOrInvalidFormatSpecifier() { assertEquals(stringify("%s:%s"), "%s:%s"); assertEquals(stringify("%i:%i"), "%i:%i"); assertEquals(stringify("%d:%d"), "%d:%d"); @@ -1118,7 +1117,7 @@ unitTest(function consoleTestWithVariousOrInvalidFormatSpecifier() { assertEquals(stringify("abc%", 1), "abc% 1"); }); -unitTest(function consoleTestCallToStringOnLabel() { +Deno.test(function consoleTestCallToStringOnLabel() { const methods = ["count", "countReset", "time", "timeLog", "timeEnd"]; mockConsole((console) => { for (const method of methods) { @@ -1133,7 +1132,7 @@ unitTest(function consoleTestCallToStringOnLabel() { }); }); -unitTest(function consoleTestError() { +Deno.test(function consoleTestError() { class MyError extends Error { constructor(errStr: string) { super(errStr); @@ -1151,7 +1150,7 @@ unitTest(function consoleTestError() { } }); -unitTest(function consoleTestClear() { +Deno.test(function consoleTestClear() { mockConsole((console, out) => { console.clear(); assertEquals(out.toString(), "\x1b[1;1H" + "\x1b[0J"); @@ -1159,7 +1158,7 @@ unitTest(function consoleTestClear() { }); // Test bound this issue -unitTest(function consoleDetachedLog() { +Deno.test(function consoleDetachedLog() { mockConsole((console) => { const log = console.log; const dir = console.dir; @@ -1232,7 +1231,7 @@ function mockConsole(f: ConsoleExamineFunc) { } // console.group test -unitTest(function consoleGroup() { +Deno.test(function consoleGroup() { mockConsole((console, out) => { console.group("1"); console.log("2"); @@ -1257,7 +1256,7 @@ unitTest(function consoleGroup() { }); // console.group with console.warn test -unitTest(function consoleGroupWarn() { +Deno.test(function consoleGroupWarn() { mockConsole((console, _out, _err, both) => { assert(both); console.warn("1"); @@ -1287,7 +1286,7 @@ unitTest(function consoleGroupWarn() { }); // console.table test -unitTest(function consoleTable() { +Deno.test(function consoleTable() { mockConsole((console, out) => { console.table({ a: "test", b: 1 }); assertEquals( @@ -1535,7 +1534,7 @@ unitTest(function consoleTable() { }); // console.log(Error) test -unitTest(function consoleLogShouldNotThrowError() { +Deno.test(function consoleLogShouldNotThrowError() { mockConsole((console) => { let result = 0; try { @@ -1555,7 +1554,7 @@ unitTest(function consoleLogShouldNotThrowError() { }); // console.log(Invalid Date) test -unitTest(function consoleLogShoultNotThrowErrorWhenInvalidDateIsPassed() { +Deno.test(function consoleLogShoultNotThrowErrorWhenInvalidDateIsPassed() { mockConsole((console, out) => { const invalidDate = new Date("test"); console.log(invalidDate); @@ -1564,7 +1563,7 @@ unitTest(function consoleLogShoultNotThrowErrorWhenInvalidDateIsPassed() { }); // console.dir test -unitTest(function consoleDir() { +Deno.test(function consoleDir() { mockConsole((console, out) => { console.dir("DIR"); assertEquals(out.toString(), "DIR\n"); @@ -1576,7 +1575,7 @@ unitTest(function consoleDir() { }); // console.dir test -unitTest(function consoleDirXml() { +Deno.test(function consoleDirXml() { mockConsole((console, out) => { console.dirxml("DIRXML"); assertEquals(out.toString(), "DIRXML\n"); @@ -1588,7 +1587,7 @@ unitTest(function consoleDirXml() { }); // console.trace test -unitTest(function consoleTrace() { +Deno.test(function consoleTrace() { mockConsole((console, _out, err) => { console.trace("%s", "custom message"); assert(err); @@ -1596,7 +1595,7 @@ unitTest(function consoleTrace() { }); }); -unitTest(function inspectString() { +Deno.test(function inspectString() { assertEquals( stripColor(Deno.inspect("\0")), `"\\x00"`, @@ -1607,7 +1606,7 @@ unitTest(function inspectString() { ); }); -unitTest(function inspectGetters() { +Deno.test(function inspectGetters() { assertEquals( stripColor(Deno.inspect({ get foo() { @@ -1636,12 +1635,12 @@ unitTest(function inspectGetters() { ); }); -unitTest(function inspectPrototype() { +Deno.test(function inspectPrototype() { class A {} assertEquals(Deno.inspect(A.prototype), "A {}"); }); -unitTest(function inspectSorted() { +Deno.test(function inspectSorted() { assertEquals( stripColor(Deno.inspect({ b: 2, a: 1 }, { sorted: true })), "{ a: 1, b: 2 }", @@ -1662,7 +1661,7 @@ unitTest(function inspectSorted() { ); }); -unitTest(function inspectTrailingComma() { +Deno.test(function inspectTrailingComma() { assertEquals( stripColor(Deno.inspect( [ @@ -1717,7 +1716,7 @@ unitTest(function inspectTrailingComma() { ); }); -unitTest(function inspectCompact() { +Deno.test(function inspectCompact() { assertEquals( stripColor(Deno.inspect({ a: 1, b: 2 }, { compact: false })), `{ @@ -1727,7 +1726,7 @@ unitTest(function inspectCompact() { ); }); -unitTest(function inspectIterableLimit() { +Deno.test(function inspectIterableLimit() { assertEquals( stripColor(Deno.inspect(["a", "b", "c"], { iterableLimit: 2 })), `[ "a", "b", ... 1 more items ]`, @@ -1749,7 +1748,7 @@ unitTest(function inspectIterableLimit() { ); }); -unitTest(function inspectProxy() { +Deno.test(function inspectProxy() { assertEquals( stripColor(Deno.inspect( new Proxy([1, 2, 3], {}), @@ -1823,7 +1822,7 @@ unitTest(function inspectProxy() { ); }); -unitTest(function inspectError() { +Deno.test(function inspectError() { const error1 = new Error("This is an error"); const error2 = new Error("This is an error", { cause: new Error("This is a cause error"), @@ -1843,7 +1842,7 @@ unitTest(function inspectError() { ); }); -unitTest(function inspectErrorCircular() { +Deno.test(function inspectErrorCircular() { const error1 = new Error("This is an error"); const error2 = new Error("This is an error", { cause: new Error("This is a cause error"), @@ -1865,7 +1864,7 @@ unitTest(function inspectErrorCircular() { ); }); -unitTest(function inspectColors() { +Deno.test(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 f232efba85..8751291a86 100644 --- a/cli/tests/unit/copy_file_test.ts +++ b/cli/tests/unit/copy_file_test.ts @@ -1,10 +1,5 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -import { - assertEquals, - assertRejects, - assertThrows, - unitTest, -} from "./test_util.ts"; +import { assertEquals, assertRejects, assertThrows } from "./test_util.ts"; function readFileString(filename: string | URL): string { const dataRead = Deno.readFileSync(filename); @@ -27,7 +22,7 @@ function assertSameContent( assertEquals(data1, data2); } -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function copyFileSyncSuccess() { const tempDir = Deno.makeTempDirSync(); @@ -44,7 +39,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function copyFileSyncByUrl() { const tempDir = Deno.makeTempDirSync(); @@ -65,7 +60,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { write: true, read: true } }, function copyFileSyncFailure() { const tempDir = Deno.makeTempDirSync(); @@ -84,7 +79,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { write: true, read: false } }, function copyFileSyncPerm1() { assertThrows(() => { @@ -93,7 +88,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { write: false, read: true } }, function copyFileSyncPerm2() { assertThrows(() => { @@ -102,7 +97,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function copyFileSyncOverwrite() { const tempDir = Deno.makeTempDirSync(); @@ -121,7 +116,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function copyFileSuccess() { const tempDir = Deno.makeTempDirSync(); @@ -138,7 +133,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function copyFileByUrl() { const tempDir = Deno.makeTempDirSync(); @@ -159,7 +154,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function copyFileFailure() { const tempDir = Deno.makeTempDirSync(); @@ -178,7 +173,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function copyFileOverwrite() { const tempDir = Deno.makeTempDirSync(); @@ -197,7 +192,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: false, write: true } }, async function copyFilePerm1() { await assertRejects(async () => { @@ -206,7 +201,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: false } }, async function copyFilePerm2() { await assertRejects(async () => { diff --git a/cli/tests/unit/custom_event_test.ts b/cli/tests/unit/custom_event_test.ts index 3b62429969..94d4a30de3 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"; +import { assertEquals } from "./test_util.ts"; -unitTest(function customEventInitializedWithDetail() { +Deno.test(function customEventInitializedWithDetail() { const type = "touchstart"; const detail = { message: "hello" }; const customEventInit = { @@ -20,7 +20,7 @@ unitTest(function customEventInitializedWithDetail() { assertEquals(event.type, type); }); -unitTest(function toStringShouldBeWebCompatibility() { +Deno.test(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 bcddb744a8..279b9133b7 100644 --- a/cli/tests/unit/dir_test.ts +++ b/cli/tests/unit/dir_test.ts @@ -1,11 +1,11 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals, assertThrows, unitTest } from "./test_util.ts"; +import { assert, assertEquals, assertThrows } from "./test_util.ts"; -unitTest({ permissions: { read: true } }, function dirCwdNotNull() { +Deno.test({ permissions: { read: true } }, function dirCwdNotNull() { assert(Deno.cwd() != null); }); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function dirCwdChdirSuccess() { const initialdir = Deno.cwd(); @@ -21,7 +21,7 @@ unitTest( }, ); -unitTest({ permissions: { read: true, write: true } }, function dirCwdError() { +Deno.test({ permissions: { 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({ permissions: { read: true, write: true } }, function dirCwdError() { } }); -unitTest({ permissions: { read: false } }, function dirCwdPermError() { +Deno.test({ permissions: { read: false } }, function dirCwdPermError() { assertThrows( () => { Deno.cwd(); @@ -48,7 +48,7 @@ unitTest({ permissions: { read: false } }, function dirCwdPermError() { ); }); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function dirChdirError() { const path = Deno.makeTempDirSync() + "test"; diff --git a/cli/tests/unit/dom_exception_test.ts b/cli/tests/unit/dom_exception_test.ts index b5f5b1f87e..01f7b5db52 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"; +import { assertEquals, assertStringIncludes } from "./test_util.ts"; -unitTest(function customInspectFunction() { +Deno.test(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 0da3ff9936..142fc3e536 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"; +import { assert, assertEquals, assertMatch } from "./test_util.ts"; -unitTest(function errorStackMessageLine() { +Deno.test(function errorStackMessageLine() { const e1 = new Error(); e1.name = "Foo"; e1.message = "bar"; @@ -41,7 +41,7 @@ unitTest(function errorStackMessageLine() { assertMatch(e6.stack!, /^null: null\n/); }); -unitTest(function captureStackTrace() { +Deno.test(function captureStackTrace() { function foo() { const error = new Error(); const stack1 = error.stack!; @@ -55,7 +55,7 @@ unitTest(function captureStackTrace() { // FIXME(bartlomieju): no longer works after migrating // to JavaScript runtime code -unitTest({ ignore: true }, function applySourceMap() { +Deno.test({ ignore: true }, function applySourceMap() { const result = Deno.applySourceMap({ fileName: "CLI_SNAPSHOT.js", lineNumber: 23, diff --git a/cli/tests/unit/esnext_test.ts b/cli/tests/unit/esnext_test.ts index 025a280030..cc5e89e805 100644 --- a/cli/tests/unit/esnext_test.ts +++ b/cli/tests/unit/esnext_test.ts @@ -1,10 +1,10 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals, unitTest } from "./test_util.ts"; +import { assert, assertEquals } from "./test_util.ts"; // TODO(@kitsonk) remove when we are no longer patching TypeScript to have // these types available. -unitTest(function typeCheckingEsNextArrayString() { +Deno.test(function typeCheckingEsNextArrayString() { const a = "abcdef"; assertEquals(a.at(-1), "f"); const b = ["a", "b", "c", "d", "e", "f"]; @@ -13,13 +13,13 @@ unitTest(function typeCheckingEsNextArrayString() { assertEquals(b.findLastIndex((val) => typeof val === "string"), 5); }); -unitTest(function objectHasOwn() { +Deno.test(function objectHasOwn() { const a = { a: 1 }; assert(Object.hasOwn(a, "a")); assert(!Object.hasOwn(a, "b")); }); -unitTest(function errorCause() { +Deno.test(function errorCause() { const e = new Error("test", { cause: "something" }); assertEquals(e.cause, "something"); }); diff --git a/cli/tests/unit/event_target_test.ts b/cli/tests/unit/event_target_test.ts index a6c942773e..ef2868e94f 100644 --- a/cli/tests/unit/event_target_test.ts +++ b/cli/tests/unit/event_target_test.ts @@ -1,8 +1,8 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // deno-lint-ignore-file no-window-prefix -import { assertEquals, unitTest } from "./test_util.ts"; +import { assertEquals } from "./test_util.ts"; -unitTest(function addEventListenerTest() { +Deno.test(function addEventListenerTest() { const document = new EventTarget(); assertEquals(document.addEventListener("x", null, false), undefined); @@ -10,7 +10,7 @@ unitTest(function addEventListenerTest() { assertEquals(document.addEventListener("x", null), undefined); }); -unitTest(function constructedEventTargetCanBeUsedAsExpected() { +Deno.test(function constructedEventTargetCanBeUsedAsExpected() { const target = new EventTarget(); const event = new Event("foo", { bubbles: true, cancelable: false }); let callCount = 0; @@ -33,7 +33,7 @@ unitTest(function constructedEventTargetCanBeUsedAsExpected() { assertEquals(callCount, 2); }); -unitTest(function anEventTargetCanBeSubclassed() { +Deno.test(function anEventTargetCanBeSubclassed() { class NicerEventTarget extends EventTarget { on( type: string, @@ -67,14 +67,14 @@ unitTest(function anEventTargetCanBeSubclassed() { assertEquals(callCount, 0); }); -unitTest(function removingNullEventListenerShouldSucceed() { +Deno.test(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() { +Deno.test(function constructedEventTargetUseObjectPrototype() { const target = new EventTarget(); const event = new Event("toString", { bubbles: true, cancelable: false }); let callCount = 0; @@ -97,12 +97,12 @@ unitTest(function constructedEventTargetUseObjectPrototype() { assertEquals(callCount, 2); }); -unitTest(function toStringShouldBeWebCompatible() { +Deno.test(function toStringShouldBeWebCompatible() { const target = new EventTarget(); assertEquals(target.toString(), "[object EventTarget]"); }); -unitTest(function dispatchEventShouldNotThrowError() { +Deno.test(function dispatchEventShouldNotThrowError() { let hasThrown = false; try { @@ -121,7 +121,7 @@ unitTest(function dispatchEventShouldNotThrowError() { assertEquals(hasThrown, false); }); -unitTest(function eventTargetThisShouldDefaultToWindow() { +Deno.test(function eventTargetThisShouldDefaultToWindow() { const { addEventListener, dispatchEvent, @@ -150,7 +150,7 @@ unitTest(function eventTargetThisShouldDefaultToWindow() { assertEquals(n, 1); }); -unitTest(function eventTargetShouldAcceptEventListenerObject() { +Deno.test(function eventTargetShouldAcceptEventListenerObject() { const target = new EventTarget(); const event = new Event("foo", { bubbles: true, cancelable: false }); let callCount = 0; @@ -175,7 +175,7 @@ unitTest(function eventTargetShouldAcceptEventListenerObject() { assertEquals(callCount, 2); }); -unitTest(function eventTargetShouldAcceptAsyncFunction() { +Deno.test(function eventTargetShouldAcceptAsyncFunction() { const target = new EventTarget(); const event = new Event("foo", { bubbles: true, cancelable: false }); let callCount = 0; @@ -198,7 +198,7 @@ unitTest(function eventTargetShouldAcceptAsyncFunction() { assertEquals(callCount, 2); }); -unitTest( +Deno.test( function eventTargetShouldAcceptAsyncFunctionForEventListenerObject() { const target = new EventTarget(); const event = new Event("foo", { bubbles: true, cancelable: false }); @@ -224,7 +224,7 @@ unitTest( assertEquals(callCount, 2); }, ); -unitTest(function eventTargetDispatchShouldSetTargetNoListener() { +Deno.test(function eventTargetDispatchShouldSetTargetNoListener() { const target = new EventTarget(); const event = new Event("foo"); assertEquals(event.target, null); @@ -232,7 +232,7 @@ unitTest(function eventTargetDispatchShouldSetTargetNoListener() { assertEquals(event.target, target); }); -unitTest(function eventTargetDispatchShouldSetTargetInListener() { +Deno.test(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 13f2590ced..e5a58c7a64 100644 --- a/cli/tests/unit/event_test.ts +++ b/cli/tests/unit/event_test.ts @@ -1,12 +1,7 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -import { - assert, - assertEquals, - assertStringIncludes, - unitTest, -} from "./test_util.ts"; +import { assert, assertEquals, assertStringIncludes } from "./test_util.ts"; -unitTest(function eventInitializedWithType() { +Deno.test(function eventInitializedWithType() { const type = "click"; const event = new Event(type); @@ -18,7 +13,7 @@ unitTest(function eventInitializedWithType() { assertEquals(event.cancelable, false); }); -unitTest(function eventInitializedWithTypeAndDict() { +Deno.test(function eventInitializedWithTypeAndDict() { const init = "submit"; const eventInit = { bubbles: true, cancelable: true } as EventInit; const event = new Event(init, eventInit); @@ -31,7 +26,7 @@ unitTest(function eventInitializedWithTypeAndDict() { assertEquals(event.cancelable, true); }); -unitTest(function eventComposedPathSuccess() { +Deno.test(function eventComposedPathSuccess() { const type = "click"; const event = new Event(type); const composedPath = event.composedPath(); @@ -39,7 +34,7 @@ unitTest(function eventComposedPathSuccess() { assertEquals(composedPath, []); }); -unitTest(function eventStopPropagationSuccess() { +Deno.test(function eventStopPropagationSuccess() { const type = "click"; const event = new Event(type); @@ -48,7 +43,7 @@ unitTest(function eventStopPropagationSuccess() { assertEquals(event.cancelBubble, true); }); -unitTest(function eventStopImmediatePropagationSuccess() { +Deno.test(function eventStopImmediatePropagationSuccess() { const type = "click"; const event = new Event(type); @@ -57,7 +52,7 @@ unitTest(function eventStopImmediatePropagationSuccess() { assertEquals(event.cancelBubble, true); }); -unitTest(function eventPreventDefaultSuccess() { +Deno.test(function eventPreventDefaultSuccess() { const type = "click"; const event = new Event(type); @@ -72,7 +67,7 @@ unitTest(function eventPreventDefaultSuccess() { assertEquals(cancelableEvent.defaultPrevented, true); }); -unitTest(function eventInitializedWithNonStringType() { +Deno.test(function eventInitializedWithNonStringType() { // deno-lint-ignore no-explicit-any const type: any = undefined; const event = new Event(type); @@ -86,7 +81,7 @@ unitTest(function eventInitializedWithNonStringType() { }); // ref https://github.com/web-platform-tests/wpt/blob/master/dom/events/Event-isTrusted.any.js -unitTest(function eventIsTrusted() { +Deno.test(function eventIsTrusted() { const desc1 = Object.getOwnPropertyDescriptor(new Event("x"), "isTrusted"); assert(desc1); assertEquals(typeof desc1.get, "function"); @@ -98,7 +93,7 @@ unitTest(function eventIsTrusted() { assertEquals(desc1!.get, desc2!.get); }); -unitTest(function eventInspectOutput() { +Deno.test(function eventInspectOutput() { // deno-lint-ignore no-explicit-any const cases: Array<[any, (event: any) => string]> = [ [ @@ -133,7 +128,7 @@ unitTest(function eventInspectOutput() { } }); -unitTest(function inspectEvent() { +Deno.test(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 8fe8db17e7..c22fc5226c 100644 --- a/cli/tests/unit/fetch_test.ts +++ b/cli/tests/unit/fetch_test.ts @@ -6,11 +6,10 @@ import { deferred, fail, unimplemented, - unitTest, } from "./test_util.ts"; import { Buffer } from "../../../test_util/std/io/buffer.ts"; -unitTest( +Deno.test( { permissions: { net: true } }, async function fetchRequiresOneArgument() { await assertRejects( @@ -20,7 +19,7 @@ unitTest( }, ); -unitTest({ permissions: { net: true } }, async function fetchProtocolError() { +Deno.test({ permissions: { net: true } }, async function fetchProtocolError() { await assertRejects( async () => { await fetch("ftp://localhost:21/a/file"); @@ -54,7 +53,7 @@ function findClosedPortInRange( ); } -unitTest( +Deno.test( { permissions: { net: true } }, async function fetchConnectionError() { const port = findClosedPortInRange(4000, 9999); @@ -68,7 +67,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function fetchDnsError() { await assertRejects( @@ -81,7 +80,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function fetchInvalidUriError() { await assertRejects( @@ -93,25 +92,25 @@ unitTest( }, ); -unitTest({ permissions: { net: true } }, async function fetchJsonSuccess() { +Deno.test({ permissions: { net: true } }, async function fetchJsonSuccess() { const response = await fetch("http://localhost:4545/fixture.json"); const json = await response.json(); assertEquals(json.name, "deno"); }); -unitTest(async function fetchPerm() { +Deno.test({ permissions: { net: false } }, async function fetchPerm() { await assertRejects(async () => { await fetch("http://localhost:4545/fixture.json"); }, Deno.errors.PermissionDenied); }); -unitTest({ permissions: { net: true } }, async function fetchUrl() { +Deno.test({ permissions: { net: true } }, async function fetchUrl() { const response = await fetch("http://localhost:4545/fixture.json"); assertEquals(response.url, "http://localhost:4545/fixture.json"); const _json = await response.json(); }); -unitTest({ permissions: { net: true } }, async function fetchURL() { +Deno.test({ permissions: { net: true } }, async function fetchURL() { const response = await fetch( new URL("http://localhost:4545/fixture.json"), ); @@ -119,14 +118,14 @@ unitTest({ permissions: { net: true } }, async function fetchURL() { const _json = await response.json(); }); -unitTest({ permissions: { net: true } }, async function fetchHeaders() { +Deno.test({ permissions: { net: true } }, async function fetchHeaders() { const response = await fetch("http://localhost:4545/fixture.json"); const headers = response.headers; assertEquals(headers.get("Content-Type"), "application/json"); const _json = await response.json(); }); -unitTest({ permissions: { net: true } }, async function fetchBlob() { +Deno.test({ permissions: { net: true } }, async function fetchBlob() { const response = await fetch("http://localhost:4545/fixture.json"); const headers = response.headers; const blob = await response.blob(); @@ -134,7 +133,7 @@ unitTest({ permissions: { net: true } }, async function fetchBlob() { assertEquals(blob.size, Number(headers.get("Content-Length"))); }); -unitTest( +Deno.test( { permissions: { net: true } }, async function fetchBodyUsedReader() { const response = await fetch( @@ -152,7 +151,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function fetchBodyUsedCancelStream() { const response = await fetch( @@ -167,7 +166,7 @@ unitTest( }, ); -unitTest({ permissions: { net: true } }, async function fetchAsyncIterator() { +Deno.test({ permissions: { net: true } }, async function fetchAsyncIterator() { const response = await fetch("http://localhost:4545/fixture.json"); const headers = response.headers; @@ -181,7 +180,7 @@ unitTest({ permissions: { net: true } }, async function fetchAsyncIterator() { assertEquals(total, Number(headers.get("Content-Length"))); }); -unitTest({ permissions: { net: true } }, async function fetchBodyReader() { +Deno.test({ permissions: { net: true } }, async function fetchBodyReader() { const response = await fetch("http://localhost:4545/fixture.json"); const headers = response.headers; assert(response.body !== null); @@ -198,7 +197,7 @@ unitTest({ permissions: { net: true } }, async function fetchBodyReader() { assertEquals(total, Number(headers.get("Content-Length"))); }); -unitTest( +Deno.test( { permissions: { net: true } }, async function fetchBodyReaderBigBody() { const data = "a".repeat(10 << 10); // 10mb @@ -220,7 +219,7 @@ unitTest( }, ); -unitTest({ permissions: { net: true } }, async function responseClone() { +Deno.test({ permissions: { net: true } }, async function responseClone() { const response = await fetch("http://localhost:4545/fixture.json"); const response1 = response.clone(); assert(response !== response1); @@ -233,7 +232,7 @@ unitTest({ permissions: { net: true } }, async function responseClone() { } }); -unitTest( +Deno.test( { permissions: { net: true } }, async function fetchMultipartFormDataSuccess() { const response = await fetch( @@ -250,7 +249,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function fetchMultipartFormBadContentType() { const response = await fetch( @@ -268,7 +267,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function fetchURLEncodedFormDataSuccess() { const response = await fetch( @@ -282,7 +281,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function fetchInitFormDataBinaryFileBody() { // Some random bytes @@ -301,7 +300,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function fetchInitFormDataMultipleFilesBody() { const files = [ @@ -355,7 +354,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true }, }, @@ -369,7 +368,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true }, }, @@ -384,7 +383,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true }, }, @@ -405,7 +404,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true }, }, @@ -418,7 +417,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function fetchInitStringBody() { const data = "Hello World"; @@ -432,7 +431,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function fetchRequestInitStringBody() { const data = "Hello World"; @@ -446,7 +445,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function fetchSeparateInit() { // related to: https://github.com/denoland/deno/issues/10396 @@ -461,7 +460,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function fetchInitTypedArrayBody() { const data = "Hello World"; @@ -474,7 +473,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function fetchInitArrayBufferBody() { const data = "Hello World"; @@ -487,7 +486,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function fetchInitURLSearchParamsBody() { const data = "param1=value1¶m2=value2"; @@ -506,7 +505,7 @@ unitTest( }, ); -unitTest({ permissions: { net: true } }, async function fetchInitBlobBody() { +Deno.test({ permissions: { net: true } }, async function fetchInitBlobBody() { const data = "const a = 1"; const blob = new Blob([data], { type: "text/javascript", @@ -520,7 +519,7 @@ unitTest({ permissions: { net: true } }, async function fetchInitBlobBody() { assert(response.headers.get("content-type")!.startsWith("text/javascript")); }); -unitTest( +Deno.test( { permissions: { net: true } }, async function fetchInitFormDataBody() { const form = new FormData(); @@ -534,7 +533,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function fetchInitFormDataBlobFilenameBody() { const form = new FormData(); @@ -552,7 +551,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function fetchInitFormDataTextFileBody() { const fileContent = "deno land"; @@ -582,7 +581,7 @@ unitTest( }, ); -unitTest({ permissions: { net: true } }, async function fetchUserAgent() { +Deno.test({ permissions: { net: true } }, async function fetchUserAgent() { const data = "Hello World"; const response = await fetch("http://localhost:4545/echo_server", { method: "POST", @@ -619,7 +618,7 @@ function bufferServer(addr: string): Promise { }); } -unitTest( +Deno.test( { permissions: { net: true }, }, @@ -652,7 +651,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true }, }, @@ -689,7 +688,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true }, }, @@ -726,7 +725,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true }, }, @@ -740,7 +739,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true }, }, @@ -756,7 +755,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true }, }, @@ -772,7 +771,7 @@ unitTest( }, ); -unitTest(function responseRedirect() { +Deno.test(function responseRedirect() { const redir = Response.redirect("example.com/newLocation", 301); assertEquals(redir.status, 301); assertEquals(redir.statusText, ""); @@ -784,7 +783,7 @@ unitTest(function responseRedirect() { assertEquals(redir.type, "default"); }); -unitTest(async function responseWithoutBody() { +Deno.test(async function responseWithoutBody() { const response = new Response(); assertEquals(await response.arrayBuffer(), new ArrayBuffer(0)); const blob = await response.blob(); @@ -796,7 +795,7 @@ unitTest(async function responseWithoutBody() { }); }); -unitTest({ permissions: { net: true } }, async function fetchBodyReadTwice() { +Deno.test({ permissions: { net: true } }, async function fetchBodyReadTwice() { const response = await fetch("http://localhost:4545/fixture.json"); // Read body @@ -817,7 +816,7 @@ unitTest({ permissions: { net: true } }, async function fetchBodyReadTwice() { } }); -unitTest( +Deno.test( { permissions: { net: true } }, async function fetchBodyReaderAfterRead() { const response = await fetch( @@ -840,7 +839,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function fetchBodyReaderWithCancelAndNewReader() { const data = "a".repeat(1 << 10); @@ -868,7 +867,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function fetchBodyReaderWithReadCancelAndNewReader() { const data = "a".repeat(1 << 10); @@ -898,7 +897,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function fetchResourceCloseAfterStreamCancel() { const res = await fetch("http://localhost:4545/fixture.json"); @@ -916,7 +915,7 @@ unitTest( // TypeError: error sending request for url (http://localhost:4545/echo_server): // connection error: An established connection was aborted by // the software in your host machine. (os error 10053) -unitTest( +Deno.test( { permissions: { net: true }, ignore: Deno.build.os == "windows" }, async function fetchNullBodyStatus() { const nullBodyStatus = [101, 204, 205, 304]; @@ -934,7 +933,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function fetchResponseContentLength() { const body = new Uint8Array(2 ** 16); @@ -953,7 +952,7 @@ unitTest( }, ); -unitTest(function fetchResponseConstructorNullBody() { +Deno.test(function fetchResponseConstructorNullBody() { const nullBodyStatus = [204, 205, 304]; for (const status of nullBodyStatus) { @@ -970,7 +969,7 @@ unitTest(function fetchResponseConstructorNullBody() { } }); -unitTest(function fetchResponseConstructorInvalidStatus() { +Deno.test(function fetchResponseConstructorInvalidStatus() { const invalidStatus = [101, 600, 199, null, "", NaN]; for (const status of invalidStatus) { @@ -986,7 +985,7 @@ unitTest(function fetchResponseConstructorInvalidStatus() { } }); -unitTest(function fetchResponseEmptyConstructor() { +Deno.test(function fetchResponseEmptyConstructor() { const response = new Response(); assertEquals(response.status, 200); assertEquals(response.body, null); @@ -998,7 +997,7 @@ unitTest(function fetchResponseEmptyConstructor() { assertEquals([...response.headers], []); }); -unitTest( +Deno.test( { permissions: { net: true, read: true } }, async function fetchCustomHttpClientParamCertificateSuccess(): Promise< void @@ -1014,7 +1013,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function fetchCustomClientUserAgent(): Promise< void @@ -1035,7 +1034,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true }, }, @@ -1083,7 +1082,7 @@ unitTest( }, ); -unitTest({}, function fetchWritableRespProps() { +Deno.test({}, function fetchWritableRespProps() { const original = new Response("https://deno.land", { status: 404, headers: { "x-deno": "foo" }, @@ -1122,7 +1121,7 @@ function returnHostHeaderServer(addr: string): Deno.Listener { return listener; } -unitTest( +Deno.test( { permissions: { net: true } }, async function fetchFilterOutCustomHostHeader(): Promise< void @@ -1139,7 +1138,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function fetchNoServerReadableStreamBody() { const done = deferred(); @@ -1160,7 +1159,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function fetchHeadRespBody() { const res = await fetch("http://localhost:4545/echo_server", { @@ -1170,7 +1169,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, net: true } }, async function fetchClientCertWrongPrivateKey(): Promise { await assertRejects(async () => { @@ -1187,7 +1186,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, net: true } }, async function fetchClientCertBadPrivateKey(): Promise { await assertRejects(async () => { @@ -1204,7 +1203,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, net: true } }, async function fetchClientCertNotPrivateKey(): Promise { await assertRejects(async () => { @@ -1221,7 +1220,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, net: true } }, async function fetchCustomClientPrivateKey(): Promise< void @@ -1251,7 +1250,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function fetchAbortWhileUploadStreaming(): Promise { const abortController = new AbortController(); @@ -1278,7 +1277,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function fetchHeaderValueShouldNotPanic() { for (let i = 0; i < 0x21; i++) { @@ -1300,7 +1299,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function fetchHeaderNameShouldNotPanic() { const validTokens = @@ -1326,7 +1325,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true, read: true } }, async function fetchSupportsHttp1Only() { const caCert = await Deno.readTextFile("cli/tests/testdata/tls/RootCA.pem"); @@ -1338,7 +1337,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true, read: true } }, async function fetchSupportsHttp2() { const caCert = await Deno.readTextFile("cli/tests/testdata/tls/RootCA.pem"); @@ -1350,7 +1349,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true, read: true } }, async function fetchPrefersHttp2() { const caCert = await Deno.readTextFile("cli/tests/testdata/tls/RootCA.pem"); @@ -1362,19 +1361,22 @@ unitTest( }, ); -unitTest(async function fetchFilePerm() { +Deno.test({ permissions: { read: false } }, async function fetchFilePerm() { await assertRejects(async () => { await fetch(new URL("../testdata/subdir/json_1.json", import.meta.url)); }, Deno.errors.PermissionDenied); }); -unitTest(async function fetchFilePermDoesNotExist() { - await assertRejects(async () => { - await fetch(new URL("./bad.json", import.meta.url)); - }, Deno.errors.PermissionDenied); -}); +Deno.test( + { permissions: { read: false } }, + async function fetchFilePermDoesNotExist() { + await assertRejects(async () => { + await fetch(new URL("./bad.json", import.meta.url)); + }, Deno.errors.PermissionDenied); + }, +); -unitTest( +Deno.test( { permissions: { read: true } }, async function fetchFileBadMethod() { await assertRejects( @@ -1392,7 +1394,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true } }, async function fetchFileDoesNotExist() { await assertRejects( @@ -1404,7 +1406,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true } }, async function fetchFile() { const res = await fetch( @@ -1418,7 +1420,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function fetchContentLengthPost() { const response = await fetch("http://localhost:4545/content_length", { @@ -1429,7 +1431,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function fetchContentLengthPut() { const response = await fetch("http://localhost:4545/content_length", { @@ -1440,7 +1442,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function fetchContentLengthPatch() { const response = await fetch("http://localhost:4545/content_length", { @@ -1451,7 +1453,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function fetchContentLengthPostWithStringBody() { const response = await fetch("http://localhost:4545/content_length", { @@ -1463,7 +1465,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function fetchContentLengthPostWithBufferBody() { const response = await fetch("http://localhost:4545/content_length", { diff --git a/cli/tests/unit/ffi_test.ts b/cli/tests/unit/ffi_test.ts index 497435ab94..fe1ab202f3 100644 --- a/cli/tests/unit/ffi_test.ts +++ b/cli/tests/unit/ffi_test.ts @@ -1,8 +1,8 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -import { assertThrows, unitTest } from "./test_util.ts"; +import { assertThrows } from "./test_util.ts"; -unitTest({ permissions: { ffi: true } }, function dlopenInvalidArguments() { +Deno.test({ permissions: { ffi: true } }, function dlopenInvalidArguments() { const filename = "/usr/lib/libc.so.6"; assertThrows(() => { // @ts-expect-error: ForeignFunction cannot be null diff --git a/cli/tests/unit/file_test.ts b/cli/tests/unit/file_test.ts index c2346becd0..6a2c5d4617 100644 --- a/cli/tests/unit/file_test.ts +++ b/cli/tests/unit/file_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals, unitTest } from "./test_util.ts"; +import { assert, assertEquals } from "./test_util.ts"; // deno-lint-ignore no-explicit-any function testFirstArgument(arg1: any[], expectedSize: number) { @@ -10,47 +10,47 @@ function testFirstArgument(arg1: any[], expectedSize: number) { assertEquals(file.type, ""); } -unitTest(function fileEmptyFileBits() { +Deno.test(function fileEmptyFileBits() { testFirstArgument([], 0); }); -unitTest(function fileStringFileBits() { +Deno.test(function fileStringFileBits() { testFirstArgument(["bits"], 4); }); -unitTest(function fileUnicodeStringFileBits() { +Deno.test(function fileUnicodeStringFileBits() { testFirstArgument(["𝓽𝓮𝔁𝓽"], 16); }); -unitTest(function fileStringObjectFileBits() { +Deno.test(function fileStringObjectFileBits() { testFirstArgument([new String("string object")], 13); }); -unitTest(function fileEmptyBlobFileBits() { +Deno.test(function fileEmptyBlobFileBits() { testFirstArgument([new Blob()], 0); }); -unitTest(function fileBlobFileBits() { +Deno.test(function fileBlobFileBits() { testFirstArgument([new Blob(["bits"])], 4); }); -unitTest(function fileEmptyFileFileBits() { +Deno.test(function fileEmptyFileFileBits() { testFirstArgument([new File([], "world.txt")], 0); }); -unitTest(function fileFileFileBits() { +Deno.test(function fileFileFileBits() { testFirstArgument([new File(["bits"], "world.txt")], 4); }); -unitTest(function fileArrayBufferFileBits() { +Deno.test(function fileArrayBufferFileBits() { testFirstArgument([new ArrayBuffer(8)], 8); }); -unitTest(function fileTypedArrayFileBits() { +Deno.test(function fileTypedArrayFileBits() { testFirstArgument([new Uint8Array([0x50, 0x41, 0x53, 0x53])], 4); }); -unitTest(function fileVariousFileBits() { +Deno.test(function fileVariousFileBits() { testFirstArgument( [ "bits", @@ -64,15 +64,15 @@ unitTest(function fileVariousFileBits() { ); }); -unitTest(function fileNumberInFileBits() { +Deno.test(function fileNumberInFileBits() { testFirstArgument([12], 2); }); -unitTest(function fileArrayInFileBits() { +Deno.test(function fileArrayInFileBits() { testFirstArgument([[1, 2, 3]], 5); }); -unitTest(function fileObjectInFileBits() { +Deno.test(function fileObjectInFileBits() { // "[object Object]" testFirstArgument([{}], 15); }); @@ -84,23 +84,23 @@ function testSecondArgument(arg2: any, expectedFileName: string) { assertEquals(file.name, expectedFileName); } -unitTest(function fileUsingFileName() { +Deno.test(function fileUsingFileName() { testSecondArgument("dummy", "dummy"); }); -unitTest(function fileUsingNullFileName() { +Deno.test(function fileUsingNullFileName() { testSecondArgument(null, "null"); }); -unitTest(function fileUsingNumberFileName() { +Deno.test(function fileUsingNumberFileName() { testSecondArgument(1, "1"); }); -unitTest(function fileUsingEmptyStringFileName() { +Deno.test(function fileUsingEmptyStringFileName() { testSecondArgument("", ""); }); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function fileTruncateSyncSuccess() { const filename = Deno.makeTempDirSync() + "/test_fileTruncateSync.txt"; @@ -122,7 +122,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function fileTruncateSuccess() { const filename = Deno.makeTempDirSync() + "/test_fileTruncate.txt"; @@ -144,7 +144,7 @@ unitTest( }, ); -unitTest({ permissions: { read: true } }, function fileStatSyncSuccess() { +Deno.test({ permissions: { read: true } }, function fileStatSyncSuccess() { const file = Deno.openSync("README.md"); const fileInfo = file.statSync(); assert(fileInfo.isFile); @@ -159,7 +159,7 @@ unitTest({ permissions: { read: true } }, function fileStatSyncSuccess() { file.close(); }); -unitTest({ permissions: { read: true } }, async function fileStatSuccess() { +Deno.test({ permissions: { 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 bc9beab70c..3d49b20b5a 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"; +import { assertEquals } from "./test_util.ts"; -unitTest(function fileReaderConstruct() { +Deno.test(function fileReaderConstruct() { const fr = new FileReader(); assertEquals(fr.readyState, FileReader.EMPTY); @@ -10,7 +10,7 @@ unitTest(function fileReaderConstruct() { assertEquals(FileReader.DONE, 2); }); -unitTest(async function fileReaderLoadBlob() { +Deno.test(async function fileReaderLoadBlob() { await new Promise((resolve) => { const fr = new FileReader(); const b1 = new Blob(["Hello World"]); @@ -77,7 +77,7 @@ unitTest(async function fileReaderLoadBlob() { }); }); -unitTest(async function fileReaderLoadBlobDouble() { +Deno.test(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 @@ -107,7 +107,7 @@ unitTest(async function fileReaderLoadBlobDouble() { }); }); -unitTest(async function fileReaderLoadBlobArrayBuffer() { +Deno.test(async function fileReaderLoadBlobArrayBuffer() { await new Promise((resolve) => { const fr = new FileReader(); const b1 = new Blob(["Hello World"]); @@ -129,7 +129,7 @@ unitTest(async function fileReaderLoadBlobArrayBuffer() { }); }); -unitTest(async function fileReaderLoadBlobDataUrl() { +Deno.test(async function fileReaderLoadBlobDataUrl() { await new Promise((resolve) => { const fr = new FileReader(); const b1 = new Blob(["Hello World"]); @@ -149,7 +149,7 @@ unitTest(async function fileReaderLoadBlobDataUrl() { }); }); -unitTest(async function fileReaderLoadBlobAbort() { +Deno.test(async function fileReaderLoadBlobAbort() { await new Promise((resolve) => { const fr = new FileReader(); const b1 = new Blob(["Hello World"]); @@ -184,7 +184,7 @@ unitTest(async function fileReaderLoadBlobAbort() { }); }); -unitTest(async function fileReaderLoadBlobAbort() { +Deno.test(async function fileReaderLoadBlobAbort() { await new Promise((resolve) => { const fr = new FileReader(); const b1 = new Blob(["Hello World"]); @@ -219,7 +219,7 @@ unitTest(async function fileReaderLoadBlobAbort() { }); }); -unitTest( +Deno.test( async function fileReaderDispatchesEventsInCorrectOrder() { await new Promise((resolve) => { const fr = new FileReader(); diff --git a/cli/tests/unit/files_test.ts b/cli/tests/unit/files_test.ts index 9f5812d325..9e9c320b28 100644 --- a/cli/tests/unit/files_test.ts +++ b/cli/tests/unit/files_test.ts @@ -7,17 +7,16 @@ import { assertEquals, assertRejects, assertThrows, - unitTest, } from "./test_util.ts"; import { copy } from "../../../test_util/std/io/util.ts"; -unitTest(function filesStdioFileDescriptors() { +Deno.test(function filesStdioFileDescriptors() { assertEquals(Deno.stdin.rid, 0); assertEquals(Deno.stdout.rid, 1); assertEquals(Deno.stderr.rid, 2); }); -unitTest({ permissions: { read: true } }, async function filesCopyToStdout() { +Deno.test({ permissions: { read: true } }, async function filesCopyToStdout() { const filename = "cli/tests/testdata/fixture.json"; const file = await Deno.open(filename); assert(file.rid > 2); @@ -27,7 +26,7 @@ unitTest({ permissions: { read: true } }, async function filesCopyToStdout() { file.close(); }); -unitTest({ permissions: { read: true } }, async function filesIter() { +Deno.test({ permissions: { read: true } }, async function filesIter() { const filename = "cli/tests/testdata/hello.txt"; const file = await Deno.open(filename); @@ -40,7 +39,7 @@ unitTest({ permissions: { read: true } }, async function filesIter() { file.close(); }); -unitTest( +Deno.test( { permissions: { read: true } }, async function filesIterCustomBufSize() { const filename = "cli/tests/testdata/hello.txt"; @@ -59,7 +58,7 @@ unitTest( }, ); -unitTest({ permissions: { read: true } }, function filesIterSync() { +Deno.test({ permissions: { read: true } }, function filesIterSync() { const filename = "cli/tests/testdata/hello.txt"; const file = Deno.openSync(filename); @@ -72,7 +71,7 @@ unitTest({ permissions: { read: true } }, function filesIterSync() { file.close(); }); -unitTest( +Deno.test( { permissions: { read: true } }, function filesIterSyncCustomBufSize() { const filename = "cli/tests/testdata/hello.txt"; @@ -91,7 +90,7 @@ unitTest( }, ); -unitTest(async function readerIter() { +Deno.test(async function readerIter() { // ref: https://github.com/denoland/deno/issues/2330 const encoder = new TextEncoder(); @@ -126,7 +125,7 @@ unitTest(async function readerIter() { assertEquals(totalSize, 12); }); -unitTest(async function readerIterSync() { +Deno.test(async function readerIterSync() { // ref: https://github.com/denoland/deno/issues/2330 const encoder = new TextEncoder(); @@ -161,7 +160,7 @@ unitTest(async function readerIterSync() { assertEquals(totalSize, 12); }); -unitTest( +Deno.test( { permissions: { read: true, write: true }, }, @@ -180,7 +179,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true }, }, @@ -199,7 +198,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true }, }, @@ -225,7 +224,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true }, }, @@ -251,7 +250,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { write: false } }, async function writePermFailure() { const filename = "tests/hello.txt"; @@ -264,7 +263,7 @@ unitTest( }, ); -unitTest(async function openOptions() { +Deno.test(async function openOptions() { const filename = "cli/tests/testdata/fixture.json"; await assertRejects( async () => { @@ -299,13 +298,13 @@ unitTest(async function openOptions() { ); }); -unitTest({ permissions: { read: false } }, async function readPermFailure() { +Deno.test({ permissions: { read: false } }, async function readPermFailure() { await assertRejects(async () => { await Deno.open("package.json", { read: true }); }, Deno.errors.PermissionDenied); }); -unitTest( +Deno.test( { permissions: { write: true } }, async function writeNullBufferFailure() { const tempDir = Deno.makeTempDirSync(); @@ -329,7 +328,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { write: true, read: true } }, async function readNullBufferFailure() { const tempDir = Deno.makeTempDirSync(); @@ -357,7 +356,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { write: false, read: false } }, async function readWritePermFailure() { const filename = "tests/hello.txt"; @@ -367,7 +366,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { write: true, read: true } }, async function openNotFound() { await assertRejects( @@ -380,7 +379,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { write: true, read: true } }, function openSyncNotFound() { assertThrows( @@ -393,7 +392,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function createFile() { const tempDir = await Deno.makeTempDir(); @@ -414,7 +413,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function createFileWithUrl() { const tempDir = await Deno.makeTempDir(); @@ -436,7 +435,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function createSyncFile() { const tempDir = await Deno.makeTempDir(); @@ -457,7 +456,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function createSyncFileWithUrl() { const tempDir = await Deno.makeTempDir(); @@ -479,7 +478,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function openModeWrite() { const tempDir = Deno.makeTempDirSync(); @@ -522,7 +521,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function openModeWriteRead() { const tempDir = Deno.makeTempDirSync(); @@ -558,7 +557,7 @@ unitTest( }, ); -unitTest({ permissions: { read: true } }, async function seekStart() { +Deno.test({ permissions: { read: true } }, async function seekStart() { const filename = "cli/tests/testdata/hello.txt"; const file = await Deno.open(filename); const seekPosition = 6; @@ -575,7 +574,7 @@ unitTest({ permissions: { read: true } }, async function seekStart() { file.close(); }); -unitTest({ permissions: { read: true } }, function seekSyncStart() { +Deno.test({ permissions: { read: true } }, function seekSyncStart() { const filename = "cli/tests/testdata/hello.txt"; const file = Deno.openSync(filename); const seekPosition = 6; @@ -592,7 +591,7 @@ unitTest({ permissions: { read: true } }, function seekSyncStart() { file.close(); }); -unitTest({ permissions: { read: true } }, async function seekCurrent() { +Deno.test({ permissions: { read: true } }, async function seekCurrent() { const filename = "cli/tests/testdata/hello.txt"; const file = await Deno.open(filename); // Deliberately move 1 step forward @@ -609,7 +608,7 @@ unitTest({ permissions: { read: true } }, async function seekCurrent() { file.close(); }); -unitTest({ permissions: { read: true } }, function seekSyncCurrent() { +Deno.test({ permissions: { read: true } }, function seekSyncCurrent() { const filename = "cli/tests/testdata/hello.txt"; const file = Deno.openSync(filename); // Deliberately move 1 step forward @@ -626,7 +625,7 @@ unitTest({ permissions: { read: true } }, function seekSyncCurrent() { file.close(); }); -unitTest({ permissions: { read: true } }, async function seekEnd() { +Deno.test({ permissions: { read: true } }, async function seekEnd() { const filename = "cli/tests/testdata/hello.txt"; const file = await Deno.open(filename); const seekPosition = -6; @@ -640,7 +639,7 @@ unitTest({ permissions: { read: true } }, async function seekEnd() { file.close(); }); -unitTest({ permissions: { read: true } }, function seekSyncEnd() { +Deno.test({ permissions: { read: true } }, function seekSyncEnd() { const filename = "cli/tests/testdata/hello.txt"; const file = Deno.openSync(filename); const seekPosition = -6; @@ -654,7 +653,7 @@ unitTest({ permissions: { read: true } }, function seekSyncEnd() { file.close(); }); -unitTest({ permissions: { read: true } }, async function seekMode() { +Deno.test({ permissions: { read: true } }, async function seekMode() { const filename = "cli/tests/testdata/hello.txt"; const file = await Deno.open(filename); await assertRejects( diff --git a/cli/tests/unit/flock_test.ts b/cli/tests/unit/flock_test.ts index 42873cb0c4..8c62c6abca 100644 --- a/cli/tests/unit/flock_test.ts +++ b/cli/tests/unit/flock_test.ts @@ -1,15 +1,15 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -import { assertEquals, unitTest } from "./test_util.ts"; +import { assertEquals } from "./test_util.ts"; import { readAll } from "../../../test_util/std/io/util.ts"; -unitTest( +Deno.test( { permissions: { read: true, run: true, hrtime: true } }, async function flockFileSync() { await runFlockTests({ sync: true }); }, ); -unitTest( +Deno.test( { permissions: { read: true, run: true, hrtime: true } }, async function flockFileAsync() { await runFlockTests({ sync: false }); diff --git a/cli/tests/unit/format_error_test.ts b/cli/tests/unit/format_error_test.ts index 7d82499b77..1a956e25c0 100644 --- a/cli/tests/unit/format_error_test.ts +++ b/cli/tests/unit/format_error_test.ts @@ -1,7 +1,7 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -import { assert, unitTest } from "./test_util.ts"; +import { assert } from "./test_util.ts"; -unitTest(function formatDiagnosticBasic() { +Deno.test(function formatDiagnosticBasic() { const fixture: Deno.Diagnostic[] = [ { start: { @@ -25,7 +25,7 @@ unitTest(function formatDiagnosticBasic() { assert(out.includes("test.ts")); }); -unitTest(function formatDiagnosticError() { +Deno.test(function formatDiagnosticError() { let thrown = false; // deno-lint-ignore no-explicit-any const bad = ([{ hello: 123 }] as any) as Deno.Diagnostic[]; diff --git a/cli/tests/unit/fs_events_test.ts b/cli/tests/unit/fs_events_test.ts index a839e64f1d..2888a05f88 100644 --- a/cli/tests/unit/fs_events_test.ts +++ b/cli/tests/unit/fs_events_test.ts @@ -1,21 +1,15 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. -import { - assert, - assertEquals, - assertThrows, - delay, - unitTest, -} from "./test_util.ts"; +import { assert, assertEquals, assertThrows, delay } from "./test_util.ts"; // TODO(ry) Add more tests to specify format. -unitTest({ permissions: { read: false } }, function watchFsPermissions() { +Deno.test({ permissions: { read: false } }, function watchFsPermissions() { assertThrows(() => { Deno.watchFs("."); }, Deno.errors.PermissionDenied); }); -unitTest({ permissions: { read: true } }, function watchFsInvalidPath() { +Deno.test({ permissions: { read: true } }, function watchFsInvalidPath() { if (Deno.build.os === "windows") { assertThrows( () => { @@ -50,7 +44,7 @@ async function makeTempDir(): Promise { return testDir; } -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function watchFsBasic() { const testDir = await makeTempDir(); @@ -77,7 +71,7 @@ unitTest( // TODO(kt3k): This test is for the backward compatibility of `.return` method. // This should be removed at 2.0 -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function watchFsReturn() { const testDir = await makeTempDir(); @@ -95,7 +89,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function watchFsClose() { const testDir = await makeTempDir(); diff --git a/cli/tests/unit/get_random_values_test.ts b/cli/tests/unit/get_random_values_test.ts index a9b493104c..ca3986ded7 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"; +import { assertNotEquals, assertStrictEquals } from "./test_util.ts"; -unitTest(function getRandomValuesInt8Array() { +Deno.test(function getRandomValuesInt8Array() { const arr = new Int8Array(32); crypto.getRandomValues(arr); assertNotEquals(arr, new Int8Array(32)); }); -unitTest(function getRandomValuesUint8Array() { +Deno.test(function getRandomValuesUint8Array() { const arr = new Uint8Array(32); crypto.getRandomValues(arr); assertNotEquals(arr, new Uint8Array(32)); }); -unitTest(function getRandomValuesUint8ClampedArray() { +Deno.test(function getRandomValuesUint8ClampedArray() { const arr = new Uint8ClampedArray(32); crypto.getRandomValues(arr); assertNotEquals(arr, new Uint8ClampedArray(32)); }); -unitTest(function getRandomValuesInt16Array() { +Deno.test(function getRandomValuesInt16Array() { const arr = new Int16Array(4); crypto.getRandomValues(arr); assertNotEquals(arr, new Int16Array(4)); }); -unitTest(function getRandomValuesUint16Array() { +Deno.test(function getRandomValuesUint16Array() { const arr = new Uint16Array(4); crypto.getRandomValues(arr); assertNotEquals(arr, new Uint16Array(4)); }); -unitTest(function getRandomValuesInt32Array() { +Deno.test(function getRandomValuesInt32Array() { const arr = new Int32Array(8); crypto.getRandomValues(arr); assertNotEquals(arr, new Int32Array(8)); }); -unitTest(function getRandomValuesUint32Array() { +Deno.test(function getRandomValuesUint32Array() { const arr = new Uint32Array(8); crypto.getRandomValues(arr); assertNotEquals(arr, new Uint32Array(8)); }); -unitTest(function getRandomValuesReturnValue() { +Deno.test(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 f3c8141d8e..fccf65ce3a 100644 --- a/cli/tests/unit/globals_test.ts +++ b/cli/tests/unit/globals_test.ts @@ -1,73 +1,73 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. // deno-lint-ignore-file no-window-prefix -import { assert, unitTest } from "./test_util.ts"; +import { assert } from "./test_util.ts"; -unitTest(function globalThisExists() { +Deno.test(function globalThisExists() { assert(globalThis != null); }); -unitTest(function noInternalGlobals() { +Deno.test(function noInternalGlobals() { // globalThis.__bootstrap should not be there. for (const key of Object.keys(globalThis)) { assert(!key.startsWith("_")); } }); -unitTest(function windowExists() { +Deno.test(function windowExists() { assert(window != null); }); -unitTest(function selfExists() { +Deno.test(function selfExists() { assert(self != null); }); -unitTest(function windowWindowExists() { +Deno.test(function windowWindowExists() { assert(window.window === window); }); -unitTest(function windowSelfExists() { +Deno.test(function windowSelfExists() { assert(window.self === window); }); -unitTest(function globalThisEqualsWindow() { +Deno.test(function globalThisEqualsWindow() { assert(globalThis === window); }); -unitTest(function globalThisEqualsSelf() { +Deno.test(function globalThisEqualsSelf() { assert(globalThis === self); }); -unitTest(function globalThisInstanceofWindow() { +Deno.test(function globalThisInstanceofWindow() { assert(globalThis instanceof Window); }); -unitTest(function globalThisConstructorLength() { +Deno.test(function globalThisConstructorLength() { assert(globalThis.constructor.length === 0); }); -unitTest(function globalThisInstanceofEventTarget() { +Deno.test(function globalThisInstanceofEventTarget() { assert(globalThis instanceof EventTarget); }); -unitTest(function navigatorInstanceofNavigator() { +Deno.test(function navigatorInstanceofNavigator() { // TODO(nayeemrmn): Add `Navigator` to deno_lint globals. // deno-lint-ignore no-undef assert(navigator instanceof Navigator); }); -unitTest(function DenoNamespaceExists() { +Deno.test(function DenoNamespaceExists() { assert(Deno != null); }); -unitTest(function DenoNamespaceEqualsWindowDeno() { +Deno.test(function DenoNamespaceEqualsWindowDeno() { assert(Deno === window.Deno); }); -unitTest(function DenoNamespaceIsNotFrozen() { +Deno.test(function DenoNamespaceIsNotFrozen() { assert(!Object.isFrozen(Deno)); }); -unitTest(function webAssemblyExists() { +Deno.test(function webAssemblyExists() { assert(typeof WebAssembly.compile === "function"); }); @@ -78,14 +78,14 @@ declare global { } } -unitTest(function DenoNamespaceConfigurable() { +Deno.test(function DenoNamespaceConfigurable() { const desc = Object.getOwnPropertyDescriptor(globalThis, "Deno"); assert(desc); assert(desc.configurable); assert(!desc.writable); }); -unitTest(function DenoCoreNamespaceIsImmutable() { +Deno.test(function DenoCoreNamespaceIsImmutable() { const { print } = Deno.core; try { Deno.core.print = 1; @@ -101,7 +101,7 @@ unitTest(function DenoCoreNamespaceIsImmutable() { assert(print === Deno.core.print); }); -unitTest(async function windowQueueMicrotask() { +Deno.test(async function windowQueueMicrotask() { let resolve1: () => void | undefined; let resolve2: () => void | undefined; let microtaskDone = false; @@ -123,7 +123,7 @@ unitTest(async function windowQueueMicrotask() { await p2; }); -unitTest(function webApiGlobalThis() { +Deno.test(function webApiGlobalThis() { assert(globalThis.FormData !== null); assert(globalThis.TextEncoder !== null); assert(globalThis.TextEncoderStream !== null); diff --git a/cli/tests/unit/headers_test.ts b/cli/tests/unit/headers_test.ts index bc695e7d90..9fad3628db 100644 --- a/cli/tests/unit/headers_test.ts +++ b/cli/tests/unit/headers_test.ts @@ -1,18 +1,18 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals, unitTest } from "./test_util.ts"; +import { assert, assertEquals } from "./test_util.ts"; const { inspectArgs, // @ts-expect-error TypeScript (as of 3.7) does not support indexing namespaces by symbol } = Deno[Deno.internal]; -unitTest(function headersHasCorrectNameProp() { +Deno.test(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() { +Deno.test(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() { +Deno.test(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() { assertEquals(headers.get("length"), null); }); -unitTest(function newHeaderWithRecord() { +Deno.test(function newHeaderWithRecord() { const headers = new Headers(headerDict); for (const name in headerDict) { assertEquals(headers.get(name), String(headerDict[name])); } }); -unitTest(function newHeaderWithHeadersInstance() { +Deno.test(function newHeaderWithHeadersInstance() { const headers = new Headers(headerDict); const headers2 = new Headers(headers); for (const name in headerDict) { @@ -61,7 +61,7 @@ unitTest(function newHeaderWithHeadersInstance() { } }); -unitTest(function headerAppendSuccess() { +Deno.test(function headerAppendSuccess() { const headers = new Headers(); for (const name in headerDict) { headers.append(name, headerDict[name]); @@ -69,7 +69,7 @@ unitTest(function headerAppendSuccess() { } }); -unitTest(function headerSetSuccess() { +Deno.test(function headerSetSuccess() { const headers = new Headers(); for (const name in headerDict) { headers.set(name, headerDict[name]); @@ -77,7 +77,7 @@ unitTest(function headerSetSuccess() { } }); -unitTest(function headerHasSuccess() { +Deno.test(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() { } }); -unitTest(function headerDeleteSuccess() { +Deno.test(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() { } }); -unitTest(function headerGetSuccess() { +Deno.test(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() { } }); -unitTest(function headerEntriesSuccess() { +Deno.test(function headerEntriesSuccess() { const headers = new Headers(headerDict); const iterators = headers.entries(); for (const it of iterators) { @@ -116,7 +116,7 @@ unitTest(function headerEntriesSuccess() { } }); -unitTest(function headerKeysSuccess() { +Deno.test(function headerKeysSuccess() { const headers = new Headers(headerDict); const iterators = headers.keys(); for (const it of iterators) { @@ -124,7 +124,7 @@ unitTest(function headerKeysSuccess() { } }); -unitTest(function headerValuesSuccess() { +Deno.test(function headerValuesSuccess() { const headers = new Headers(headerDict); const iterators = headers.values(); const entries = headers.entries(); @@ -146,7 +146,7 @@ const headerEntriesDict: Record = { "Content-Types": "value6", }; -unitTest(function headerForEachSuccess() { +Deno.test(function headerForEachSuccess() { const headers = new Headers(headerEntriesDict); const keys = Object.keys(headerEntriesDict); keys.forEach((key) => { @@ -163,7 +163,7 @@ unitTest(function headerForEachSuccess() { assertEquals(callNum, keys.length); }); -unitTest(function headerSymbolIteratorSuccess() { +Deno.test(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() { } }); -unitTest(function headerTypesAvailable() { +Deno.test(function headerTypesAvailable() { function newHeaders(): Headers { return new Headers(); } @@ -184,7 +184,7 @@ unitTest(function headerTypesAvailable() { // 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() { +Deno.test(function headerIllegalReject() { let errorCount = 0; try { new Headers({ "He y": "ok" }); @@ -238,7 +238,7 @@ unitTest(function headerIllegalReject() { }); // If pair does not contain exactly two items,then throw a TypeError. -unitTest(function headerParamsShouldThrowTypeError() { +Deno.test(function headerParamsShouldThrowTypeError() { let hasThrown = 0; try { @@ -255,7 +255,7 @@ unitTest(function headerParamsShouldThrowTypeError() { assertEquals(hasThrown, 2); }); -unitTest(function headerParamsArgumentsCheck() { +Deno.test(function headerParamsArgumentsCheck() { const methodRequireOneParam = ["delete", "get", "has", "forEach"] as const; const methodRequireTwoParams = ["append", "set"] as const; @@ -310,7 +310,7 @@ unitTest(function headerParamsArgumentsCheck() { }); }); -unitTest(function headersInitMultiple() { +Deno.test(function headersInitMultiple() { const headers = new Headers([ ["Set-Cookie", "foo=bar"], ["Set-Cookie", "bar=baz"], @@ -325,7 +325,7 @@ unitTest(function headersInitMultiple() { ]); }); -unitTest(function headersAppendMultiple() { +Deno.test(function headersAppendMultiple() { const headers = new Headers([ ["Set-Cookie", "foo=bar"], ["X-Deno", "foo"], @@ -340,7 +340,7 @@ unitTest(function headersAppendMultiple() { ]); }); -unitTest(function headersAppendDuplicateSetCookieKey() { +Deno.test(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() { ]); }); -unitTest(function headersGetSetCookie() { +Deno.test(function headersGetSetCookie() { const headers = new Headers([ ["Set-Cookie", "foo=bar"], ["set-Cookie", "bar=qat"], @@ -360,7 +360,7 @@ unitTest(function headersGetSetCookie() { assertEquals(headers.get("SET-COOKIE"), "foo=bar, bar=qat"); }); -unitTest(function toStringShouldBeWebCompatibility() { +Deno.test(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() { +Deno.test(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 b70320741c..7cf62c0466 100644 --- a/cli/tests/unit/http_test.ts +++ b/cli/tests/unit/http_test.ts @@ -12,7 +12,6 @@ import { deferred, delay, fail, - unitTest, } from "./test_util.ts"; async function writeRequestAndReadResponse(conn: Deno.Conn): Promise { @@ -42,7 +41,7 @@ async function writeRequestAndReadResponse(conn: Deno.Conn): Promise { return decoder.decode(dest.bytes()); } -unitTest({ permissions: { net: true } }, async function httpServerBasic() { +Deno.test({ permissions: { net: true } }, async function httpServerBasic() { const promise = (async () => { const listener = Deno.listen({ port: 4501 }); for await (const conn of listener) { @@ -68,7 +67,7 @@ unitTest({ permissions: { net: true } }, async function httpServerBasic() { await promise; }); -unitTest( +Deno.test( { permissions: { net: true } }, async function httpServerGetRequestBody() { const promise = (async () => { @@ -102,7 +101,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function httpServerStreamResponse() { const stream = new TransformStream(); @@ -131,7 +130,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function httpServerStreamRequest() { const stream = new TransformStream(); @@ -170,7 +169,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function httpServerStreamDuplex() { const promise = (async () => { @@ -209,7 +208,7 @@ unitTest( }, ); -unitTest({ permissions: { net: true } }, async function httpServerClose() { +Deno.test({ permissions: { net: true } }, async function httpServerClose() { const listener = Deno.listen({ port: 4501 }); const client = await Deno.connect({ port: 4501 }); const httpConn = Deno.serveHttp(await listener.accept()); @@ -220,7 +219,7 @@ unitTest({ permissions: { net: true } }, async function httpServerClose() { listener.close(); }); -unitTest( +Deno.test( { permissions: { net: true } }, async function httpServerInvalidMethod() { const listener = Deno.listen({ port: 4501 }); @@ -240,7 +239,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, net: true } }, async function httpServerWithTls() { const hostname = "localhost"; @@ -281,7 +280,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function httpServerRegressionHang() { const promise = (async () => { @@ -308,7 +307,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function httpServerCancelBodyOnResponseFailure() { const promise = (async () => { @@ -353,7 +352,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function httpServerNextRequestErrorExposedInResponse() { const promise = (async () => { @@ -398,7 +397,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function httpServerEmptyBlobResponse() { const promise = (async () => { @@ -420,7 +419,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function httpServerNextRequestResolvesOnClose() { const httpConnList: Deno.HttpConn[] = []; @@ -452,7 +451,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, // Issue: https://github.com/denoland/deno/issues/10870 async function httpServerHang() { @@ -498,7 +497,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, // Issue: https://github.com/denoland/deno/issues/10930 async function httpServerStreamingResponse() { @@ -588,7 +587,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function httpRequestLatin1Headers() { const promise = (async () => { @@ -634,7 +633,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function httpServerRequestWithoutPath() { const promise = (async () => { @@ -679,7 +678,7 @@ unitTest( }, ); -unitTest({ permissions: { net: true } }, async function httpServerWebSocket() { +Deno.test({ permissions: { net: true } }, async function httpServerWebSocket() { const promise = (async () => { const listener = Deno.listen({ port: 4501 }); for await (const conn of listener) { @@ -709,7 +708,7 @@ unitTest({ permissions: { net: true } }, async function httpServerWebSocket() { await promise; }); -unitTest(function httpUpgradeWebSocket() { +Deno.test(function httpUpgradeWebSocket() { const request = new Request("https://deno.land/", { headers: { connection: "Upgrade", @@ -727,7 +726,7 @@ unitTest(function httpUpgradeWebSocket() { ); }); -unitTest(function httpUpgradeWebSocketMultipleConnectionOptions() { +Deno.test(function httpUpgradeWebSocketMultipleConnectionOptions() { const request = new Request("https://deno.land/", { headers: { connection: "keep-alive, upgrade", @@ -739,7 +738,7 @@ unitTest(function httpUpgradeWebSocketMultipleConnectionOptions() { assertEquals(response.status, 101); }); -unitTest(function httpUpgradeWebSocketMultipleUpgradeOptions() { +Deno.test(function httpUpgradeWebSocketMultipleUpgradeOptions() { const request = new Request("https://deno.land/", { headers: { connection: "upgrade", @@ -751,7 +750,7 @@ unitTest(function httpUpgradeWebSocketMultipleUpgradeOptions() { assertEquals(response.status, 101); }); -unitTest(function httpUpgradeWebSocketCaseInsensitiveUpgradeHeader() { +Deno.test(function httpUpgradeWebSocketCaseInsensitiveUpgradeHeader() { const request = new Request("https://deno.land/", { headers: { connection: "upgrade", @@ -763,7 +762,7 @@ unitTest(function httpUpgradeWebSocketCaseInsensitiveUpgradeHeader() { assertEquals(response.status, 101); }); -unitTest(function httpUpgradeWebSocketInvalidUpgradeHeader() { +Deno.test(function httpUpgradeWebSocketInvalidUpgradeHeader() { assertThrows( () => { const request = new Request("https://deno.land/", { @@ -780,7 +779,7 @@ unitTest(function httpUpgradeWebSocketInvalidUpgradeHeader() { ); }); -unitTest(function httpUpgradeWebSocketWithoutUpgradeHeader() { +Deno.test(function httpUpgradeWebSocketWithoutUpgradeHeader() { assertThrows( () => { const request = new Request("https://deno.land/", { @@ -796,7 +795,7 @@ unitTest(function httpUpgradeWebSocketWithoutUpgradeHeader() { ); }); -unitTest( +Deno.test( { permissions: { net: true } }, async function httpCookieConcatenation() { const promise = (async () => { @@ -827,7 +826,7 @@ unitTest( ); // https://github.com/denoland/deno/issues/11651 -unitTest({ permissions: { net: true } }, async function httpServerPanic() { +Deno.test({ permissions: { net: true } }, async function httpServerPanic() { const listener = Deno.listen({ port: 4501 }); const client = await Deno.connect({ port: 4501 }); const conn = await listener.accept(); @@ -847,7 +846,7 @@ unitTest({ permissions: { net: true } }, async function httpServerPanic() { }); // https://github.com/denoland/deno/issues/11595 -unitTest( +Deno.test( { permissions: { net: true } }, async function httpServerIncompleteMessage() { const listener = Deno.listen({ port: 4501 }); @@ -906,7 +905,7 @@ unitTest( ); // https://github.com/denoland/deno/issues/11743 -unitTest( +Deno.test( { permissions: { net: true } }, async function httpServerDoesntLeakResources() { const listener = Deno.listen({ port: 4505 }); @@ -930,7 +929,7 @@ unitTest( ); // https://github.com/denoland/deno/issues/11926 -unitTest( +Deno.test( { permissions: { net: true } }, async function httpServerDoesntLeakResources2() { let listener: Deno.Listener; @@ -972,7 +971,7 @@ unitTest( ); // https://github.com/denoland/deno/pull/12216 -unitTest( +Deno.test( { permissions: { net: true } }, async function droppedConnSenderNoPanic() { async function server() { @@ -1003,7 +1002,7 @@ unitTest( ); // https://github.com/denoland/deno/issues/12193 -unitTest( +Deno.test( { permissions: { net: true } }, async function httpConnConcurrentNextRequestCalls() { const hostname = "localhost"; @@ -1040,7 +1039,7 @@ unitTest( // https://github.com/denoland/deno/pull/12704 // https://github.com/denoland/deno/pull/12732 -unitTest( +Deno.test( { permissions: { net: true } }, async function httpConnAutoCloseDelayedOnUpgrade() { const hostname = "localhost"; @@ -1079,7 +1078,7 @@ unitTest( // https://github.com/denoland/deno/issues/12741 // https://github.com/denoland/deno/pull/12746 // https://github.com/denoland/deno/pull/12798 -unitTest( +Deno.test( { permissions: { net: true, run: true } }, async function httpServerDeleteRequestHasBody() { const hostname = "localhost"; @@ -1110,7 +1109,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function httpServerRespondNonAsciiUint8Array() { const promise = (async () => { diff --git a/cli/tests/unit/internals_test.ts b/cli/tests/unit/internals_test.ts index d3512de057..f96f251928 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"; +import { assert } from "./test_util.ts"; -unitTest(function internalsExists() { +Deno.test(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/io_test.ts b/cli/tests/unit/io_test.ts index 5338bbc5e5..ac6c9e2097 100644 --- a/cli/tests/unit/io_test.ts +++ b/cli/tests/unit/io_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -import { assertEquals, unitTest } from "./test_util.ts"; +import { assertEquals } from "./test_util.ts"; import { Buffer } from "../../../test_util/std/io/buffer.ts"; const DEFAULT_BUF_SIZE = 32 * 1024; @@ -28,7 +28,7 @@ function spyRead(obj: Buffer): Spy { return spy; } -unitTest(async function copyWithDefaultBufferSize() { +Deno.test(async function copyWithDefaultBufferSize() { const xBytes = repeat("b", DEFAULT_BUF_SIZE); const reader = new Buffer(xBytes.buffer as ArrayBuffer); const write = new Buffer(); @@ -43,7 +43,7 @@ unitTest(async function copyWithDefaultBufferSize() { assertEquals(readSpy.calls, 2); // read with DEFAULT_BUF_SIZE bytes + read with 0 bytes }); -unitTest(async function copyWithCustomBufferSize() { +Deno.test(async function copyWithCustomBufferSize() { const bufSize = 1024; const xBytes = repeat("b", DEFAULT_BUF_SIZE); const reader = new Buffer(xBytes.buffer as ArrayBuffer); @@ -59,7 +59,7 @@ unitTest(async function copyWithCustomBufferSize() { assertEquals(readSpy.calls, DEFAULT_BUF_SIZE / bufSize + 1); }); -unitTest({ permissions: { write: true } }, async function copyBufferToFile() { +Deno.test({ permissions: { write: true } }, async function copyBufferToFile() { const filePath = "test-file.txt"; // bigger than max File possible buffer 16kb const bufSize = 32 * 1024; diff --git a/cli/tests/unit/link_test.ts b/cli/tests/unit/link_test.ts index fdd7d2fe82..36e30f3ba9 100644 --- a/cli/tests/unit/link_test.ts +++ b/cli/tests/unit/link_test.ts @@ -4,10 +4,9 @@ import { assertEquals, assertRejects, assertThrows, - unitTest, } from "./test_util.ts"; -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function linkSyncSuccess() { const testDir = Deno.makeTempDirSync(); @@ -46,7 +45,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function linkSyncExists() { const testDir = Deno.makeTempDirSync(); @@ -66,7 +65,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function linkSyncNotFound() { const testDir = Deno.makeTempDirSync(); @@ -83,7 +82,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: false, write: true } }, function linkSyncReadPerm() { assertThrows(() => { @@ -92,7 +91,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: false } }, function linkSyncWritePerm() { assertThrows(() => { @@ -101,7 +100,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function linkSuccess() { const testDir = Deno.makeTempDirSync(); @@ -140,7 +139,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function linkExists() { const testDir = Deno.makeTempDirSync(); @@ -160,7 +159,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function linkNotFound() { const testDir = Deno.makeTempDirSync(); @@ -177,7 +176,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: false, write: true } }, async function linkReadPerm() { await assertRejects(async () => { @@ -186,7 +185,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: false } }, async function linkWritePerm() { await assertRejects(async () => { diff --git a/cli/tests/unit/make_temp_test.ts b/cli/tests/unit/make_temp_test.ts index da39be2ded..c7d8aa2520 100644 --- a/cli/tests/unit/make_temp_test.ts +++ b/cli/tests/unit/make_temp_test.ts @@ -4,10 +4,9 @@ import { assertEquals, assertRejects, assertThrows, - unitTest, } from "./test_util.ts"; -unitTest({ permissions: { write: true } }, function makeTempDirSyncSuccess() { +Deno.test({ permissions: { 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. @@ -28,7 +27,7 @@ unitTest({ permissions: { write: true } }, function makeTempDirSyncSuccess() { }, Deno.errors.NotFound); }); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function makeTempDirSyncMode() { const path = Deno.makeTempDirSync(); @@ -39,14 +38,14 @@ unitTest( }, ); -unitTest(function makeTempDirSyncPerm() { +Deno.test({ permissions: { write: false } }, function makeTempDirSyncPerm() { // makeTempDirSync should require write permissions (for now). assertThrows(() => { Deno.makeTempDirSync({ dir: "/baddir" }); }, Deno.errors.PermissionDenied); }); -unitTest( +Deno.test( { permissions: { write: true } }, async function makeTempDirSuccess() { const dir1 = await Deno.makeTempDir({ prefix: "hello", suffix: "world" }); @@ -70,7 +69,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function makeTempDirMode() { const path = await Deno.makeTempDir(); @@ -81,7 +80,7 @@ unitTest( }, ); -unitTest({ permissions: { write: true } }, function makeTempFileSyncSuccess() { +Deno.test({ permissions: { 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. @@ -103,7 +102,7 @@ unitTest({ permissions: { write: true } }, function makeTempFileSyncSuccess() { }, Deno.errors.NotFound); }); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function makeTempFileSyncMode() { const path = Deno.makeTempFileSync(); @@ -114,14 +113,14 @@ unitTest( }, ); -unitTest(function makeTempFileSyncPerm() { +Deno.test({ permissions: { write: false } }, function makeTempFileSyncPerm() { // makeTempFileSync should require write permissions (for now). assertThrows(() => { Deno.makeTempFileSync({ dir: "/baddir" }); }, Deno.errors.PermissionDenied); }); -unitTest( +Deno.test( { permissions: { write: true } }, async function makeTempFileSuccess() { const file1 = await Deno.makeTempFile({ prefix: "hello", suffix: "world" }); @@ -146,7 +145,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function makeTempFileMode() { const path = await Deno.makeTempFile(); diff --git a/cli/tests/unit/metrics_test.ts b/cli/tests/unit/metrics_test.ts index f020d69e8f..00dc06a206 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"; +import { assert } from "./test_util.ts"; -unitTest(async function metrics() { +Deno.test(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", @@ -39,7 +39,7 @@ unitTest(async function metrics() { assert(m2OpWrite.bytesReceived === m1OpWrite.bytesReceived); }); -unitTest( +Deno.test( { permissions: { write: true } }, function metricsUpdatedIfNoResponseSync() { const filename = Deno.makeTempDirSync() + "/test.txt"; @@ -53,7 +53,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { write: true } }, async function metricsUpdatedIfNoResponseAsync() { const filename = Deno.makeTempDirSync() + "/test.txt"; @@ -69,7 +69,7 @@ unitTest( ); // Test that ops from extensions have metrics (via OpMiddleware) -unitTest(function metricsForOpCrates() { +Deno.test(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 b06a1cd4cf..327665ee8f 100644 --- a/cli/tests/unit/mkdir_test.ts +++ b/cli/tests/unit/mkdir_test.ts @@ -5,7 +5,6 @@ import { assertRejects, assertThrows, pathToAbsoluteFileUrl, - unitTest, } from "./test_util.ts"; function assertDirectory(path: string, mode?: number) { @@ -16,7 +15,7 @@ function assertDirectory(path: string, mode?: number) { } } -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function mkdirSyncSuccess() { const path = Deno.makeTempDirSync() + "/dir"; @@ -25,7 +24,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function mkdirSyncMode() { const path = Deno.makeTempDirSync() + "/dir"; @@ -34,13 +33,13 @@ unitTest( }, ); -unitTest({ permissions: { write: false } }, function mkdirSyncPerm() { +Deno.test({ permissions: { write: false } }, function mkdirSyncPerm() { assertThrows(() => { Deno.mkdirSync("/baddir"); }, Deno.errors.PermissionDenied); }); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function mkdirSuccess() { const path = Deno.makeTempDirSync() + "/dir"; @@ -49,7 +48,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function mkdirMode() { const path = Deno.makeTempDirSync() + "/dir"; @@ -58,7 +57,7 @@ unitTest( }, ); -unitTest({ permissions: { write: true } }, function mkdirErrSyncIfExists() { +Deno.test({ permissions: { write: true } }, function mkdirErrSyncIfExists() { assertThrows( () => { Deno.mkdirSync("."); @@ -68,7 +67,7 @@ unitTest({ permissions: { write: true } }, function mkdirErrSyncIfExists() { ); }); -unitTest({ permissions: { write: true } }, async function mkdirErrIfExists() { +Deno.test({ permissions: { write: true } }, async function mkdirErrIfExists() { await assertRejects( async () => { await Deno.mkdir("."); @@ -78,7 +77,7 @@ unitTest({ permissions: { write: true } }, async function mkdirErrIfExists() { ); }); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function mkdirSyncRecursive() { const path = Deno.makeTempDirSync() + "/nested/directory"; @@ -87,7 +86,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function mkdirRecursive() { const path = Deno.makeTempDirSync() + "/nested/directory"; @@ -96,7 +95,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function mkdirSyncRecursiveMode() { const nested = Deno.makeTempDirSync() + "/nested"; @@ -107,7 +106,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function mkdirRecursiveMode() { const nested = Deno.makeTempDirSync() + "/nested"; @@ -118,7 +117,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function mkdirSyncRecursiveIfExists() { const path = Deno.makeTempDirSync() + "/dir"; @@ -136,7 +135,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function mkdirRecursiveIfExists() { const path = Deno.makeTempDirSync() + "/dir"; @@ -154,7 +153,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function mkdirSyncErrors() { const testDir = Deno.makeTempDirSync(); @@ -205,7 +204,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function mkdirSyncRelativeUrlPath() { const testDir = Deno.makeTempDirSync(); @@ -220,7 +219,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function mkdirRelativeUrlPath() { const testDir = Deno.makeTempDirSync(); diff --git a/cli/tests/unit/navigator_test.ts b/cli/tests/unit/navigator_test.ts index 6357d4c560..898042d882 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"; +import { assert } from "./test_util.ts"; -unitTest(function navigatorNumCpus() { +Deno.test(function navigatorNumCpus() { assert(navigator.hardwareConcurrency > 0); }); diff --git a/cli/tests/unit/net_test.ts b/cli/tests/unit/net_test.ts index eabe26c84d..7ea1b8bcfd 100644 --- a/cli/tests/unit/net_test.ts +++ b/cli/tests/unit/net_test.ts @@ -7,7 +7,6 @@ import { assertThrows, deferred, delay, - unitTest, } from "./test_util.ts"; let isCI: boolean; @@ -17,7 +16,7 @@ try { isCI = true; } -unitTest({ permissions: { net: true } }, function netTcpListenClose() { +Deno.test({ permissions: { 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"); @@ -26,7 +25,7 @@ unitTest({ permissions: { net: true } }, function netTcpListenClose() { listener.close(); }); -unitTest( +Deno.test( { permissions: { net: true }, }, @@ -43,7 +42,7 @@ unitTest( }, ); -unitTest( +Deno.test( { ignore: Deno.build.os === "windows", permissions: { read: true, write: true }, @@ -60,7 +59,7 @@ unitTest( }, ); -unitTest( +Deno.test( { ignore: Deno.build.os === "windows", permissions: { read: true, write: true }, @@ -77,8 +76,11 @@ unitTest( }, ); -unitTest( - { ignore: Deno.build.os === "windows", permissions: { read: true } }, +Deno.test( + { + ignore: Deno.build.os === "windows", + permissions: { read: true, write: false }, + }, function netUnixListenWritePermission() { assertThrows(() => { const filePath = Deno.makeTempFileSync(); @@ -93,8 +95,11 @@ unitTest( }, ); -unitTest( - { ignore: Deno.build.os === "windows", permissions: { read: true } }, +Deno.test( + { + ignore: Deno.build.os === "windows", + permissions: { read: true, write: false }, + }, function netUnixPacketListenWritePermission() { assertThrows(() => { const filePath = Deno.makeTempFileSync(); @@ -109,7 +114,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true }, }, @@ -127,7 +132,7 @@ unitTest( }, ); -unitTest( +Deno.test( { ignore: Deno.build.os === "windows", permissions: { read: true, write: true }, @@ -147,7 +152,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function netTcpConcurrentAccept() { const listener = Deno.listen({ port: 4502 }); @@ -170,7 +175,7 @@ unitTest( }, ); -unitTest( +Deno.test( { ignore: Deno.build.os === "windows", permissions: { read: true, write: true }, @@ -197,7 +202,7 @@ unitTest( }, ); -unitTest({ permissions: { net: true } }, async function netTcpDialListen() { +Deno.test({ permissions: { net: true } }, async function netTcpDialListen() { const listener = Deno.listen({ port: 3500 }); listener.accept().then( async (conn) => { @@ -232,7 +237,7 @@ unitTest({ permissions: { net: true } }, async function netTcpDialListen() { conn.close(); }); -unitTest( +Deno.test( { ignore: Deno.build.os === "windows", permissions: { read: true, write: true }, @@ -271,7 +276,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function netUdpSendReceive() { const alice = Deno.listenDatagram({ port: 3500, transport: "udp" }); @@ -301,7 +306,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function netUdpConcurrentSendReceive() { const socket = Deno.listenDatagram({ port: 3500, transport: "udp" }); @@ -325,7 +330,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function netUdpBorrowMutError() { const socket = Deno.listenDatagram({ @@ -340,7 +345,7 @@ unitTest( }, ); -unitTest( +Deno.test( { ignore: Deno.build.os === "windows", permissions: { read: true, write: true }, @@ -378,7 +383,7 @@ unitTest( ); // TODO(piscisaureus): Enable after Tokio v0.3/v1.0 upgrade. -unitTest( +Deno.test( { ignore: true, permissions: { read: true, write: true } }, async function netUnixPacketConcurrentSendReceive() { const filePath = await Deno.makeTempFile(); @@ -405,7 +410,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function netTcpListenIteratorBreakClosesResource() { async function iterate(listener: Deno.Listener) { @@ -435,7 +440,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function netTcpListenCloseWhileIterating() { const listener = Deno.listen({ port: 8001 }); @@ -448,7 +453,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function netUdpListenCloseWhileIterating() { const socket = Deno.listenDatagram({ port: 8000, transport: "udp" }); @@ -461,7 +466,7 @@ unitTest( }, ); -unitTest( +Deno.test( { ignore: Deno.build.os === "windows", permissions: { read: true, write: true }, @@ -478,7 +483,7 @@ unitTest( }, ); -unitTest( +Deno.test( { ignore: Deno.build.os === "windows", permissions: { read: true, write: true }, @@ -498,7 +503,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true } }, async function netListenAsyncIterator() { const addr = { hostname: "127.0.0.1", port: 3500 }; @@ -529,7 +534,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true }, }, @@ -562,7 +567,7 @@ unitTest( }, ); -unitTest( +Deno.test( { // https://github.com/denoland/deno/issues/11580 ignore: Deno.build.os === "darwin" && isCI, @@ -610,7 +615,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { net: true }, }, @@ -621,7 +626,7 @@ unitTest( }, ); -unitTest( +Deno.test( { ignore: Deno.build.os !== "linux", permissions: { read: true, write: true }, diff --git a/cli/tests/unit/opcall_test.ts b/cli/tests/unit/opcall_test.ts index 2cf0862204..5e783efc8d 100644 --- a/cli/tests/unit/opcall_test.ts +++ b/cli/tests/unit/opcall_test.ts @@ -1,11 +1,6 @@ -import { - assert, - assertStringIncludes, - unitTest, - unreachable, -} from "./test_util.ts"; +import { assert, assertStringIncludes, unreachable } from "./test_util.ts"; -unitTest(async function sendAsyncStackTrace() { +Deno.test(async function sendAsyncStackTrace() { const buf = new Uint8Array(10); const rid = 10; try { @@ -32,7 +27,7 @@ declare global { } } -unitTest(async function opsAsyncBadResource() { +Deno.test(async function opsAsyncBadResource() { try { const nonExistingRid = 9999; await Deno.core.read( @@ -46,7 +41,7 @@ unitTest(async function opsAsyncBadResource() { } }); -unitTest(function opsSyncBadResource() { +Deno.test(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 8c018cad0d..430b25fabc 100644 --- a/cli/tests/unit/os_test.ts +++ b/cli/tests/unit/os_test.ts @@ -4,10 +4,9 @@ import { assertEquals, assertNotEquals, assertThrows, - unitTest, } from "./test_util.ts"; -unitTest({ permissions: { env: true } }, function envSuccess() { +Deno.test({ permissions: { env: true } }, function envSuccess() { Deno.env.set("TEST_VAR", "A"); const env = Deno.env.toObject(); Deno.env.set("TEST_VAR", "B"); @@ -15,19 +14,19 @@ unitTest({ permissions: { env: true } }, function envSuccess() { assertNotEquals(Deno.env.get("TEST_VAR"), env["TEST_VAR"]); }); -unitTest({ permissions: { env: true } }, function envNotFound() { +Deno.test({ permissions: { env: true } }, function envNotFound() { const r = Deno.env.get("env_var_does_not_exist!"); assertEquals(r, undefined); }); -unitTest({ permissions: { env: true } }, function deleteEnv() { +Deno.test({ permissions: { 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({ permissions: { env: true } }, function avoidEmptyNamedEnv() { +Deno.test({ permissions: { 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 +41,13 @@ unitTest({ permissions: { env: true } }, function avoidEmptyNamedEnv() { assertThrows(() => Deno.env.delete("a\0a"), TypeError); }); -unitTest(function envPermissionDenied1() { +Deno.test({ permissions: { env: false } }, function envPermissionDenied1() { assertThrows(() => { Deno.env.toObject(); }, Deno.errors.PermissionDenied); }); -unitTest(function envPermissionDenied2() { +Deno.test({ permissions: { env: false } }, function envPermissionDenied2() { assertThrows(() => { Deno.env.get("PATH"); }, Deno.errors.PermissionDenied); @@ -57,7 +56,7 @@ unitTest(function envPermissionDenied2() { // This test verifies that on Windows, environment variables are // case-insensitive. Case normalization needs be done using the collation // that Windows uses, rather than naively using String.toLowerCase(). -unitTest( +Deno.test( { ignore: Deno.build.os !== "windows", permissions: { read: true, env: true, run: true }, @@ -122,15 +121,15 @@ unitTest( }, ); -unitTest(function osPid() { +Deno.test(function osPid() { assert(Deno.pid > 0); }); -unitTest(function osPpid() { +Deno.test(function osPpid() { assert(Deno.ppid > 0); }); -unitTest( +Deno.test( { permissions: { run: true, read: true } }, async function osPpidIsEqualToPidOfParentProcess() { const decoder = new TextDecoder(); @@ -148,11 +147,11 @@ unitTest( }, ); -unitTest({ permissions: { read: true } }, function execPath() { +Deno.test({ permissions: { read: true } }, function execPath() { assertNotEquals(Deno.execPath(), ""); }); -unitTest({ permissions: { read: false } }, function execPathPerm() { +Deno.test({ permissions: { read: false } }, function execPathPerm() { assertThrows( () => { Deno.execPath(); @@ -162,38 +161,38 @@ unitTest({ permissions: { read: false } }, function execPathPerm() { ); }); -unitTest({ permissions: { env: true } }, function loadavgSuccess() { +Deno.test({ permissions: { env: true } }, function loadavgSuccess() { const load = Deno.loadavg(); assertEquals(load.length, 3); }); -unitTest({ permissions: { env: false } }, function loadavgPerm() { +Deno.test({ permissions: { env: false } }, function loadavgPerm() { assertThrows(() => { Deno.loadavg(); }, Deno.errors.PermissionDenied); }); -unitTest({ permissions: { env: true } }, function hostnameDir() { +Deno.test({ permissions: { env: true } }, function hostnameDir() { assertNotEquals(Deno.hostname(), ""); }); -unitTest({ permissions: { env: false } }, function hostnamePerm() { +Deno.test({ permissions: { env: false } }, function hostnamePerm() { assertThrows(() => { Deno.hostname(); }, Deno.errors.PermissionDenied); }); -unitTest({ permissions: { env: true } }, function releaseDir() { +Deno.test({ permissions: { env: true } }, function releaseDir() { assertNotEquals(Deno.osRelease(), ""); }); -unitTest({ permissions: { env: false } }, function releasePerm() { +Deno.test({ permissions: { env: false } }, function releasePerm() { assertThrows(() => { Deno.osRelease(); }, Deno.errors.PermissionDenied); }); -unitTest({ permissions: { env: true } }, function systemMemoryInfo() { +Deno.test({ permissions: { 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 887b423665..f375d84f4f 100644 --- a/cli/tests/unit/path_from_url_test.ts +++ b/cli/tests/unit/path_from_url_test.ts @@ -1,9 +1,9 @@ -import { assertEquals, assertThrows, unitTest } from "./test_util.ts"; +import { assertEquals, assertThrows } from "./test_util.ts"; // @ts-expect-error TypeScript (as of 3.7) does not support indexing namespaces by symbol const { pathFromURL } = Deno[Deno.internal]; -unitTest( +Deno.test( { ignore: Deno.build.os === "windows" }, function pathFromURLPosix() { assertEquals( @@ -15,7 +15,7 @@ unitTest( }, ); -unitTest( +Deno.test( { ignore: Deno.build.os !== "windows" }, function pathFromURLWin32() { assertEquals( diff --git a/cli/tests/unit/performance_test.ts b/cli/tests/unit/performance_test.ts index ee0d716787..7237df3e7b 100644 --- a/cli/tests/unit/performance_test.ts +++ b/cli/tests/unit/performance_test.ts @@ -5,10 +5,9 @@ import { assertStringIncludes, assertThrows, deferred, - unitTest, } from "./test_util.ts"; -unitTest({ permissions: { hrtime: false } }, async function performanceNow() { +Deno.test({ permissions: { hrtime: false } }, async function performanceNow() { const resolvable = deferred(); const start = performance.now(); let totalTime = 0; @@ -21,7 +20,7 @@ unitTest({ permissions: { hrtime: false } }, async function performanceNow() { assert(totalTime >= 10); }); -unitTest(function performanceMark() { +Deno.test(function performanceMark() { const mark = performance.mark("test"); assert(mark instanceof PerformanceMark); assertEquals(mark.detail, null); @@ -35,7 +34,7 @@ unitTest(function performanceMark() { assert(markEntries[markEntries.length - 1] === mark); }); -unitTest(function performanceMeasure() { +Deno.test(function performanceMeasure() { const markName1 = "mark1"; const measureName1 = "measure1"; const measureName2 = "measure2"; @@ -82,7 +81,7 @@ unitTest(function performanceMeasure() { }); }); -unitTest(function performanceCustomInspectFunction() { +Deno.test(function performanceCustomInspectFunction() { assertStringIncludes(Deno.inspect(performance), "Performance"); assertStringIncludes( Deno.inspect(Performance.prototype), @@ -90,7 +89,7 @@ unitTest(function performanceCustomInspectFunction() { ); }); -unitTest(function performanceMarkCustomInspectFunction() { +Deno.test(function performanceMarkCustomInspectFunction() { const mark1 = performance.mark("mark1"); assertStringIncludes(Deno.inspect(mark1), "PerformanceMark"); assertStringIncludes( @@ -99,7 +98,7 @@ unitTest(function performanceMarkCustomInspectFunction() { ); }); -unitTest(function performanceMeasureCustomInspectFunction() { +Deno.test(function performanceMeasureCustomInspectFunction() { const measure1 = performance.measure("measure1"); assertStringIncludes(Deno.inspect(measure1), "PerformanceMeasure"); assertStringIncludes( @@ -108,17 +107,17 @@ unitTest(function performanceMeasureCustomInspectFunction() { ); }); -unitTest(function performanceIllegalConstructor() { +Deno.test(function performanceIllegalConstructor() { assertThrows(() => new Performance(), TypeError, "Illegal constructor"); assertEquals(Performance.length, 0); }); -unitTest(function performanceEntryIllegalConstructor() { +Deno.test(function performanceEntryIllegalConstructor() { assertThrows(() => new PerformanceEntry(), TypeError, "Illegal constructor"); assertEquals(PerformanceEntry.length, 0); }); -unitTest(function performanceMeasureIllegalConstructor() { +Deno.test(function performanceMeasureIllegalConstructor() { assertThrows( () => new PerformanceMeasure(), TypeError, diff --git a/cli/tests/unit/permissions_test.ts b/cli/tests/unit/permissions_test.ts index f1e66fb3c1..723f17ebfe 100644 --- a/cli/tests/unit/permissions_test.ts +++ b/cli/tests/unit/permissions_test.ts @@ -4,23 +4,22 @@ import { assertEquals, assertRejects, assertThrows, - unitTest, } from "./test_util.ts"; -unitTest(async function permissionInvalidName() { +Deno.test(async function permissionInvalidName() { await assertRejects(async () => { // deno-lint-ignore no-explicit-any await Deno.permissions.query({ name: "foo" as any }); }, TypeError); }); -unitTest(async function permissionNetInvalidHost() { +Deno.test(async function permissionNetInvalidHost() { await assertRejects(async () => { await Deno.permissions.query({ name: "net", host: ":" }); }, URIError); }); -unitTest(async function permissionQueryReturnsEventTarget() { +Deno.test(async function permissionQueryReturnsEventTarget() { const status = await Deno.permissions.query({ name: "hrtime" }); assert(["granted", "denied", "prompt"].includes(status.state)); let called = false; @@ -32,7 +31,7 @@ unitTest(async function permissionQueryReturnsEventTarget() { assert(status === (await Deno.permissions.query({ name: "hrtime" }))); }); -unitTest(async function permissionQueryForReadReturnsSameStatus() { +Deno.test(async function permissionQueryForReadReturnsSameStatus() { const status1 = await Deno.permissions.query({ name: "read", path: ".", @@ -44,12 +43,12 @@ unitTest(async function permissionQueryForReadReturnsSameStatus() { assert(status1 === status2); }); -unitTest(function permissionsIllegalConstructor() { +Deno.test(function permissionsIllegalConstructor() { assertThrows(() => new Deno.Permissions(), TypeError, "Illegal constructor."); assertEquals(Deno.Permissions.length, 0); }); -unitTest(function permissionStatusIllegalConstructor() { +Deno.test(function permissionStatusIllegalConstructor() { assertThrows( () => new Deno.PermissionStatus(), TypeError, @@ -58,7 +57,7 @@ unitTest(function permissionStatusIllegalConstructor() { assertEquals(Deno.PermissionStatus.length, 0); }); -unitTest(async function permissionURL() { +Deno.test(async function permissionURL() { await Deno.permissions.query({ name: "read", path: new URL(".", import.meta.url), diff --git a/cli/tests/unit/process_test.ts b/cli/tests/unit/process_test.ts index f1cc756f44..23ac66bb92 100644 --- a/cli/tests/unit/process_test.ts +++ b/cli/tests/unit/process_test.ts @@ -4,16 +4,20 @@ import { assertEquals, assertStringIncludes, assertThrows, - unitTest, } from "./test_util.ts"; -unitTest({ permissions: { read: true } }, function runPermissions() { - assertThrows(() => { - Deno.run({ cmd: [Deno.execPath(), "eval", "console.log('hello world')"] }); - }, Deno.errors.PermissionDenied); -}); +Deno.test( + { permissions: { read: true, run: false } }, + function runPermissions() { + assertThrows(() => { + Deno.run({ + cmd: [Deno.execPath(), "eval", "console.log('hello world')"], + }); + }, Deno.errors.PermissionDenied); + }, +); -unitTest( +Deno.test( { permissions: { run: true, read: true } }, async function runSuccess() { const p = Deno.run({ @@ -30,7 +34,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { run: true, read: true } }, async function runUrl() { const p = Deno.run({ @@ -51,7 +55,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { run: true, read: true } }, async function runStdinRid0(): Promise< void @@ -71,7 +75,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { run: true, read: true } }, function runInvalidStdio() { assertThrows(() => @@ -98,7 +102,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { run: true, read: true } }, async function runCommandFailedWithCode() { const p = Deno.run({ @@ -112,7 +116,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { run: true, read: true }, }, @@ -137,7 +141,7 @@ unitTest( }, ); -unitTest({ permissions: { run: true } }, function runNotFound() { +Deno.test({ permissions: { run: true } }, function runNotFound() { let error; try { Deno.run({ cmd: ["this file hopefully doesn't exist"] }); @@ -148,7 +152,7 @@ unitTest({ permissions: { run: true } }, function runNotFound() { assert(error instanceof Deno.errors.NotFound); }); -unitTest( +Deno.test( { permissions: { write: true, run: true, read: true } }, async function runWithCwdIsAsync() { const enc = new TextEncoder(); @@ -189,7 +193,7 @@ tryExit(); }, ); -unitTest( +Deno.test( { permissions: { run: true, read: true } }, async function runStdinPiped(): Promise< void @@ -220,7 +224,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { run: true, read: true } }, async function runStdoutPiped(): Promise< void @@ -256,7 +260,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { run: true, read: true } }, async function runStderrPiped(): Promise< void @@ -292,7 +296,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { run: true, read: true } }, async function runOutput() { const p = Deno.run({ @@ -310,7 +314,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { run: true, read: true } }, async function runStderrOutput(): Promise< void @@ -330,7 +334,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { run: true, write: true, read: true } }, async function runRedirectStdoutStderr() { const tempDir = await Deno.makeTempDir(); @@ -363,7 +367,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { run: true, write: true, read: true } }, async function runRedirectStdin() { const tempDir = await Deno.makeTempDir(); @@ -388,7 +392,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { run: true, read: true } }, async function runEnv() { const p = Deno.run({ @@ -410,7 +414,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { run: true, read: true } }, async function runClose() { const p = Deno.run({ @@ -433,7 +437,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { run: true, read: true } }, async function runKillAfterStatus() { const p = Deno.run({ @@ -461,7 +465,7 @@ unitTest( }, ); -unitTest(function killPermissions() { +Deno.test({ permissions: { run: false } }, 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 @@ -471,7 +475,7 @@ unitTest(function killPermissions() { }, Deno.errors.PermissionDenied); }); -unitTest( +Deno.test( { ignore: Deno.build.os !== "windows", permissions: { run: true } }, function negativePidInvalidWindows() { assertThrows(() => { @@ -480,7 +484,7 @@ unitTest( }, ); -unitTest( +Deno.test( { ignore: Deno.build.os !== "windows", permissions: { run: true } }, function invalidSignalNameWindows() { assertThrows(() => { @@ -489,7 +493,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { run: true, read: true } }, async function killSuccess() { const p = Deno.run({ @@ -514,7 +518,7 @@ unitTest( }, ); -unitTest({ permissions: { run: true, read: true } }, function killFailed() { +Deno.test({ permissions: { run: true, read: true } }, function killFailed() { const p = Deno.run({ cmd: [Deno.execPath(), "eval", "setTimeout(() => {}, 10000)"], }); @@ -529,7 +533,7 @@ unitTest({ permissions: { run: true, read: true } }, function killFailed() { p.close(); }); -unitTest( +Deno.test( { permissions: { run: true, read: true, env: true } }, async function clearEnv(): Promise { const p = Deno.run({ @@ -557,7 +561,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { run: true, read: true }, ignore: Deno.build.os === "windows", @@ -588,7 +592,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { run: true, read: true }, ignore: Deno.build.os === "windows", diff --git a/cli/tests/unit/progressevent_test.ts b/cli/tests/unit/progressevent_test.ts index 4d6b4c08f8..271180d88b 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"; +import { assertEquals } from "./test_util.ts"; -unitTest(function progressEventConstruct() { +Deno.test(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 686c38af34..58e4c4d2d1 100644 --- a/cli/tests/unit/read_dir_test.ts +++ b/cli/tests/unit/read_dir_test.ts @@ -5,7 +5,6 @@ import { assertRejects, assertThrows, pathToAbsoluteFileUrl, - unitTest, } from "./test_util.ts"; function assertSameContent(files: Deno.DirEntry[]) { @@ -21,25 +20,25 @@ function assertSameContent(files: Deno.DirEntry[]) { assertEquals(counter, 1); } -unitTest({ permissions: { read: true } }, function readDirSyncSuccess() { +Deno.test({ permissions: { read: true } }, function readDirSyncSuccess() { const files = [...Deno.readDirSync("cli/tests/testdata")]; assertSameContent(files); }); -unitTest({ permissions: { read: true } }, function readDirSyncWithUrl() { +Deno.test({ permissions: { read: true } }, function readDirSyncWithUrl() { const files = [ ...Deno.readDirSync(pathToAbsoluteFileUrl("cli/tests/testdata")), ]; assertSameContent(files); }); -unitTest({ permissions: { read: false } }, function readDirSyncPerm() { +Deno.test({ permissions: { read: false } }, function readDirSyncPerm() { assertThrows(() => { Deno.readDirSync("tests/"); }, Deno.errors.PermissionDenied); }); -unitTest({ permissions: { read: true } }, function readDirSyncNotDir() { +Deno.test({ permissions: { read: true } }, function readDirSyncNotDir() { assertThrows( () => { Deno.readDirSync("cli/tests/testdata/fixture.json"); @@ -49,7 +48,7 @@ unitTest({ permissions: { read: true } }, function readDirSyncNotDir() { ); }); -unitTest({ permissions: { read: true } }, function readDirSyncNotFound() { +Deno.test({ permissions: { read: true } }, function readDirSyncNotFound() { assertThrows( () => { Deno.readDirSync("bad_dir_name"); @@ -59,7 +58,7 @@ unitTest({ permissions: { read: true } }, function readDirSyncNotFound() { ); }); -unitTest({ permissions: { read: true } }, async function readDirSuccess() { +Deno.test({ permissions: { read: true } }, async function readDirSuccess() { const files = []; for await (const dirEntry of Deno.readDir("cli/tests/testdata")) { files.push(dirEntry); @@ -67,7 +66,7 @@ unitTest({ permissions: { read: true } }, async function readDirSuccess() { assertSameContent(files); }); -unitTest({ permissions: { read: true } }, async function readDirWithUrl() { +Deno.test({ permissions: { read: true } }, async function readDirWithUrl() { const files = []; for await ( const dirEntry of Deno.readDir(pathToAbsoluteFileUrl("cli/tests/testdata")) @@ -77,13 +76,13 @@ unitTest({ permissions: { read: true } }, async function readDirWithUrl() { assertSameContent(files); }); -unitTest({ permissions: { read: false } }, async function readDirPerm() { +Deno.test({ permissions: { read: false } }, async function readDirPerm() { await assertRejects(async () => { await Deno.readDir("tests/")[Symbol.asyncIterator]().next(); }, Deno.errors.PermissionDenied); }); -unitTest( +Deno.test( { permissions: { read: true }, ignore: Deno.build.os == "windows" }, async function readDirDevFd(): Promise< void @@ -94,7 +93,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true }, ignore: Deno.build.os == "windows" }, function readDirDevFdSync() { for (const _ of Deno.readDirSync("/dev/fd")) { @@ -103,7 +102,7 @@ unitTest( }, ); -unitTest({ permissions: { read: true } }, async function readDirNotFound() { +Deno.test({ permissions: { read: true } }, async function readDirNotFound() { await assertRejects( async () => { await Deno.readDir("bad_dir_name")[Symbol.asyncIterator]().next(); diff --git a/cli/tests/unit/read_file_test.ts b/cli/tests/unit/read_file_test.ts index 90a6abc2c5..df3161f0b2 100644 --- a/cli/tests/unit/read_file_test.ts +++ b/cli/tests/unit/read_file_test.ts @@ -6,10 +6,9 @@ import { assertRejects, assertThrows, pathToAbsoluteFileUrl, - unitTest, } from "./test_util.ts"; -unitTest({ permissions: { read: true } }, function readFileSyncSuccess() { +Deno.test({ permissions: { read: true } }, function readFileSyncSuccess() { const data = Deno.readFileSync("cli/tests/testdata/fixture.json"); assert(data.byteLength > 0); const decoder = new TextDecoder("utf-8"); @@ -18,7 +17,7 @@ unitTest({ permissions: { read: true } }, function readFileSyncSuccess() { assertEquals(pkg.name, "deno"); }); -unitTest({ permissions: { read: true } }, function readFileSyncUrl() { +Deno.test({ permissions: { read: true } }, function readFileSyncUrl() { const data = Deno.readFileSync( pathToAbsoluteFileUrl("cli/tests/testdata/fixture.json"), ); @@ -29,19 +28,19 @@ unitTest({ permissions: { read: true } }, function readFileSyncUrl() { assertEquals(pkg.name, "deno"); }); -unitTest({ permissions: { read: false } }, function readFileSyncPerm() { +Deno.test({ permissions: { read: false } }, function readFileSyncPerm() { assertThrows(() => { Deno.readFileSync("cli/tests/testdata/fixture.json"); }, Deno.errors.PermissionDenied); }); -unitTest({ permissions: { read: true } }, function readFileSyncNotFound() { +Deno.test({ permissions: { read: true } }, function readFileSyncNotFound() { assertThrows(() => { Deno.readFileSync("bad_filename"); }, Deno.errors.NotFound); }); -unitTest({ permissions: { read: true } }, async function readFileUrl() { +Deno.test({ permissions: { read: true } }, async function readFileUrl() { const data = await Deno.readFile( pathToAbsoluteFileUrl("cli/tests/testdata/fixture.json"), ); @@ -52,7 +51,7 @@ unitTest({ permissions: { read: true } }, async function readFileUrl() { assertEquals(pkg.name, "deno"); }); -unitTest({ permissions: { read: true } }, async function readFileSuccess() { +Deno.test({ permissions: { read: true } }, async function readFileSuccess() { const data = await Deno.readFile("cli/tests/testdata/fixture.json"); assert(data.byteLength > 0); const decoder = new TextDecoder("utf-8"); @@ -61,19 +60,19 @@ unitTest({ permissions: { read: true } }, async function readFileSuccess() { assertEquals(pkg.name, "deno"); }); -unitTest({ permissions: { read: false } }, async function readFilePerm() { +Deno.test({ permissions: { read: false } }, async function readFilePerm() { await assertRejects(async () => { await Deno.readFile("cli/tests/testdata/fixture.json"); }, Deno.errors.PermissionDenied); }); -unitTest({ permissions: { read: true } }, function readFileSyncLoop() { +Deno.test({ permissions: { read: true } }, function readFileSyncLoop() { for (let i = 0; i < 256; i++) { Deno.readFileSync("cli/tests/testdata/fixture.json"); } }); -unitTest( +Deno.test( { permissions: { read: true } }, async function readFileDoesNotLeakResources() { const resourcesBefore = Deno.resources(); @@ -82,7 +81,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true } }, function readFileSyncDoesNotLeakResources() { const resourcesBefore = Deno.resources(); @@ -91,7 +90,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true } }, async function readFileWithAbortSignal() { const ac = new AbortController(); @@ -104,7 +103,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true }, ignore: Deno.build.os !== "linux" }, async function readFileProcFs() { const data = await Deno.readFile("/proc/self/stat"); @@ -112,7 +111,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function readFileExtendedDuringRead() { // Write 128MB file @@ -131,7 +130,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function readFile0LengthExtendedDuringRead() { // Write 0 byte file diff --git a/cli/tests/unit/read_link_test.ts b/cli/tests/unit/read_link_test.ts index d59dae2b82..6946c00f58 100644 --- a/cli/tests/unit/read_link_test.ts +++ b/cli/tests/unit/read_link_test.ts @@ -4,10 +4,9 @@ import { assertRejects, assertThrows, pathToAbsoluteFileUrl, - unitTest, } from "./test_util.ts"; -unitTest( +Deno.test( { permissions: { write: true, read: true } }, function readLinkSyncSuccess() { const testDir = Deno.makeTempDirSync(); @@ -22,7 +21,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { write: true, read: true } }, function readLinkSyncUrlSuccess() { const testDir = Deno.makeTempDirSync(); @@ -37,13 +36,13 @@ unitTest( }, ); -unitTest({ permissions: { read: false } }, function readLinkSyncPerm() { +Deno.test({ permissions: { read: false } }, function readLinkSyncPerm() { assertThrows(() => { Deno.readLinkSync("/symlink"); }, Deno.errors.PermissionDenied); }); -unitTest({ permissions: { read: true } }, function readLinkSyncNotFound() { +Deno.test({ permissions: { read: true } }, function readLinkSyncNotFound() { assertThrows( () => { Deno.readLinkSync("bad_filename"); @@ -53,7 +52,7 @@ unitTest({ permissions: { read: true } }, function readLinkSyncNotFound() { ); }); -unitTest( +Deno.test( { permissions: { write: true, read: true } }, async function readLinkSuccess() { const testDir = Deno.makeTempDirSync(); @@ -68,7 +67,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { write: true, read: true } }, async function readLinkUrlSuccess() { const testDir = Deno.makeTempDirSync(); @@ -83,13 +82,13 @@ unitTest( }, ); -unitTest({ permissions: { read: false } }, async function readLinkPerm() { +Deno.test({ permissions: { read: false } }, async function readLinkPerm() { await assertRejects(async () => { await Deno.readLink("/symlink"); }, Deno.errors.PermissionDenied); }); -unitTest({ permissions: { read: true } }, async function readLinkNotFound() { +Deno.test({ permissions: { read: true } }, async function readLinkNotFound() { await assertRejects( async () => { await Deno.readLink("bad_filename"); diff --git a/cli/tests/unit/read_text_file_test.ts b/cli/tests/unit/read_text_file_test.ts index 1447fd028a..6e7dce73ed 100644 --- a/cli/tests/unit/read_text_file_test.ts +++ b/cli/tests/unit/read_text_file_test.ts @@ -4,17 +4,16 @@ import { assertRejects, assertThrows, pathToAbsoluteFileUrl, - unitTest, } from "./test_util.ts"; -unitTest({ permissions: { read: true } }, function readTextFileSyncSuccess() { +Deno.test({ permissions: { read: true } }, function readTextFileSyncSuccess() { const data = Deno.readTextFileSync("cli/tests/testdata/fixture.json"); assert(data.length > 0); const pkg = JSON.parse(data); assertEquals(pkg.name, "deno"); }); -unitTest({ permissions: { read: true } }, function readTextFileSyncByUrl() { +Deno.test({ permissions: { read: true } }, function readTextFileSyncByUrl() { const data = Deno.readTextFileSync( pathToAbsoluteFileUrl("cli/tests/testdata/fixture.json"), ); @@ -23,19 +22,19 @@ unitTest({ permissions: { read: true } }, function readTextFileSyncByUrl() { assertEquals(pkg.name, "deno"); }); -unitTest({ permissions: { read: false } }, function readTextFileSyncPerm() { +Deno.test({ permissions: { read: false } }, function readTextFileSyncPerm() { assertThrows(() => { Deno.readTextFileSync("cli/tests/testdata/fixture.json"); }, Deno.errors.PermissionDenied); }); -unitTest({ permissions: { read: true } }, function readTextFileSyncNotFound() { +Deno.test({ permissions: { read: true } }, function readTextFileSyncNotFound() { assertThrows(() => { Deno.readTextFileSync("bad_filename"); }, Deno.errors.NotFound); }); -unitTest( +Deno.test( { permissions: { read: true } }, async function readTextFileSuccess() { const data = await Deno.readTextFile("cli/tests/testdata/fixture.json"); @@ -45,7 +44,7 @@ unitTest( }, ); -unitTest({ permissions: { read: true } }, async function readTextFileByUrl() { +Deno.test({ permissions: { read: true } }, async function readTextFileByUrl() { const data = await Deno.readTextFile( pathToAbsoluteFileUrl("cli/tests/testdata/fixture.json"), ); @@ -54,19 +53,19 @@ unitTest({ permissions: { read: true } }, async function readTextFileByUrl() { assertEquals(pkg.name, "deno"); }); -unitTest({ permissions: { read: false } }, async function readTextFilePerm() { +Deno.test({ permissions: { read: false } }, async function readTextFilePerm() { await assertRejects(async () => { await Deno.readTextFile("cli/tests/testdata/fixture.json"); }, Deno.errors.PermissionDenied); }); -unitTest({ permissions: { read: true } }, function readTextFileSyncLoop() { +Deno.test({ permissions: { read: true } }, function readTextFileSyncLoop() { for (let i = 0; i < 256; i++) { Deno.readTextFileSync("cli/tests/testdata/fixture.json"); } }); -unitTest( +Deno.test( { permissions: { read: true } }, async function readTextFileDoesNotLeakResources() { const resourcesBefore = Deno.resources(); @@ -75,7 +74,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true } }, function readTextFileSyncDoesNotLeakResources() { const resourcesBefore = Deno.resources(); @@ -84,7 +83,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true } }, async function readTextFileWithAbortSignal() { const ac = new AbortController(); @@ -97,7 +96,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true }, ignore: Deno.build.os !== "linux" }, async function readTextFileProcFs() { const data = await Deno.readTextFile("/proc/self/stat"); diff --git a/cli/tests/unit/real_path_test.ts b/cli/tests/unit/real_path_test.ts index ee4ad23ec8..c9e64e16fc 100644 --- a/cli/tests/unit/real_path_test.ts +++ b/cli/tests/unit/real_path_test.ts @@ -6,10 +6,9 @@ import { assertRejects, assertThrows, pathToAbsoluteFileUrl, - unitTest, } from "./test_util.ts"; -unitTest({ permissions: { read: true } }, function realPathSyncSuccess() { +Deno.test({ permissions: { read: true } }, function realPathSyncSuccess() { const relative = "cli/tests/testdata/fixture.json"; const realPath = Deno.realPathSync(relative); if (Deno.build.os !== "windows") { @@ -21,13 +20,13 @@ unitTest({ permissions: { read: true } }, function realPathSyncSuccess() { } }); -unitTest({ permissions: { read: true } }, function realPathSyncUrl() { +Deno.test({ permissions: { read: true } }, function realPathSyncUrl() { const relative = "cli/tests/testdata/fixture.json"; const url = pathToAbsoluteFileUrl(relative); assertEquals(Deno.realPathSync(relative), Deno.realPathSync(url)); }); -unitTest( +Deno.test( { permissions: { read: true, write: true }, }, @@ -48,19 +47,19 @@ unitTest( }, ); -unitTest({ permissions: { read: false } }, function realPathSyncPerm() { +Deno.test({ permissions: { read: false } }, function realPathSyncPerm() { assertThrows(() => { Deno.realPathSync("some_file"); }, Deno.errors.PermissionDenied); }); -unitTest({ permissions: { read: true } }, function realPathSyncNotFound() { +Deno.test({ permissions: { read: true } }, function realPathSyncNotFound() { assertThrows(() => { Deno.realPathSync("bad_filename"); }, Deno.errors.NotFound); }); -unitTest({ permissions: { read: true } }, async function realPathSuccess() { +Deno.test({ permissions: { read: true } }, async function realPathSuccess() { const relativePath = "cli/tests/testdata/fixture.json"; const realPath = await Deno.realPath(relativePath); if (Deno.build.os !== "windows") { @@ -72,7 +71,7 @@ unitTest({ permissions: { read: true } }, async function realPathSuccess() { } }); -unitTest( +Deno.test( { permissions: { read: true } }, async function realPathUrl() { const relative = "cli/tests/testdata/fixture.json"; @@ -81,7 +80,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true }, }, @@ -102,13 +101,13 @@ unitTest( }, ); -unitTest({ permissions: { read: false } }, async function realPathPerm() { +Deno.test({ permissions: { read: false } }, async function realPathPerm() { await assertRejects(async () => { await Deno.realPath("some_file"); }, Deno.errors.PermissionDenied); }); -unitTest({ permissions: { read: true } }, async function realPathNotFound() { +Deno.test({ permissions: { read: true } }, async function realPathNotFound() { await assertRejects(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 5ea265ea8c..69ba4de8fb 100644 --- a/cli/tests/unit/remove_test.ts +++ b/cli/tests/unit/remove_test.ts @@ -1,9 +1,9 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -import { assert, assertRejects, assertThrows, unitTest } from "./test_util.ts"; +import { assert, assertRejects, assertThrows } from "./test_util.ts"; const REMOVE_METHODS = ["remove", "removeSync"] as const; -unitTest( +Deno.test( { permissions: { write: true, read: true } }, async function removeDirSuccess() { for (const method of REMOVE_METHODS) { @@ -21,7 +21,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { write: true, read: true } }, async function removeFileSuccess() { for (const method of REMOVE_METHODS) { @@ -41,7 +41,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { write: true, read: true } }, async function removeFileByUrl() { for (const method of REMOVE_METHODS) { @@ -66,7 +66,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { write: true, read: true } }, async function removeFail() { for (const method of REMOVE_METHODS) { @@ -101,7 +101,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { write: true, read: true } }, async function removeDanglingSymlinkSuccess() { for (const method of REMOVE_METHODS) { @@ -123,7 +123,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { write: true, read: true } }, async function removeValidSymlinkSuccess() { for (const method of REMOVE_METHODS) { @@ -149,7 +149,7 @@ unitTest( }, ); -unitTest({ permissions: { write: false } }, async function removePerm() { +Deno.test({ permissions: { write: false } }, async function removePerm() { for (const method of REMOVE_METHODS) { await assertRejects(async () => { await Deno[method]("/baddir"); @@ -157,7 +157,7 @@ unitTest({ permissions: { write: false } }, async function removePerm() { } }); -unitTest( +Deno.test( { permissions: { write: true, read: true } }, async function removeAllDirSuccess() { for (const method of REMOVE_METHODS) { @@ -194,7 +194,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { write: true, read: true } }, async function removeAllFileSuccess() { for (const method of REMOVE_METHODS) { @@ -215,7 +215,7 @@ unitTest( }, ); -unitTest({ permissions: { write: true } }, async function removeAllFail() { +Deno.test({ permissions: { write: true } }, async function removeAllFail() { for (const method of REMOVE_METHODS) { // NON-EXISTENT DIRECTORY/FILE await assertRejects( @@ -229,7 +229,7 @@ unitTest({ permissions: { write: true } }, async function removeAllFail() { } }); -unitTest({ permissions: { write: false } }, async function removeAllPerm() { +Deno.test({ permissions: { write: false } }, async function removeAllPerm() { for (const method of REMOVE_METHODS) { await assertRejects(async () => { await Deno[method]("/baddir", { recursive: true }); @@ -237,7 +237,7 @@ unitTest({ permissions: { write: false } }, async function removeAllPerm() { } }); -unitTest( +Deno.test( { ignore: Deno.build.os === "windows", permissions: { write: true, read: true }, @@ -259,7 +259,7 @@ unitTest( ); if (Deno.build.os === "windows") { - unitTest( + Deno.test( { permissions: { run: true, write: true, read: true } }, async function removeFileSymlink() { const symlink = Deno.run({ @@ -276,7 +276,7 @@ if (Deno.build.os === "windows") { }, ); - unitTest( + Deno.test( { permissions: { run: true, write: true, read: true } }, async function removeDirSymlink() { const symlink = Deno.run({ diff --git a/cli/tests/unit/rename_test.ts b/cli/tests/unit/rename_test.ts index a2291dd1c5..49a572a01f 100644 --- a/cli/tests/unit/rename_test.ts +++ b/cli/tests/unit/rename_test.ts @@ -4,7 +4,6 @@ import { assertEquals, assertThrows, pathToAbsoluteFileUrl, - unitTest, } from "./test_util.ts"; function assertMissing(path: string) { @@ -33,7 +32,7 @@ function assertDirectory(path: string, mode?: number) { } } -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function renameSyncSuccess() { const testDir = Deno.makeTempDirSync(); @@ -46,7 +45,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function renameSyncWithURL() { const testDir = Deno.makeTempDirSync(); @@ -62,7 +61,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: false, write: true } }, function renameSyncReadPerm() { assertThrows(() => { @@ -73,7 +72,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: false } }, function renameSyncWritePerm() { assertThrows(() => { @@ -84,7 +83,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function renameSuccess() { const testDir = Deno.makeTempDirSync(); @@ -97,7 +96,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function renameWithURL() { const testDir = Deno.makeTempDirSync(); @@ -125,7 +124,7 @@ function writeFileString(filename: string, s: string) { Deno.writeFileSync(filename, data, { mode: 0o666 }); } -unitTest( +Deno.test( { ignore: Deno.build.os === "windows", permissions: { read: true, write: true }, @@ -210,7 +209,7 @@ unitTest( }, ); -unitTest( +Deno.test( { ignore: Deno.build.os !== "windows", permissions: { read: true, write: true }, diff --git a/cli/tests/unit/request_test.ts b/cli/tests/unit/request_test.ts index 8f31d7d5d9..b4f20a2026 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"; +import { assertEquals, assertStringIncludes } from "./test_util.ts"; -unitTest(async function fromInit() { +Deno.test(async function fromInit() { const req = new Request("http://foo/", { body: "ahoyhoy", method: "POST", @@ -15,7 +15,7 @@ unitTest(async function fromInit() { assertEquals(req.headers.get("test-header"), "value"); }); -unitTest(function requestNonString() { +Deno.test(function requestNonString() { const nonString = { toString() { return "http://foo/"; @@ -26,18 +26,18 @@ unitTest(function requestNonString() { assertEquals(new Request(nonString).url, "http://foo/"); }); -unitTest(function methodNonString() { +Deno.test(function methodNonString() { assertEquals(new Request("http://foo/", { method: undefined }).method, "GET"); }); -unitTest(function requestRelativeUrl() { +Deno.test(function requestRelativeUrl() { assertEquals( new Request("relative-url").url, "http://js-unit-tests/foo/relative-url", ); }); -unitTest(async function cloneRequestBodyStream() { +Deno.test(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() { assertEquals(b1, b2); }); -unitTest(function customInspectFunction() { +Deno.test(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 368f7f990c..fffd940db9 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"; +import { assert, assertEquals, assertThrows } from "./test_util.ts"; -unitTest(function resourcesCloseBadArgs() { +Deno.test(function resourcesCloseBadArgs() { assertThrows(() => { Deno.close((null as unknown) as number); }, TypeError); }); -unitTest(function resourcesStdio() { +Deno.test(function resourcesStdio() { const res = Deno.resources(); assertEquals(res[0], "stdin"); @@ -15,7 +15,7 @@ unitTest(function resourcesStdio() { assertEquals(res[2], "stderr"); }); -unitTest({ permissions: { net: true } }, async function resourcesNet() { +Deno.test({ permissions: { net: true } }, async function resourcesNet() { const listener = Deno.listen({ port: 4501 }); const dialerConn = await Deno.connect({ port: 4501 }); const listenerConn = await listener.accept(); @@ -35,7 +35,7 @@ unitTest({ permissions: { net: true } }, async function resourcesNet() { listener.close(); }); -unitTest({ permissions: { read: true } }, async function resourcesFile() { +Deno.test({ permissions: { read: true } }, async function resourcesFile() { const resourcesBefore = Deno.resources(); const f = await Deno.open("cli/tests/testdata/hello.txt"); const resourcesAfter = Deno.resources(); diff --git a/cli/tests/unit/response_test.ts b/cli/tests/unit/response_test.ts index 9c6da1c5f9..3d3fc07ef8 100644 --- a/cli/tests/unit/response_test.ts +++ b/cli/tests/unit/response_test.ts @@ -4,10 +4,9 @@ import { assertEquals, assertStringIncludes, assertThrows, - unitTest, } from "./test_util.ts"; -unitTest(async function responseText() { +Deno.test(async function responseText() { const response = new Response("hello world"); const textPromise = response.text(); assert(textPromise instanceof Promise); @@ -16,7 +15,7 @@ unitTest(async function responseText() { assertEquals(text, "hello world"); }); -unitTest(async function responseArrayBuffer() { +Deno.test(async function responseArrayBuffer() { const response = new Response(new Uint8Array([1, 2, 3])); const arrayBufferPromise = response.arrayBuffer(); assert(arrayBufferPromise instanceof Promise); @@ -25,7 +24,7 @@ unitTest(async function responseArrayBuffer() { assertEquals(new Uint8Array(arrayBuffer), new Uint8Array([1, 2, 3])); }); -unitTest(async function responseJson() { +Deno.test(async function responseJson() { const response = new Response('{"hello": "world"}'); const jsonPromise = response.json(); assert(jsonPromise instanceof Promise); @@ -34,7 +33,7 @@ unitTest(async function responseJson() { assertEquals(json, { hello: "world" }); }); -unitTest(async function responseBlob() { +Deno.test(async function responseBlob() { const response = new Response(new Uint8Array([1, 2, 3])); const blobPromise = response.blob(); assert(blobPromise instanceof Promise); @@ -44,7 +43,7 @@ unitTest(async function responseBlob() { assertEquals(await blob.arrayBuffer(), new Uint8Array([1, 2, 3]).buffer); }); -unitTest(async function responseFormData() { +Deno.test(async function responseFormData() { const input = new FormData(); input.append("hello", "world"); const response = new Response(input); @@ -57,7 +56,7 @@ unitTest(async function responseFormData() { assertEquals([...formData], [...input]); }); -unitTest(function responseInvalidInit() { +Deno.test(function responseInvalidInit() { // deno-lint-ignore ban-ts-comment // @ts-expect-error assertThrows(() => new Response("", 0)); @@ -67,14 +66,14 @@ unitTest(function responseInvalidInit() { assertThrows(() => new Response("", { status: null })); }); -unitTest(function responseNullInit() { +Deno.test(function responseNullInit() { // deno-lint-ignore ban-ts-comment // @ts-expect-error const response = new Response("", null); assertEquals(response.status, 200); }); -unitTest(function customInspectFunction() { +Deno.test(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 d567b69fc8..31562c99a6 100644 --- a/cli/tests/unit/signal_test.ts +++ b/cli/tests/unit/signal_test.ts @@ -1,13 +1,7 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -import { - assertEquals, - assertThrows, - deferred, - delay, - unitTest, -} from "./test_util.ts"; +import { assertEquals, assertThrows, deferred, delay } from "./test_util.ts"; -unitTest( +Deno.test( { ignore: Deno.build.os !== "windows" }, function signalsNotImplemented() { assertThrows( @@ -97,7 +91,7 @@ unitTest( }, ); -unitTest( +Deno.test( { ignore: Deno.build.os === "windows", permissions: { run: true }, @@ -125,7 +119,7 @@ unitTest( }, ); -unitTest( +Deno.test( { ignore: Deno.build.os === "windows", permissions: { run: true }, @@ -173,7 +167,7 @@ unitTest( ); // This tests that pending op_signal_poll doesn't block the runtime from exiting the process. -unitTest( +Deno.test( { ignore: Deno.build.os === "windows", permissions: { run: true, read: true }, @@ -193,7 +187,7 @@ unitTest( }, ); -unitTest( +Deno.test( { ignore: Deno.build.os === "windows", permissions: { run: true }, diff --git a/cli/tests/unit/stat_test.ts b/cli/tests/unit/stat_test.ts index eefbab2c5c..2ed3dd3b3d 100644 --- a/cli/tests/unit/stat_test.ts +++ b/cli/tests/unit/stat_test.ts @@ -5,10 +5,9 @@ import { assertRejects, assertThrows, pathToAbsoluteFileUrl, - unitTest, } from "./test_util.ts"; -unitTest({ permissions: { read: true } }, function fstatSyncSuccess() { +Deno.test({ permissions: { read: true } }, function fstatSyncSuccess() { const file = Deno.openSync("README.md"); const fileInfo = Deno.fstatSync(file.rid); assert(fileInfo.isFile); @@ -23,7 +22,7 @@ unitTest({ permissions: { read: true } }, function fstatSyncSuccess() { Deno.close(file.rid); }); -unitTest({ permissions: { read: true } }, async function fstatSuccess() { +Deno.test({ permissions: { read: true } }, async function fstatSuccess() { const file = await Deno.open("README.md"); const fileInfo = await Deno.fstat(file.rid); assert(fileInfo.isFile); @@ -38,7 +37,7 @@ unitTest({ permissions: { read: true } }, async function fstatSuccess() { Deno.close(file.rid); }); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function statSyncSuccess() { const readmeInfo = Deno.statSync("README.md"); @@ -101,13 +100,13 @@ unitTest( }, ); -unitTest({ permissions: { read: false } }, function statSyncPerm() { +Deno.test({ permissions: { read: false } }, function statSyncPerm() { assertThrows(() => { Deno.statSync("README.md"); }, Deno.errors.PermissionDenied); }); -unitTest({ permissions: { read: true } }, function statSyncNotFound() { +Deno.test({ permissions: { read: true } }, function statSyncNotFound() { assertThrows( () => { Deno.statSync("bad_file_name"); @@ -117,7 +116,7 @@ unitTest({ permissions: { read: true } }, function statSyncNotFound() { ); }); -unitTest({ permissions: { read: true } }, function lstatSyncSuccess() { +Deno.test({ permissions: { read: true } }, function lstatSyncSuccess() { const packageInfo = Deno.lstatSync("README.md"); assert(packageInfo.isFile); assert(!packageInfo.isSymlink); @@ -145,13 +144,13 @@ unitTest({ permissions: { read: true } }, function lstatSyncSuccess() { assert(!coreInfoByUrl.isSymlink); }); -unitTest({ permissions: { read: false } }, function lstatSyncPerm() { +Deno.test({ permissions: { read: false } }, function lstatSyncPerm() { assertThrows(() => { Deno.lstatSync("hello.txt"); }, Deno.errors.PermissionDenied); }); -unitTest({ permissions: { read: true } }, function lstatSyncNotFound() { +Deno.test({ permissions: { read: true } }, function lstatSyncNotFound() { assertThrows( () => { Deno.lstatSync("bad_file_name"); @@ -161,7 +160,7 @@ unitTest({ permissions: { read: true } }, function lstatSyncNotFound() { ); }); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function statSuccess() { const readmeInfo = await Deno.stat("README.md"); @@ -227,13 +226,13 @@ unitTest( }, ); -unitTest({ permissions: { read: false } }, async function statPerm() { +Deno.test({ permissions: { read: false } }, async function statPerm() { await assertRejects(async () => { await Deno.stat("README.md"); }, Deno.errors.PermissionDenied); }); -unitTest({ permissions: { read: true } }, async function statNotFound() { +Deno.test({ permissions: { read: true } }, async function statNotFound() { await assertRejects( async () => { await Deno.stat("bad_file_name"); @@ -243,7 +242,7 @@ unitTest({ permissions: { read: true } }, async function statNotFound() { ); }); -unitTest({ permissions: { read: true } }, async function lstatSuccess() { +Deno.test({ permissions: { read: true } }, async function lstatSuccess() { const readmeInfo = await Deno.lstat("README.md"); assert(readmeInfo.isFile); assert(!readmeInfo.isSymlink); @@ -271,13 +270,13 @@ unitTest({ permissions: { read: true } }, async function lstatSuccess() { assert(!coreInfoByUrl.isSymlink); }); -unitTest({ permissions: { read: false } }, async function lstatPerm() { +Deno.test({ permissions: { read: false } }, async function lstatPerm() { await assertRejects(async () => { await Deno.lstat("README.md"); }, Deno.errors.PermissionDenied); }); -unitTest({ permissions: { read: true } }, async function lstatNotFound() { +Deno.test({ permissions: { read: true } }, async function lstatNotFound() { await assertRejects( async () => { await Deno.lstat("bad_file_name"); @@ -287,7 +286,7 @@ unitTest({ permissions: { read: true } }, async function lstatNotFound() { ); }); -unitTest( +Deno.test( { ignore: Deno.build.os !== "windows", permissions: { read: true, write: true }, @@ -311,7 +310,7 @@ unitTest( }, ); -unitTest( +Deno.test( { ignore: Deno.build.os === "windows", permissions: { read: true, write: true }, diff --git a/cli/tests/unit/stdio_test.ts b/cli/tests/unit/stdio_test.ts index 628f3f5613..52cda3b8bc 100644 --- a/cli/tests/unit/stdio_test.ts +++ b/cli/tests/unit/stdio_test.ts @@ -1,32 +1,32 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -import { assertEquals, unitTest } from "./test_util.ts"; +import { assertEquals } from "./test_util.ts"; -unitTest(async function stdioStdinRead() { +Deno.test(async function stdioStdinRead() { const nread = await Deno.stdin.read(new Uint8Array(0)); assertEquals(nread, 0); }); -unitTest(function stdioStdinReadSync() { +Deno.test(function stdioStdinReadSync() { const nread = Deno.stdin.readSync(new Uint8Array(0)); assertEquals(nread, 0); }); -unitTest(async function stdioStdoutWrite() { +Deno.test(async function stdioStdoutWrite() { const nwritten = await Deno.stdout.write(new Uint8Array(0)); assertEquals(nwritten, 0); }); -unitTest(function stdioStdoutWriteSync() { +Deno.test(function stdioStdoutWriteSync() { const nwritten = Deno.stdout.writeSync(new Uint8Array(0)); assertEquals(nwritten, 0); }); -unitTest(async function stdioStderrWrite() { +Deno.test(async function stdioStderrWrite() { const nwritten = await Deno.stderr.write(new Uint8Array(0)); assertEquals(nwritten, 0); }); -unitTest(function stdioStderrWriteSync() { +Deno.test(function stdioStderrWriteSync() { const nwritten = Deno.stderr.writeSync(new Uint8Array(0)); assertEquals(nwritten, 0); }); diff --git a/cli/tests/unit/streams_deprecated.ts b/cli/tests/unit/streams_deprecated.ts index 77750072c9..a3c81777d1 100644 --- a/cli/tests/unit/streams_deprecated.ts +++ b/cli/tests/unit/streams_deprecated.ts @@ -1,7 +1,7 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -import { assertEquals, unitTest } from "./test_util.ts"; +import { assertEquals } from "./test_util.ts"; -unitTest(async function symlinkSyncPerm() { +Deno.test(async function symlinkSyncPerm() { const rs = new ReadableStream({ start(controller) { controller.enqueue("hello "); diff --git a/cli/tests/unit/symlink_test.ts b/cli/tests/unit/symlink_test.ts index 782b031754..47aecacc89 100644 --- a/cli/tests/unit/symlink_test.ts +++ b/cli/tests/unit/symlink_test.ts @@ -4,10 +4,9 @@ import { assertRejects, assertThrows, pathToAbsoluteFileUrl, - unitTest, } from "./test_util.ts"; -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function symlinkSyncSuccess() { const testDir = Deno.makeTempDirSync(); @@ -22,7 +21,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function symlinkSyncURL() { const testDir = Deno.makeTempDirSync(); @@ -40,13 +39,16 @@ unitTest( }, ); -unitTest(function symlinkSyncPerm() { - assertThrows(() => { - Deno.symlinkSync("oldbaddir", "newbaddir"); - }, Deno.errors.PermissionDenied); -}); +Deno.test( + { permissions: { read: false, write: false } }, + function symlinkSyncPerm() { + assertThrows(() => { + Deno.symlinkSync("oldbaddir", "newbaddir"); + }, Deno.errors.PermissionDenied); + }, +); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function symlinkSyncAlreadyExist() { const existingFile = Deno.makeTempFileSync(); @@ -61,7 +63,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function symlinkSuccess() { const testDir = Deno.makeTempDirSync(); @@ -76,7 +78,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function symlinkURL() { const testDir = Deno.makeTempDirSync(); @@ -94,7 +96,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function symlinkAlreadyExist() { const existingFile = Deno.makeTempFileSync(); @@ -109,7 +111,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: ["."] } }, async function symlinkNoFullWritePermissions() { await assertRejects( @@ -123,7 +125,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: ["."], write: true } }, async function symlinkNoFullReadPermissions() { await assertRejects( diff --git a/cli/tests/unit/sync_test.ts b/cli/tests/unit/sync_test.ts index 65c2a97647..4e01000ad9 100644 --- a/cli/tests/unit/sync_test.ts +++ b/cli/tests/unit/sync_test.ts @@ -1,7 +1,7 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -import { assertEquals, unitTest } from "./test_util.ts"; +import { assertEquals } from "./test_util.ts"; -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function fdatasyncSyncSuccess() { const filename = Deno.makeTempDirSync() + "/test_fdatasyncSync.txt"; @@ -19,7 +19,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function fdatasyncSuccess() { const filename = (await Deno.makeTempDir()) + "/test_fdatasync.txt"; @@ -37,7 +37,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function fsyncSyncSuccess() { const filename = Deno.makeTempDirSync() + "/test_fsyncSync.txt"; @@ -55,7 +55,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function fsyncSuccess() { const filename = (await Deno.makeTempDir()) + "/test_fsync.txt"; diff --git a/cli/tests/unit/test_util.ts b/cli/tests/unit/test_util.ts index 65d23af650..80af8fdfc7 100644 --- a/cli/tests/unit/test_util.ts +++ b/cli/tests/unit/test_util.ts @@ -23,72 +23,6 @@ export { delay } from "../../../test_util/std/async/delay.ts"; export { readLines } from "../../../test_util/std/io/bufio.ts"; export { parse as parseArgs } from "../../../test_util/std/flags/mod.ts"; -interface UnitTestPermissions { - env?: "inherit" | boolean | string[]; - hrtime?: "inherit" | boolean; - net?: "inherit" | boolean | string[]; - ffi?: "inherit" | boolean; - read?: "inherit" | boolean | Array; - run?: "inherit" | boolean | Array; - write?: "inherit" | boolean | Array; -} - -interface UnitTestOptions { - ignore?: boolean; - only?: boolean; - permissions?: UnitTestPermissions; -} - -type TestFunction = (tester: Deno.TestContext) => void | Promise; - -export function unitTest(fn: TestFunction): void; -export function unitTest(options: UnitTestOptions, fn: TestFunction): void; -export function unitTest( - optionsOrFn: UnitTestOptions | TestFunction, - maybeFn?: TestFunction, -): void { - assert(optionsOrFn, "At least one argument is required"); - - let options: UnitTestOptions; - let name: string; - let fn: TestFunction; - - if (typeof optionsOrFn === "function") { - options = {}; - fn = optionsOrFn; - name = fn.name; - assert(name, "Missing test function name"); - } else { - options = optionsOrFn; - assert(maybeFn, "Missing test function definition"); - assert( - typeof maybeFn === "function", - "Second argument should be test function definition", - ); - fn = maybeFn; - name = fn.name; - assert(name, "Missing test function name"); - } - - const testDefinition: Deno.TestDefinition = { - name, - fn, - ignore: !!options.ignore, - only: !!options.only, - permissions: Object.assign({ - read: false, - write: false, - net: false, - env: false, - run: false, - ffi: false, - hrtime: false, - }, options.permissions), - }; - - Deno.test(testDefinition); -} - export function pathToAbsoluteFileUrl(path: string): URL { path = resolve(path); diff --git a/cli/tests/unit/testing_test.ts b/cli/tests/unit/testing_test.ts index d4d25d12fe..de3da77aaa 100644 --- a/cli/tests/unit/testing_test.ts +++ b/cli/tests/unit/testing_test.ts @@ -1,7 +1,7 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -import { assertRejects, assertThrows, unitTest } from "./test_util.ts"; +import { assertRejects, assertThrows } from "./test_util.ts"; -unitTest(function testWrongOverloads() { +Deno.test(function testWrongOverloads() { assertThrows( () => { // @ts-ignore Testing invalid overloads @@ -60,7 +60,7 @@ unitTest(function testWrongOverloads() { ); }); -unitTest(function nameOfTestCaseCantBeEmpty() { +Deno.test(function nameOfTestCaseCantBeEmpty() { assertThrows( () => { Deno.test("", () => {}); @@ -80,7 +80,7 @@ unitTest(function nameOfTestCaseCantBeEmpty() { ); }); -unitTest(function invalidStepArguments(t) { +Deno.test(function invalidStepArguments(t) { assertRejects( async () => { // deno-lint-ignore no-explicit-any diff --git a/cli/tests/unit/text_encoding_test.ts b/cli/tests/unit/text_encoding_test.ts index d83d845848..f8bc4395b3 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"; +import { assert, assertEquals, assertThrows } from "./test_util.ts"; -unitTest(function btoaSuccess() { +Deno.test(function btoaSuccess() { const text = "hello world"; const encoded = btoa(text); assertEquals(encoded, "aGVsbG8gd29ybGQ="); }); -unitTest(function atobSuccess() { +Deno.test(function atobSuccess() { const encoded = "aGVsbG8gd29ybGQ="; const decoded = atob(encoded); assertEquals(decoded, "hello world"); }); -unitTest(function atobWithAsciiWhitespace() { +Deno.test(function atobWithAsciiWhitespace() { const encodedList = [ " aGVsbG8gd29ybGQ=", " aGVsbG8gd29ybGQ=", @@ -30,7 +30,7 @@ unitTest(function atobWithAsciiWhitespace() { } }); -unitTest(function atobThrows() { +Deno.test(function atobThrows() { let threw = false; try { atob("aGVsbG8gd29ybGQ=="); @@ -40,7 +40,7 @@ unitTest(function atobThrows() { assert(threw); }); -unitTest(function atobThrows2() { +Deno.test(function atobThrows2() { let threw = false; try { atob("aGVsbG8gd29ybGQ==="); @@ -50,7 +50,7 @@ unitTest(function atobThrows2() { assert(threw); }); -unitTest(function atobThrows3() { +Deno.test(function atobThrows3() { let threw = false; try { atob("foobar!!"); @@ -65,14 +65,14 @@ unitTest(function atobThrows3() { assert(threw); }); -unitTest(function btoaFailed() { +Deno.test(function btoaFailed() { const text = "你好"; assertThrows(() => { btoa(text); }, DOMException); }); -unitTest(function textDecoder2() { +Deno.test(function textDecoder2() { // deno-fmt-ignore const fixture = new Uint8Array([ 0xf0, 0x9d, 0x93, 0xbd, @@ -86,13 +86,13 @@ unitTest(function textDecoder2() { // ignoreBOM is tested through WPT -unitTest(function textDecoderASCII() { +Deno.test(function textDecoderASCII() { const fixture = new Uint8Array([0x89, 0x95, 0x9f, 0xbf]); const decoder = new TextDecoder("ascii"); assertEquals(decoder.decode(fixture), "‰•Ÿ¿"); }); -unitTest(function textDecoderErrorEncoding() { +Deno.test(function textDecoderErrorEncoding() { let didThrow = false; try { new TextDecoder("Foo"); @@ -104,7 +104,7 @@ unitTest(function textDecoderErrorEncoding() { assert(didThrow); }); -unitTest(function textEncoder() { +Deno.test(function textEncoder() { const fixture = "𝓽𝓮𝔁𝓽"; const encoder = new TextEncoder(); // deno-fmt-ignore @@ -116,7 +116,7 @@ unitTest(function textEncoder() { ]); }); -unitTest(function textEncodeInto() { +Deno.test(function textEncodeInto() { const fixture = "text"; const encoder = new TextEncoder(); const bytes = new Uint8Array(5); @@ -129,7 +129,7 @@ unitTest(function textEncodeInto() { ]); }); -unitTest(function textEncodeInto2() { +Deno.test(function textEncodeInto2() { const fixture = "𝓽𝓮𝔁𝓽"; const encoder = new TextEncoder(); const bytes = new Uint8Array(17); @@ -145,7 +145,7 @@ unitTest(function textEncodeInto2() { ]); }); -unitTest(function textEncodeInto3() { +Deno.test(function textEncodeInto3() { const fixture = "𝓽𝓮𝔁𝓽"; const encoder = new TextEncoder(); const bytes = new Uint8Array(5); @@ -158,7 +158,7 @@ unitTest(function textEncodeInto3() { ]); }); -unitTest(function loneSurrogateEncodeInto() { +Deno.test(function loneSurrogateEncodeInto() { const fixture = "lone𝄞\ud888surrogate"; const encoder = new TextEncoder(); const bytes = new Uint8Array(20); @@ -175,7 +175,7 @@ unitTest(function loneSurrogateEncodeInto() { ]); }); -unitTest(function loneSurrogateEncodeInto2() { +Deno.test(function loneSurrogateEncodeInto2() { const fixture = "\ud800"; const encoder = new TextEncoder(); const bytes = new Uint8Array(3); @@ -188,7 +188,7 @@ unitTest(function loneSurrogateEncodeInto2() { ]); }); -unitTest(function loneSurrogateEncodeInto3() { +Deno.test(function loneSurrogateEncodeInto3() { const fixture = "\udc00"; const encoder = new TextEncoder(); const bytes = new Uint8Array(3); @@ -201,7 +201,7 @@ unitTest(function loneSurrogateEncodeInto3() { ]); }); -unitTest(function swappedSurrogatePairEncodeInto4() { +Deno.test(function swappedSurrogatePairEncodeInto4() { const fixture = "\udc00\ud800"; const encoder = new TextEncoder(); const bytes = new Uint8Array(8); @@ -214,7 +214,7 @@ unitTest(function swappedSurrogatePairEncodeInto4() { ]); }); -unitTest(function textDecoderSharedUint8Array() { +Deno.test(function textDecoderSharedUint8Array() { const ab = new SharedArrayBuffer(6); const dataView = new DataView(ab); const charCodeA = "A".charCodeAt(0); @@ -227,7 +227,7 @@ unitTest(function textDecoderSharedUint8Array() { assertEquals(actual, "ABCDEF"); }); -unitTest(function textDecoderSharedInt32Array() { +Deno.test(function textDecoderSharedInt32Array() { const ab = new SharedArrayBuffer(8); const dataView = new DataView(ab); const charCodeA = "A".charCodeAt(0); @@ -240,14 +240,14 @@ unitTest(function textDecoderSharedInt32Array() { assertEquals(actual, "ABCDEFGH"); }); -unitTest(function toStringShouldBeWebCompatibility() { +Deno.test(function toStringShouldBeWebCompatibility() { const encoder = new TextEncoder(); assertEquals(encoder.toString(), "[object TextEncoder]"); const decoder = new TextDecoder(); assertEquals(decoder.toString(), "[object TextDecoder]"); }); -unitTest(function textEncoderShouldCoerceToString() { +Deno.test(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 7ac2705161..35a21297f4 100644 --- a/cli/tests/unit/timers_test.ts +++ b/cli/tests/unit/timers_test.ts @@ -6,10 +6,9 @@ import { Deferred, deferred, delay, - unitTest, } from "./test_util.ts"; -unitTest(async function functionParameterBindingSuccess() { +Deno.test(async function functionParameterBindingSuccess() { const promise = deferred(); let count = 0; @@ -26,7 +25,7 @@ unitTest(async function functionParameterBindingSuccess() { assertEquals(count, 1); }); -unitTest(async function stringifyAndEvalNonFunctions() { +Deno.test(async function stringifyAndEvalNonFunctions() { // eval can only access global scope const global = globalThis as unknown as { globalPromise: ReturnType; @@ -50,7 +49,7 @@ unitTest(async function stringifyAndEvalNonFunctions() { Reflect.deleteProperty(global, "globalCount"); }); -unitTest(async function timeoutSuccess() { +Deno.test(async function timeoutSuccess() { const promise = deferred(); let count = 0; setTimeout(() => { @@ -62,7 +61,7 @@ unitTest(async function timeoutSuccess() { assertEquals(count, 1); }); -unitTest(async function timeoutEvalNoScopeLeak() { +Deno.test(async function timeoutEvalNoScopeLeak() { // eval can only access global scope const global = globalThis as unknown as { globalPromise: Deferred; @@ -83,7 +82,7 @@ unitTest(async function timeoutEvalNoScopeLeak() { Reflect.deleteProperty(global, "globalPromise"); }); -unitTest(async function timeoutArgs() { +Deno.test(async function timeoutArgs() { const promise = deferred(); const arg = 1; let capturedArgs: unknown[] = []; @@ -105,7 +104,7 @@ unitTest(async function timeoutArgs() { ]); }); -unitTest(async function timeoutCancelSuccess() { +Deno.test(async function timeoutCancelSuccess() { let count = 0; const id = setTimeout(() => { count++; @@ -116,7 +115,7 @@ unitTest(async function timeoutCancelSuccess() { assertEquals(count, 0); }); -unitTest(async function timeoutCancelMultiple() { +Deno.test(async function timeoutCancelMultiple() { function uncalled(): never { throw new Error("This function should not be called."); } @@ -141,7 +140,7 @@ unitTest(async function timeoutCancelMultiple() { await delay(50); }); -unitTest(async function timeoutCancelInvalidSilentFail() { +Deno.test(async function timeoutCancelInvalidSilentFail() { // Expect no panic const promise = deferred(); let count = 0; @@ -158,7 +157,7 @@ unitTest(async function timeoutCancelInvalidSilentFail() { clearTimeout(2147483647); }); -unitTest(async function intervalSuccess() { +Deno.test(async function intervalSuccess() { const promise = deferred(); let count = 0; const id = setInterval(() => { @@ -176,7 +175,7 @@ unitTest(async function intervalSuccess() { await delay(0); }); -unitTest(async function intervalCancelSuccess() { +Deno.test(async function intervalCancelSuccess() { let count = 0; const id = setInterval(() => { count++; @@ -186,7 +185,7 @@ unitTest(async function intervalCancelSuccess() { assertEquals(count, 0); }); -unitTest(async function intervalOrdering() { +Deno.test(async function intervalOrdering() { const timers: number[] = []; let timeouts = 0; function onTimeout() { @@ -202,12 +201,12 @@ unitTest(async function intervalOrdering() { assertEquals(timeouts, 1); }); -unitTest(function intervalCancelInvalidSilentFail() { +Deno.test(function intervalCancelInvalidSilentFail() { // Should silently fail (no panic) clearInterval(2147483647); }); -unitTest(async function fireCallbackImmediatelyWhenDelayOverMaxValue() { +Deno.test(async function fireCallbackImmediatelyWhenDelayOverMaxValue() { let count = 0; setTimeout(() => { count++; @@ -216,7 +215,7 @@ unitTest(async function fireCallbackImmediatelyWhenDelayOverMaxValue() { assertEquals(count, 1); }); -unitTest(async function timeoutCallbackThis() { +Deno.test(async function timeoutCallbackThis() { const promise = deferred(); let capturedThis: unknown; const obj = { @@ -230,7 +229,7 @@ unitTest(async function timeoutCallbackThis() { assertEquals(capturedThis, window); }); -unitTest(async function timeoutBindThis() { +Deno.test(async function timeoutBindThis() { const thisCheckPassed = [null, undefined, window, globalThis]; const thisCheckFailed = [ @@ -278,7 +277,7 @@ unitTest(async function timeoutBindThis() { } }); -unitTest(function clearTimeoutShouldConvertToNumber() { +Deno.test(function clearTimeoutShouldConvertToNumber() { let called = false; const obj = { valueOf(): number { @@ -290,7 +289,7 @@ unitTest(function clearTimeoutShouldConvertToNumber() { assert(called); }); -unitTest(function setTimeoutShouldThrowWithBigint() { +Deno.test(function setTimeoutShouldThrowWithBigint() { let hasThrown = 0; try { setTimeout(() => {}, (1n as unknown) as number); @@ -305,7 +304,7 @@ unitTest(function setTimeoutShouldThrowWithBigint() { assertEquals(hasThrown, 2); }); -unitTest(function clearTimeoutShouldThrowWithBigint() { +Deno.test(function clearTimeoutShouldThrowWithBigint() { let hasThrown = 0; try { clearTimeout((1n as unknown) as number); @@ -320,23 +319,23 @@ unitTest(function clearTimeoutShouldThrowWithBigint() { assertEquals(hasThrown, 2); }); -unitTest(function testFunctionName() { +Deno.test(function testFunctionName() { assertEquals(clearTimeout.name, "clearTimeout"); assertEquals(clearInterval.name, "clearInterval"); }); -unitTest(function testFunctionParamsLength() { +Deno.test(function testFunctionParamsLength() { assertEquals(setTimeout.length, 1); assertEquals(setInterval.length, 1); assertEquals(clearTimeout.length, 0); assertEquals(clearInterval.length, 0); }); -unitTest(function clearTimeoutAndClearIntervalNotBeEquals() { +Deno.test(function clearTimeoutAndClearIntervalNotBeEquals() { assertNotEquals(clearTimeout, clearInterval); }); -unitTest(async function timerMaxCpuBug() { +Deno.test(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. @@ -347,7 +346,7 @@ unitTest(async function timerMaxCpuBug() { assert(opsDispatched_ - opsDispatched < 10); }); -unitTest(async function timerBasicMicrotaskOrdering() { +Deno.test(async function timerBasicMicrotaskOrdering() { let s = ""; let count = 0; const promise = deferred(); @@ -371,7 +370,7 @@ unitTest(async function timerBasicMicrotaskOrdering() { assertEquals(s, "deno"); }); -unitTest(async function timerNestedMicrotaskOrdering() { +Deno.test(async function timerNestedMicrotaskOrdering() { let s = ""; const promise = deferred(); s += "0"; @@ -407,11 +406,11 @@ unitTest(async function timerNestedMicrotaskOrdering() { assertEquals(s, "0123456789AB"); }); -unitTest(function testQueueMicrotask() { +Deno.test(function testQueueMicrotask() { assertEquals(typeof queueMicrotask, "function"); }); -unitTest(async function timerIgnoresDateOverride() { +Deno.test(async function timerIgnoresDateOverride() { const OriginalDate = Date; const promise = deferred(); let hasThrown = 0; @@ -445,14 +444,14 @@ unitTest(async function timerIgnoresDateOverride() { assertEquals(hasThrown, 1); }); -unitTest({ permissions: { hrtime: true } }, function sleepSync() { +Deno.test({ permissions: { hrtime: true } }, function sleepSync() { const start = performance.now(); Deno.sleepSync(10); const after = performance.now(); assert(after - start >= 10); }); -unitTest( +Deno.test( { permissions: { hrtime: true } }, async function sleepSyncShorterPromise() { const perf = performance; @@ -471,7 +470,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { hrtime: true } }, async function sleepSyncLongerPromise() { const perf = performance; diff --git a/cli/tests/unit/tls_test.ts b/cli/tests/unit/tls_test.ts index fb8888be47..4062ef5046 100644 --- a/cli/tests/unit/tls_test.ts +++ b/cli/tests/unit/tls_test.ts @@ -8,7 +8,6 @@ import { assertThrows, Deferred, deferred, - unitTest, } from "./test_util.ts"; import { BufReader, BufWriter } from "../../../test_util/std/io/bufio.ts"; import { readAll } from "../../../test_util/std/io/util.ts"; @@ -25,13 +24,13 @@ function unreachable(): never { throw new Error("Unreachable code reached"); } -unitTest(async function connectTLSNoPerm() { +Deno.test({ permissions: { net: false } }, async function connectTLSNoPerm() { await assertRejects(async () => { await Deno.connectTls({ hostname: "deno.land", port: 443 }); }, Deno.errors.PermissionDenied); }); -unitTest( +Deno.test( { permissions: { read: true, net: true } }, async function connectTLSInvalidHost() { const listener = await Deno.listenTls({ @@ -49,17 +48,20 @@ unitTest( }, ); -unitTest(async function connectTLSCertFileNoReadPerm() { - await assertRejects(async () => { - await Deno.connectTls({ - hostname: "deno.land", - port: 443, - certFile: "cli/tests/testdata/tls/RootCA.crt", - }); - }, Deno.errors.PermissionDenied); -}); +Deno.test( + { permissions: { net: true, read: false } }, + async function connectTLSCertFileNoReadPerm() { + await assertRejects(async () => { + await Deno.connectTls({ + hostname: "deno.land", + port: 443, + certFile: "cli/tests/testdata/tls/RootCA.crt", + }); + }, Deno.errors.PermissionDenied); + }, +); -unitTest( +Deno.test( { permissions: { read: true, net: true } }, function listenTLSNonExistentCertKeyFiles() { const options = { @@ -85,18 +87,21 @@ unitTest( }, ); -unitTest({ permissions: { net: true } }, function listenTLSNoReadPerm() { - assertThrows(() => { - Deno.listenTls({ - hostname: "localhost", - port: 3500, - certFile: "cli/tests/testdata/tls/localhost.crt", - keyFile: "cli/tests/testdata/tls/localhost.key", - }); - }, Deno.errors.PermissionDenied); -}); +Deno.test( + { permissions: { net: true, read: false } }, + function listenTLSNoReadPerm() { + assertThrows(() => { + Deno.listenTls({ + hostname: "localhost", + port: 3500, + certFile: "cli/tests/testdata/tls/localhost.crt", + keyFile: "cli/tests/testdata/tls/localhost.key", + }); + }, Deno.errors.PermissionDenied); + }, +); -unitTest( +Deno.test( { permissions: { read: true, write: true, net: true }, }, @@ -123,7 +128,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true, net: true } }, function listenTLSEmptyCertFile() { const options = { @@ -148,7 +153,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, net: true } }, async function dialAndListenTLS() { const resolvable = deferred(); @@ -300,7 +305,7 @@ async function receiveThenSend( conn.close(); } -unitTest( +Deno.test( { permissions: { read: true, net: true } }, async function tlsServerStreamHalfCloseSendOneByte() { const [serverConn, clientConn] = await tlsPair(); @@ -311,7 +316,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, net: true } }, async function tlsClientStreamHalfCloseSendOneByte() { const [serverConn, clientConn] = await tlsPair(); @@ -322,7 +327,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, net: true } }, async function tlsServerStreamHalfCloseSendOneChunk() { const [serverConn, clientConn] = await tlsPair(); @@ -333,7 +338,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, net: true } }, async function tlsClientStreamHalfCloseSendOneChunk() { const [serverConn, clientConn] = await tlsPair(); @@ -344,7 +349,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, net: true } }, async function tlsServerStreamHalfCloseSendManyBytes() { const [serverConn, clientConn] = await tlsPair(); @@ -355,7 +360,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, net: true } }, async function tlsClientStreamHalfCloseSendManyBytes() { const [serverConn, clientConn] = await tlsPair(); @@ -366,7 +371,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, net: true } }, async function tlsServerStreamHalfCloseSendManyChunks() { const [serverConn, clientConn] = await tlsPair(); @@ -377,7 +382,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, net: true } }, async function tlsClientStreamHalfCloseSendManyChunks() { const [serverConn, clientConn] = await tlsPair(); @@ -427,7 +432,7 @@ async function receiveAlotSendNothing(conn: Deno.Conn) { conn.close(); } -unitTest( +Deno.test( { permissions: { read: true, net: true } }, async function tlsServerStreamCancelRead() { const [serverConn, clientConn] = await tlsPair(); @@ -438,7 +443,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, net: true } }, async function tlsClientStreamCancelRead() { const [serverConn, clientConn] = await tlsPair(); @@ -484,7 +489,7 @@ async function sendReceiveEmptyBuf(conn: Deno.Conn) { conn.close(); } -unitTest( +Deno.test( { permissions: { read: true, net: true } }, async function tlsStreamSendReceiveEmptyBuf() { const [serverConn, clientConn] = await tlsPair(); @@ -510,7 +515,7 @@ async function closeWriteAndClose(conn: Deno.Conn) { conn.close(); } -unitTest( +Deno.test( { permissions: { read: true, net: true } }, async function tlsServerStreamImmediateClose() { const [serverConn, clientConn] = await tlsPair(); @@ -521,7 +526,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, net: true } }, async function tlsClientStreamImmediateClose() { const [serverConn, clientConn] = await tlsPair(); @@ -532,7 +537,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, net: true } }, async function tlsClientAndServerStreamImmediateClose() { const [serverConn, clientConn] = await tlsPair(); @@ -775,7 +780,7 @@ async function tlsWithTcpFailureTestImpl( } } -unitTest( +Deno.test( { permissions: { read: true, net: true } }, async function tlsHandshakeWithTcpCorruptionImmediately() { await tlsWithTcpFailureTestImpl("handshake", 0, "corruption", false); @@ -783,7 +788,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, net: true } }, async function tlsHandshakeWithTcpShutdownImmediately() { await tlsWithTcpFailureTestImpl("handshake", 0, "shutdown", false); @@ -791,7 +796,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, net: true } }, async function tlsHandshakeWithTcpCorruptionAfter70Bytes() { await tlsWithTcpFailureTestImpl("handshake", 76, "corruption", false); @@ -799,7 +804,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, net: true } }, async function tlsHandshakeWithTcpShutdownAfter70bytes() { await tlsWithTcpFailureTestImpl("handshake", 77, "shutdown", false); @@ -807,7 +812,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, net: true } }, async function tlsHandshakeWithTcpCorruptionAfter200Bytes() { await tlsWithTcpFailureTestImpl("handshake", 200, "corruption", false); @@ -815,7 +820,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, net: true } }, async function tlsHandshakeWithTcpShutdownAfter200bytes() { await tlsWithTcpFailureTestImpl("handshake", 201, "shutdown", false); @@ -823,7 +828,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, net: true } }, async function tlsTrafficWithTcpCorruption() { await tlsWithTcpFailureTestImpl("traffic", Infinity, "corruption", false); @@ -831,7 +836,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, net: true } }, async function tlsTrafficWithTcpShutdown() { await tlsWithTcpFailureTestImpl("traffic", Infinity, "shutdown", false); @@ -912,7 +917,7 @@ async function curl(url: string): Promise { } } -unitTest( +Deno.test( { permissions: { read: true, net: true, run: true } }, async function curlFakeHttpsServer() { const port = getPort(); @@ -936,7 +941,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, net: true } }, async function startTls() { const hostname = "smtp.gmail.com"; @@ -987,7 +992,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, net: true } }, async function connectTLSBadClientCertPrivateKey(): Promise { await assertRejects(async () => { @@ -1003,7 +1008,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, net: true } }, async function connectTLSBadPrivateKey(): Promise { await assertRejects(async () => { @@ -1019,7 +1024,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, net: true } }, async function connectTLSNotPrivateKey(): Promise { await assertRejects(async () => { @@ -1035,7 +1040,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, net: true } }, async function connectWithClientCert() { // The test_server running on port 4552 responds with 'PASS' if client @@ -1060,7 +1065,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, net: true } }, async function connectTLSCaCerts() { const conn = await Deno.connectTls({ @@ -1074,7 +1079,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, net: true } }, async function connectTLSCertFile() { const conn = await Deno.connectTls({ @@ -1088,7 +1093,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, net: true } }, async function startTLSCaCerts() { const plainConn = await Deno.connect({ @@ -1105,7 +1110,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, net: true } }, async function tlsHandshakeSuccess() { const hostname = "localhost"; @@ -1174,7 +1179,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, net: true } }, async function tlsHandshakeFailure() { const hostname = "localhost"; diff --git a/cli/tests/unit/truncate_test.ts b/cli/tests/unit/truncate_test.ts index 33a1cd4b17..f7819fcd9d 100644 --- a/cli/tests/unit/truncate_test.ts +++ b/cli/tests/unit/truncate_test.ts @@ -1,12 +1,7 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -import { - assertEquals, - assertRejects, - assertThrows, - unitTest, -} from "./test_util.ts"; +import { assertEquals, assertRejects, assertThrows } from "./test_util.ts"; -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function ftruncateSyncSuccess() { const filename = Deno.makeTempDirSync() + "/test_ftruncateSync.txt"; @@ -28,7 +23,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function ftruncateSuccess() { const filename = Deno.makeTempDirSync() + "/test_ftruncate.txt"; @@ -50,7 +45,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function truncateSyncSuccess() { const filename = Deno.makeTempDirSync() + "/test_truncateSync.txt"; @@ -65,7 +60,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function truncateSuccess() { const filename = Deno.makeTempDirSync() + "/test_truncate.txt"; @@ -80,19 +75,19 @@ unitTest( }, ); -unitTest({ permissions: { write: false } }, function truncateSyncPerm() { +Deno.test({ permissions: { write: false } }, function truncateSyncPerm() { assertThrows(() => { Deno.truncateSync("/test_truncateSyncPermission.txt"); }, Deno.errors.PermissionDenied); }); -unitTest({ permissions: { write: false } }, async function truncatePerm() { +Deno.test({ permissions: { write: false } }, async function truncatePerm() { await assertRejects(async () => { await Deno.truncate("/test_truncatePermission.txt"); }, Deno.errors.PermissionDenied); }); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function truncateSyncNotFound() { const filename = "/badfile.txt"; @@ -106,7 +101,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function truncateSyncNotFound() { const filename = "/badfile.txt"; diff --git a/cli/tests/unit/tty_test.ts b/cli/tests/unit/tty_test.ts index 2f13dd7397..dd492aa36b 100644 --- a/cli/tests/unit/tty_test.ts +++ b/cli/tests/unit/tty_test.ts @@ -1,9 +1,9 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -import { assert, assertThrows, unitTest } from "./test_util.ts"; +import { assert, assertThrows } from "./test_util.ts"; // Note tests for Deno.setRaw is in integration tests. -unitTest({ permissions: { read: true } }, function consoleSizeFile() { +Deno.test({ permissions: { read: true } }, function consoleSizeFile() { const file = Deno.openSync("cli/tests/testdata/hello.txt"); assertThrows(() => { Deno.consoleSize(file.rid); @@ -11,21 +11,21 @@ unitTest({ permissions: { read: true } }, function consoleSizeFile() { file.close(); }); -unitTest(function consoleSizeError() { +Deno.test(function consoleSizeError() { assertThrows(() => { // Absurdly large rid. Deno.consoleSize(0x7fffffff); }, Deno.errors.BadResource); }); -unitTest({ permissions: { read: true } }, function isatty() { +Deno.test({ permissions: { read: true } }, function isatty() { // CI not under TTY, so cannot test stdin/stdout/stderr. const f = Deno.openSync("cli/tests/testdata/hello.txt"); assert(!Deno.isatty(f.rid)); f.close(); }); -unitTest(function isattyError() { +Deno.test(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 579208ee0d..5f981bf7e2 100644 --- a/cli/tests/unit/umask_test.ts +++ b/cli/tests/unit/umask_test.ts @@ -1,7 +1,7 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -import { assertEquals, unitTest } from "./test_util.ts"; +import { assertEquals } from "./test_util.ts"; -unitTest( +Deno.test( { ignore: Deno.build.os === "windows", }, diff --git a/cli/tests/unit/url_search_params_test.ts b/cli/tests/unit/url_search_params_test.ts index 6e45d7ba02..7025676689 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"; +import { assert, assertEquals } from "./test_util.ts"; -unitTest(function urlSearchParamsWithMultipleSpaces() { +Deno.test(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() { +Deno.test(function urlSearchParamsWithExclamation() { const init = [ ["str", "hello, world!"], ]; @@ -15,7 +15,7 @@ unitTest(function urlSearchParamsWithExclamation() { assertEquals(searchParams, "str=hello%2C+world%21"); }); -unitTest(function urlSearchParamsWithQuotes() { +Deno.test(function urlSearchParamsWithQuotes() { const init = [ ["str", "'hello world'"], ]; @@ -23,7 +23,7 @@ unitTest(function urlSearchParamsWithQuotes() { assertEquals(searchParams, "str=%27hello+world%27"); }); -unitTest(function urlSearchParamsWithBraket() { +Deno.test(function urlSearchParamsWithBraket() { const init = [ ["str", "(hello world)"], ]; @@ -31,7 +31,7 @@ unitTest(function urlSearchParamsWithBraket() { assertEquals(searchParams, "str=%28hello+world%29"); }); -unitTest(function urlSearchParamsWithTilde() { +Deno.test(function urlSearchParamsWithTilde() { const init = [ ["str", "hello~world"], ]; @@ -39,7 +39,7 @@ unitTest(function urlSearchParamsWithTilde() { assertEquals(searchParams, "str=hello%7Eworld"); }); -unitTest(function urlSearchParamsInitString() { +Deno.test(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() { ); }); -unitTest(function urlSearchParamsInitStringWithPlusCharacter() { +Deno.test(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() { assertEquals(params.get("q"), "a b c"); }); -unitTest(function urlSearchParamsInitStringWithMalformedParams() { +Deno.test(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() { assertEquals(params.get("b"), "%*"); }); -unitTest(function urlSearchParamsInitIterable() { +Deno.test(function urlSearchParamsInitIterable() { const init = [ ["a", "54"], ["b", "true"], @@ -93,33 +93,33 @@ unitTest(function urlSearchParamsInitIterable() { assertEquals(searchParams.toString(), "a=54&b=true"); }); -unitTest(function urlSearchParamsInitRecord() { +Deno.test(function urlSearchParamsInitRecord() { const init = { a: "54", b: "true" }; const searchParams = new URLSearchParams(init); assertEquals(searchParams.toString(), "a=54&b=true"); }); -unitTest(function urlSearchParamsInit() { +Deno.test(function urlSearchParamsInit() { const params1 = new URLSearchParams("a=b"); assertEquals(params1.toString(), "a=b"); const params2 = new URLSearchParams(params1); assertEquals(params2.toString(), "a=b"); }); -unitTest(function urlSearchParamsAppendSuccess() { +Deno.test(function urlSearchParamsAppendSuccess() { const searchParams = new URLSearchParams(); searchParams.append("a", "true"); assertEquals(searchParams.toString(), "a=true"); }); -unitTest(function urlSearchParamsDeleteSuccess() { +Deno.test(function urlSearchParamsDeleteSuccess() { const init = "a=54&b=true"; const searchParams = new URLSearchParams(init); searchParams.delete("b"); assertEquals(searchParams.toString(), "a=54"); }); -unitTest(function urlSearchParamsGetAllSuccess() { +Deno.test(function urlSearchParamsGetAllSuccess() { const init = "a=54&b=true&a=true"; const searchParams = new URLSearchParams(init); assertEquals(searchParams.getAll("a"), ["54", "true"]); @@ -127,7 +127,7 @@ unitTest(function urlSearchParamsGetAllSuccess() { assertEquals(searchParams.getAll("c"), []); }); -unitTest(function urlSearchParamsGetSuccess() { +Deno.test(function urlSearchParamsGetSuccess() { const init = "a=54&b=true&a=true"; const searchParams = new URLSearchParams(init); assertEquals(searchParams.get("a"), "54"); @@ -135,7 +135,7 @@ unitTest(function urlSearchParamsGetSuccess() { assertEquals(searchParams.get("c"), null); }); -unitTest(function urlSearchParamsHasSuccess() { +Deno.test(function urlSearchParamsHasSuccess() { const init = "a=54&b=true&a=true"; const searchParams = new URLSearchParams(init); assert(searchParams.has("a")); @@ -143,28 +143,28 @@ unitTest(function urlSearchParamsHasSuccess() { assert(!searchParams.has("c")); }); -unitTest(function urlSearchParamsSetReplaceFirstAndRemoveOthers() { +Deno.test(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() { +Deno.test(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() { +Deno.test(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() { +Deno.test(function urlSearchParamsForEachSuccess() { const init = [ ["a", "54"], ["b", "true"], @@ -180,34 +180,34 @@ unitTest(function urlSearchParamsForEachSuccess() { assertEquals(callNum, init.length); }); -unitTest(function urlSearchParamsMissingName() { +Deno.test(function urlSearchParamsMissingName() { const init = "=4"; const searchParams = new URLSearchParams(init); assertEquals(searchParams.get(""), "4"); assertEquals(searchParams.toString(), "=4"); }); -unitTest(function urlSearchParamsMissingValue() { +Deno.test(function urlSearchParamsMissingValue() { const init = "4="; const searchParams = new URLSearchParams(init); assertEquals(searchParams.get("4"), ""); assertEquals(searchParams.toString(), "4="); }); -unitTest(function urlSearchParamsMissingEqualSign() { +Deno.test(function urlSearchParamsMissingEqualSign() { const init = "4"; const searchParams = new URLSearchParams(init); assertEquals(searchParams.get("4"), ""); assertEquals(searchParams.toString(), "4="); }); -unitTest(function urlSearchParamsMissingPair() { +Deno.test(function urlSearchParamsMissingPair() { const init = "c=4&&a=54&"; const searchParams = new URLSearchParams(init); assertEquals(searchParams.toString(), "c=4&a=54"); }); -unitTest(function urlSearchParamsForShortEncodedChar() { +Deno.test(function urlSearchParamsForShortEncodedChar() { const init = { linefeed: "\n", tab: "\t" }; const searchParams = new URLSearchParams(init); assertEquals(searchParams.toString(), "linefeed=%0A&tab=%09"); @@ -215,7 +215,7 @@ unitTest(function urlSearchParamsForShortEncodedChar() { // If pair does not contain exactly two items, then throw a TypeError. // ref https://url.spec.whatwg.org/#interface-urlsearchparams -unitTest(function urlSearchParamsShouldThrowTypeError() { +Deno.test(function urlSearchParamsShouldThrowTypeError() { let hasThrown = 0; try { @@ -245,7 +245,7 @@ unitTest(function urlSearchParamsShouldThrowTypeError() { assertEquals(hasThrown, 2); }); -unitTest(function urlSearchParamsAppendArgumentsCheck() { +Deno.test(function urlSearchParamsAppendArgumentsCheck() { const methodRequireOneParam = ["delete", "getAll", "get", "has", "forEach"]; const methodRequireTwoParams = ["append", "set"]; @@ -288,7 +288,7 @@ unitTest(function urlSearchParamsAppendArgumentsCheck() { }); // ref: https://github.com/web-platform-tests/wpt/blob/master/url/urlsearchparams-delete.any.js -unitTest(function urlSearchParamsDeletingAppendedMultiple() { +Deno.test(function urlSearchParamsDeletingAppendedMultiple() { const params = new URLSearchParams(); params.append("first", (1 as unknown) as string); assert(params.has("first")); @@ -302,7 +302,7 @@ unitTest(function urlSearchParamsDeletingAppendedMultiple() { }); // ref: https://github.com/web-platform-tests/wpt/blob/master/url/urlsearchparams-constructor.any.js#L176-L182 -unitTest(function urlSearchParamsCustomSymbolIterator() { +Deno.test(function urlSearchParamsCustomSymbolIterator() { const params = new URLSearchParams(); params[Symbol.iterator] = function* (): IterableIterator<[string, string]> { yield ["a", "b"]; @@ -311,7 +311,7 @@ unitTest(function urlSearchParamsCustomSymbolIterator() { assertEquals(params1.get("a"), "b"); }); -unitTest( +Deno.test( function urlSearchParamsCustomSymbolIteratorWithNonStringParams() { const params = {}; // deno-lint-ignore no-explicit-any @@ -326,7 +326,7 @@ unitTest( ); // If a class extends URLSearchParams, override one method should not change another's behavior. -unitTest( +Deno.test( function urlSearchParamsOverridingAppendNotChangeConstructorAndSet() { let overridedAppendCalled = 0; class CustomSearchParams extends URLSearchParams { @@ -343,7 +343,7 @@ unitTest( }, ); -unitTest(function urlSearchParamsOverridingEntriesNotChangeForEach() { +Deno.test(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 9f32445a94..1ade4a7484 100644 --- a/cli/tests/unit/url_test.ts +++ b/cli/tests/unit/url_test.ts @@ -4,10 +4,9 @@ import { assertEquals, assertStrictEquals, assertThrows, - unitTest, } from "./test_util.ts"; -unitTest(function urlParsing() { +Deno.test(function urlParsing() { const url = new URL( "https://foo:bar@baz.qat:8000/qux/quux?foo=bar&baz=12#qat", ); @@ -33,7 +32,7 @@ unitTest(function urlParsing() { ); }); -unitTest(function urlProtocolParsing() { +Deno.test(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 +49,7 @@ unitTest(function urlProtocolParsing() { assertThrows(() => new URL("*://foo"), TypeError, "Invalid URL"); }); -unitTest(function urlAuthenticationParsing() { +Deno.test(function urlAuthenticationParsing() { const specialUrl = new URL("http://foo:bar@baz"); assertEquals(specialUrl.username, "foo"); assertEquals(specialUrl.password, "bar"); @@ -62,7 +61,7 @@ unitTest(function urlAuthenticationParsing() { assertEquals(nonSpecialUrl.hostname, "baz"); }); -unitTest(function urlHostnameParsing() { +Deno.test(function urlHostnameParsing() { // IPv6. assertEquals(new URL("http://[::1]").hostname, "[::1]"); assertEquals(new URL("file://[::1]").hostname, "[::1]"); @@ -102,7 +101,7 @@ unitTest(function urlHostnameParsing() { assertThrows(() => new URL("http://4294967296"), TypeError, "Invalid URL"); }); -unitTest(function urlPortParsing() { +Deno.test(function urlPortParsing() { const specialUrl = new URL("http://foo:8000"); assertEquals(specialUrl.hostname, "foo"); assertEquals(specialUrl.port, "8000"); @@ -112,7 +111,7 @@ unitTest(function urlPortParsing() { assertEquals(nonSpecialUrl.port, "8000"); }); -unitTest(function urlModifications() { +Deno.test(function urlModifications() { const url = new URL( "https://foo:bar@baz.qat:8000/qux/quux?foo=bar&baz=12#qat", ); @@ -167,7 +166,7 @@ unitTest(function urlModifications() { ); }); -unitTest(function urlModifyHref() { +Deno.test(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 +178,13 @@ unitTest(function urlModifyHref() { assertEquals(url.hash, "#qux"); }); -unitTest(function urlNormalize() { +Deno.test(function urlNormalize() { const url = new URL("http://example.com"); assertEquals(url.pathname, "/"); assertEquals(url.href, "http://example.com/"); }); -unitTest(function urlModifyPathname() { +Deno.test(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 +200,7 @@ unitTest(function urlModifyPathname() { assertEquals(url.pathname, "/a/b/c"); }); -unitTest(function urlModifyHash() { +Deno.test(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 +209,7 @@ unitTest(function urlModifyHash() { assertEquals(url.hash, "#%foo%20bar/qat%qux#bar"); }); -unitTest(function urlSearchParamsReuse() { +Deno.test(function urlSearchParamsReuse() { const url = new URL( "https://foo:bar@baz.qat:8000/qux/quux?foo=bar&baz=12#qat", ); @@ -219,7 +218,7 @@ unitTest(function urlSearchParamsReuse() { assert(sp === url.searchParams, "Search params should be reused."); }); -unitTest(function urlBackSlashes() { +Deno.test(function urlBackSlashes() { const url = new URL( "https:\\\\foo:bar@baz.qat:8000\\qux\\quux?foo=bar&baz=12#qat", ); @@ -229,7 +228,7 @@ unitTest(function urlBackSlashes() { ); }); -unitTest(function urlProtocolSlashes() { +Deno.test(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 +237,7 @@ unitTest(function urlProtocolSlashes() { assertEquals(new URL("abcd://foo").href, "abcd://foo"); }); -unitTest(function urlRequireHost() { +Deno.test(function urlRequireHost() { assertEquals(new URL("file:///").href, "file:///"); assertThrows(() => new URL("ftp:///"), TypeError, "Invalid URL"); assertThrows(() => new URL("http:///"), TypeError, "Invalid URL"); @@ -247,7 +246,7 @@ unitTest(function urlRequireHost() { assertThrows(() => new URL("wss:///"), TypeError, "Invalid URL"); }); -unitTest(function urlDriveLetter() { +Deno.test(function urlDriveLetter() { assertEquals(new URL("file:///C:").href, "file:///C:"); assertEquals(new URL("file:///C:/").href, "file:///C:/"); assertEquals(new URL("file:///C:/..").href, "file:///C:/"); @@ -269,28 +268,28 @@ unitTest(function urlDriveLetter() { // assertEquals(new URL("abcd://foo/C:/..").href, "abcd://foo/"); }); -unitTest(function urlHostnameUpperCase() { +Deno.test(function urlHostnameUpperCase() { assertEquals(new URL("http://EXAMPLE.COM").href, "http://example.com/"); assertEquals(new URL("abcd://EXAMPLE.COM").href, "abcd://EXAMPLE.COM"); }); -unitTest(function urlEmptyPath() { +Deno.test(function urlEmptyPath() { assertEquals(new URL("http://foo").pathname, "/"); assertEquals(new URL("file://foo").pathname, "/"); assertEquals(new URL("abcd://foo").pathname, ""); }); -unitTest(function urlPathRepeatedSlashes() { +Deno.test(function urlPathRepeatedSlashes() { assertEquals(new URL("http://foo//bar//").pathname, "//bar//"); assertEquals(new URL("file://foo///bar//").pathname, "/bar//"); assertEquals(new URL("abcd://foo//bar//").pathname, "//bar//"); }); -unitTest(function urlTrim() { +Deno.test(function urlTrim() { assertEquals(new URL(" http://example.com ").href, "http://example.com/"); }); -unitTest(function urlEncoding() { +Deno.test(function urlEncoding() { assertEquals( new URL("http://a !$&*()=,;+'\"@example.com").username, "a%20!$&*()%3D,%3B+'%22", @@ -320,7 +319,7 @@ unitTest(function urlEncoding() { ); }); -unitTest(function urlBase() { +Deno.test(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"); @@ -362,12 +361,12 @@ unitTest(function urlBase() { assertEquals(new URL("/foo", "abcd:/").href, "abcd:/foo"); }); -unitTest(function urlDriveLetterBase() { +Deno.test(function urlDriveLetterBase() { assertEquals(new URL("/b", "file:///C:/a/b").href, "file:///C:/b"); assertEquals(new URL("/D:", "file:///C:/a/b").href, "file:///D:"); }); -unitTest(function urlSameProtocolBase() { +Deno.test(function urlSameProtocolBase() { assertEquals(new URL("http:", "http://foo/a").href, "http://foo/a"); assertEquals(new URL("file:", "file://foo/a").href, "file://foo/a"); assertEquals(new URL("abcd:", "abcd://foo/a").href, "abcd:"); @@ -377,7 +376,7 @@ unitTest(function urlSameProtocolBase() { assertEquals(new URL("abcd:b", "abcd://foo/a").href, "abcd:b"); }); -unitTest(function deletingAllParamsRemovesQuestionMarkFromURL() { +Deno.test(function deletingAllParamsRemovesQuestionMarkFromURL() { const url = new URL("http://example.com/?param1¶m2"); url.searchParams.delete("param1"); url.searchParams.delete("param2"); @@ -385,7 +384,7 @@ unitTest(function deletingAllParamsRemovesQuestionMarkFromURL() { assertEquals(url.search, ""); }); -unitTest(function removingNonExistentParamRemovesQuestionMarkFromURL() { +Deno.test(function removingNonExistentParamRemovesQuestionMarkFromURL() { const url = new URL("http://example.com/?"); assertEquals(url.href, "http://example.com/?"); url.searchParams.delete("param1"); @@ -393,7 +392,7 @@ unitTest(function removingNonExistentParamRemovesQuestionMarkFromURL() { assertEquals(url.search, ""); }); -unitTest(function sortingNonExistentParamRemovesQuestionMarkFromURL() { +Deno.test(function sortingNonExistentParamRemovesQuestionMarkFromURL() { const url = new URL("http://example.com/?"); assertEquals(url.href, "http://example.com/?"); url.searchParams.sort(); @@ -401,7 +400,7 @@ unitTest(function sortingNonExistentParamRemovesQuestionMarkFromURL() { assertEquals(url.search, ""); }); -unitTest(function customInspectFunction() { +Deno.test(function customInspectFunction() { const url = new URL("http://example.com/?"); assertEquals( Deno.inspect(url), @@ -421,14 +420,14 @@ unitTest(function customInspectFunction() { ); }); -unitTest(function protocolNotHttpOrFile() { +Deno.test(function protocolNotHttpOrFile() { const url = new URL("about:blank"); assertEquals(url.href, "about:blank"); assertEquals(url.protocol, "about:"); assertEquals(url.origin, "null"); }); -unitTest(function throwForInvalidPortConstructor() { +Deno.test(function throwForInvalidPortConstructor() { const urls = [ // If port is greater than 2^16 − 1, validation error, return failure. `https://baz.qat:${2 ** 16}`, @@ -447,7 +446,7 @@ unitTest(function throwForInvalidPortConstructor() { new URL("https://baz.qat:0"); }); -unitTest(function doNotOverridePortIfInvalid() { +Deno.test(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 +454,7 @@ unitTest(function doNotOverridePortIfInvalid() { assertEquals(url.port, initialPort); }); -unitTest(function emptyPortForSchemeDefaultPort() { +Deno.test(function emptyPortForSchemeDefaultPort() { const nonDefaultPort = "3500"; const url = new URL("ftp://baz.qat:21"); @@ -477,7 +476,7 @@ unitTest(function emptyPortForSchemeDefaultPort() { assertEquals(url2.port, ""); }); -unitTest(function assigningPortPropertyAffectsReceiverOnly() { +Deno.test(function assigningPortPropertyAffectsReceiverOnly() { // Setting `.port` should update only the receiver. const u1 = new URL("http://google.com/"); // deno-lint-ignore no-explicit-any @@ -487,7 +486,7 @@ unitTest(function assigningPortPropertyAffectsReceiverOnly() { assertStrictEquals(u2.port, "123"); }); -unitTest(function urlSearchParamsIdentityPreserved() { +Deno.test(function urlSearchParamsIdentityPreserved() { // URLSearchParams identity should not be lost when URL is updated. const u = new URL("http://foo.com/"); const sp1 = u.searchParams; diff --git a/cli/tests/unit/urlpattern_test.ts b/cli/tests/unit/urlpattern_test.ts index 37a662ac12..5d39afe6c2 100644 --- a/cli/tests/unit/urlpattern_test.ts +++ b/cli/tests/unit/urlpattern_test.ts @@ -1,7 +1,7 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals, unitTest } from "./test_util.ts"; +import { assert, assertEquals } from "./test_util.ts"; -unitTest(function urlPatternFromString() { +Deno.test(function urlPatternFromString() { const pattern = new URLPattern("https://deno.land/foo/:bar"); assertEquals(pattern.protocol, "https"); assertEquals(pattern.hostname, "deno.land"); @@ -15,7 +15,7 @@ unitTest(function urlPatternFromString() { assertEquals(match.pathname.groups, { bar: "x" }); }); -unitTest(function urlPatternFromStringWithBase() { +Deno.test(function urlPatternFromStringWithBase() { const pattern = new URLPattern("/foo/:bar", "https://deno.land"); assertEquals(pattern.protocol, "https"); assertEquals(pattern.hostname, "deno.land"); @@ -29,7 +29,7 @@ unitTest(function urlPatternFromStringWithBase() { assertEquals(match.pathname.groups, { bar: "x" }); }); -unitTest(function urlPatternFromInit() { +Deno.test(function urlPatternFromInit() { const pattern = new URLPattern({ pathname: "/foo/:bar", }); diff --git a/cli/tests/unit/utime_test.ts b/cli/tests/unit/utime_test.ts index a46bd7a0ca..b96ed1cf87 100644 --- a/cli/tests/unit/utime_test.ts +++ b/cli/tests/unit/utime_test.ts @@ -4,10 +4,9 @@ import { assertRejects, assertThrows, pathToAbsoluteFileUrl, - unitTest, } from "./test_util.ts"; -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function futimeSyncSuccess() { const testDir = await Deno.makeTempDir(); @@ -29,7 +28,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function futimeSyncSuccess() { const testDir = Deno.makeTempDirSync(); @@ -51,7 +50,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function utimeSyncFileSuccess() { const testDir = Deno.makeTempDirSync(); @@ -70,7 +69,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function utimeSyncUrlSuccess() { const testDir = Deno.makeTempDirSync(); @@ -89,7 +88,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function utimeSyncDirectorySuccess() { const testDir = Deno.makeTempDirSync(); @@ -104,7 +103,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function utimeSyncDateSuccess() { const testDir = Deno.makeTempDirSync(); @@ -119,7 +118,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function utimeSyncFileDateSuccess() { const testDir = Deno.makeTempDirSync(); @@ -137,7 +136,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function utimeSyncLargeNumberSuccess() { const testDir = Deno.makeTempDirSync(); @@ -154,7 +153,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function utimeSyncNotFound() { const atime = 1000; @@ -170,7 +169,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: false } }, function utimeSyncPerm() { const atime = 1000; @@ -182,7 +181,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function utimeFileSuccess() { const testDir = Deno.makeTempDirSync(); @@ -201,7 +200,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function utimeUrlSuccess() { const testDir = Deno.makeTempDirSync(); @@ -220,7 +219,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function utimeDirectorySuccess() { const testDir = Deno.makeTempDirSync(); @@ -235,7 +234,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function utimeDateSuccess() { const testDir = Deno.makeTempDirSync(); @@ -250,7 +249,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function utimeFileDateSuccess() { const testDir = Deno.makeTempDirSync(); @@ -269,7 +268,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function utimeNotFound() { const atime = 1000; @@ -285,7 +284,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: false } }, async function utimeSyncPerm() { const atime = 1000; diff --git a/cli/tests/unit/version_test.ts b/cli/tests/unit/version_test.ts index e6e95ff076..6da4fd684d 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"; +import { assert } from "./test_util.ts"; -unitTest(function version() { +Deno.test(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 f687cd0949..e1659b090b 100644 --- a/cli/tests/unit/wasm_test.ts +++ b/cli/tests/unit/wasm_test.ts @@ -1,4 +1,4 @@ -import { assert, assertEquals, assertRejects, unitTest } from "./test_util.ts"; +import { assert, assertEquals, assertRejects } from "./test_util.ts"; // The following blob can be created by taking the following s-expr and pass // it through wat2wasm. @@ -17,7 +17,7 @@ const simpleWasm = new Uint8Array([ 0x00, 0x20, 0x01, 0x6a, 0x0b ]); -unitTest(async function wasmInstantiateWorksWithBuffer() { +Deno.test(async function wasmInstantiateWorksWithBuffer() { const { module, instance } = await WebAssembly.instantiate(simpleWasm); assertEquals(WebAssembly.Module.exports(module), [{ name: "add", @@ -32,7 +32,7 @@ unitTest(async function wasmInstantiateWorksWithBuffer() { // V8's default implementation of `WebAssembly.instantiateStreaming()` if you // 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( +Deno.test( async function wasmInstantiateStreamingFailsWithBuffer() { await assertRejects(async () => { await WebAssembly.instantiateStreaming( @@ -43,7 +43,7 @@ unitTest( }, ); -unitTest( +Deno.test( async function wasmInstantiateStreamingNoContentType() { await assertRejects( async () => { @@ -56,7 +56,7 @@ unitTest( }, ); -unitTest(async function wasmInstantiateStreaming() { +Deno.test(async function wasmInstantiateStreaming() { let isomorphic = ""; for (const byte of simpleWasm) { isomorphic += String.fromCharCode(byte); @@ -76,7 +76,7 @@ unitTest(async function wasmInstantiateStreaming() { assertEquals(add(1, 3), 4); }); -unitTest( +Deno.test( { permissions: { net: true } }, async function wasmStreamingNonTrivial() { // deno-dom's WASM file is a real-world non-trivial case that gave us diff --git a/cli/tests/unit/webcrypto_test.ts b/cli/tests/unit/webcrypto_test.ts index b1d4e96376..7108e060b7 100644 --- a/cli/tests/unit/webcrypto_test.ts +++ b/cli/tests/unit/webcrypto_test.ts @@ -1,7 +1,7 @@ -import { assert, assertEquals, assertRejects, unitTest } from "./test_util.ts"; +import { assert, assertEquals, assertRejects } from "./test_util.ts"; // https://github.com/denoland/deno/issues/11664 -unitTest(async function testImportArrayBufferKey() { +Deno.test(async function testImportArrayBufferKey() { const subtle = window.crypto.subtle; assert(subtle); @@ -22,7 +22,7 @@ unitTest(async function testImportArrayBufferKey() { }); // TODO(@littledivy): Remove this when we enable WPT for sign_verify -unitTest(async function testSignVerify() { +Deno.test(async function testSignVerify() { const subtle = window.crypto.subtle; assert(subtle); for (const algorithm of ["RSA-PSS", "RSASSA-PKCS1-v1_5"]) { @@ -95,7 +95,7 @@ const hashPlainTextVector = [ ]; // TODO(@littledivy): Remove this when we enable WPT for encrypt_decrypt -unitTest(async function testEncryptDecrypt() { +Deno.test(async function testEncryptDecrypt() { const subtle = window.crypto.subtle; assert(subtle); for ( @@ -148,7 +148,7 @@ unitTest(async function testEncryptDecrypt() { } }); -unitTest(async function testGenerateRSAKey() { +Deno.test(async function testGenerateRSAKey() { const subtle = window.crypto.subtle; assert(subtle); @@ -169,7 +169,7 @@ unitTest(async function testGenerateRSAKey() { assert(keyPair.privateKey.usages.includes("sign")); }); -unitTest(async function testGenerateHMACKey() { +Deno.test(async function testGenerateHMACKey() { const key = await window.crypto.subtle.generateKey( { name: "HMAC", @@ -184,7 +184,7 @@ unitTest(async function testGenerateHMACKey() { assert(key.usages.includes("sign")); }); -unitTest(async function testECDSASignVerify() { +Deno.test(async function testECDSASignVerify() { const key = await window.crypto.subtle.generateKey( { name: "ECDSA", @@ -215,7 +215,7 @@ unitTest(async function testECDSASignVerify() { }); // Tests the "bad paths" as a temporary replacement for sign_verify/ecdsa WPT. -unitTest(async function testECDSASignVerifyFail() { +Deno.test(async function testECDSASignVerifyFail() { const key = await window.crypto.subtle.generateKey( { name: "ECDSA", @@ -256,7 +256,7 @@ unitTest(async function testECDSASignVerifyFail() { }); // https://github.com/denoland/deno/issues/11313 -unitTest(async function testSignRSASSAKey() { +Deno.test(async function testSignRSASSAKey() { const subtle = window.crypto.subtle; assert(subtle); @@ -303,7 +303,7 @@ const jwk: JsonWebKey = { "key_ops": ["sign"], }; -unitTest(async function subtleCryptoHmacImportExport() { +Deno.test(async function subtleCryptoHmacImportExport() { const key1 = await crypto.subtle.importKey( "raw", rawKey, @@ -353,7 +353,7 @@ unitTest(async function subtleCryptoHmacImportExport() { }); // https://github.com/denoland/deno/issues/12085 -unitTest(async function generateImportHmacJwk() { +Deno.test(async function generateImportHmacJwk() { const key = await crypto.subtle.generateKey( { name: "HMAC", @@ -397,7 +397,7 @@ const pkcs8TestVectors = [ }, ]; -unitTest({ permissions: { read: true } }, async function importRsaPkcs8() { +Deno.test({ permissions: { read: true } }, async function importRsaPkcs8() { const pemHeader = "-----BEGIN PRIVATE KEY-----"; const pemFooter = "-----END PRIVATE KEY-----"; for (const { pem, hash } of pkcs8TestVectors) { @@ -441,7 +441,7 @@ const asn1AlgorithmIdentifier = new Uint8Array([ 0x05, 0x00, // NULL ]); -unitTest(async function rsaExport() { +Deno.test(async function rsaExport() { for (const algorithm of ["RSASSA-PKCS1-v1_5", "RSA-PSS", "RSA-OAEP"]) { const keyPair = await crypto.subtle.generateKey( { @@ -489,7 +489,7 @@ unitTest(async function rsaExport() { } }); -unitTest(async function testHkdfDeriveBits() { +Deno.test(async function testHkdfDeriveBits() { const rawKey = await crypto.getRandomValues(new Uint8Array(16)); const key = await crypto.subtle.importKey( "raw", @@ -513,7 +513,7 @@ unitTest(async function testHkdfDeriveBits() { assertEquals(result.byteLength, 128 / 8); }); -unitTest(async function testHkdfDeriveBitsWithLargeKeySize() { +Deno.test(async function testHkdfDeriveBitsWithLargeKeySize() { const key = await crypto.subtle.importKey( "raw", new Uint8Array([0x00]), @@ -538,7 +538,7 @@ unitTest(async function testHkdfDeriveBitsWithLargeKeySize() { ); }); -unitTest(async function testDeriveKey() { +Deno.test(async function testDeriveKey() { // Test deriveKey const rawKey = await crypto.getRandomValues(new Uint8Array(16)); const key = await crypto.subtle.importKey( @@ -574,7 +574,7 @@ unitTest(async function testDeriveKey() { assertEquals(algorithm.length, 256); }); -unitTest(async function testAesCbcEncryptDecrypt() { +Deno.test(async function testAesCbcEncryptDecrypt() { const key = await crypto.subtle.generateKey( { name: "AES-CBC", length: 128 }, true, @@ -609,7 +609,7 @@ unitTest(async function testAesCbcEncryptDecrypt() { }); // TODO(@littledivy): Enable WPT when we have importKey support -unitTest(async function testECDH() { +Deno.test(async function testECDH() { const namedCurve = "P-256"; const keyPair = await crypto.subtle.generateKey( { @@ -633,7 +633,7 @@ unitTest(async function testECDH() { assertEquals(derivedKey.byteLength, 256 / 8); }); -unitTest(async function testWrapKey() { +Deno.test(async function testWrapKey() { // Test wrapKey const key = await crypto.subtle.generateKey( { @@ -672,7 +672,7 @@ unitTest(async function testWrapKey() { // Doesn't need to cover all cases. // Only for testing types. -unitTest(async function testAesKeyGen() { +Deno.test(async function testAesKeyGen() { const key = await crypto.subtle.generateKey( { name: "AES-GCM", @@ -691,7 +691,7 @@ unitTest(async function testAesKeyGen() { assertEquals(algorithm.length, 256); }); -unitTest(async function testDecryptWithInvalidIntializationVector() { +Deno.test(async function testDecryptWithInvalidIntializationVector() { const data = new Uint8Array([42, 42, 42, 42]); const key = await crypto.subtle.generateKey( { name: "AES-CBC", length: 256 }, diff --git a/cli/tests/unit/webgpu_test.ts b/cli/tests/unit/webgpu_test.ts index 7cfca007d4..1d54d7b026 100644 --- a/cli/tests/unit/webgpu_test.ts +++ b/cli/tests/unit/webgpu_test.ts @@ -1,4 +1,4 @@ -import { assert, assertEquals, unitTest } from "./test_util.ts"; +import { assert, assertEquals } from "./test_util.ts"; let isCI: boolean; try { @@ -9,7 +9,7 @@ try { // Skip this test on linux CI, because the vulkan emulator is not good enough // yet, and skip on macOS because these do not have virtual GPUs. -unitTest({ +Deno.test({ permissions: { read: true, env: true }, ignore: (Deno.build.os === "linux" || Deno.build.os === "darwin") && isCI, }, async function webgpuComputePass() { @@ -100,7 +100,7 @@ unitTest({ // Skip this test on linux CI, because the vulkan emulator is not good enough // yet, and skip on macOS because these do not have virtual GPUs. -unitTest({ +Deno.test({ permissions: { read: true, env: true }, ignore: (Deno.build.os === "linux" || Deno.build.os === "darwin") && isCI, }, async function webgpuHelloTriangle() { diff --git a/cli/tests/unit/websocket_test.ts b/cli/tests/unit/websocket_test.ts index ecc86029dd..a2e72d4ea7 100644 --- a/cli/tests/unit/websocket_test.ts +++ b/cli/tests/unit/websocket_test.ts @@ -1,7 +1,7 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -import { assertThrows, unitTest } from "./test_util.ts"; +import { assertThrows } from "./test_util.ts"; -unitTest(function websocketPermissionless() { +Deno.test({ permissions: "none" }, function websocketPermissionless() { assertThrows( () => new WebSocket("ws://localhost"), Deno.errors.PermissionDenied, diff --git a/cli/tests/unit/worker_permissions_test.ts b/cli/tests/unit/worker_permissions_test.ts index 35cb2d04d5..5725f339cb 100644 --- a/cli/tests/unit/worker_permissions_test.ts +++ b/cli/tests/unit/worker_permissions_test.ts @@ -1,7 +1,7 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -import { assertEquals, deferred, unitTest } from "./test_util.ts"; +import { assertEquals, deferred } from "./test_util.ts"; -unitTest( +Deno.test( { permissions: { env: true, read: true } }, async function workerEnvArrayPermissions() { const promise = deferred(); diff --git a/cli/tests/unit/worker_types.ts b/cli/tests/unit/worker_types.ts index 0f99e15df5..1ba603796d 100644 --- a/cli/tests/unit/worker_types.ts +++ b/cli/tests/unit/worker_types.ts @@ -1,7 +1,7 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -import { assert, unitTest } from "./test_util.ts"; +import { assert } from "./test_util.ts"; -unitTest( +Deno.test( { permissions: { read: true } }, function utimeSyncFileSuccess() { const w = new Worker( diff --git a/cli/tests/unit/write_file_test.ts b/cli/tests/unit/write_file_test.ts index 9ad8da5783..66f07b9b1c 100644 --- a/cli/tests/unit/write_file_test.ts +++ b/cli/tests/unit/write_file_test.ts @@ -4,10 +4,9 @@ import { assertEquals, assertRejects, assertThrows, - unitTest, } from "./test_util.ts"; -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function writeFileSyncSuccess() { const enc = new TextEncoder(); @@ -21,7 +20,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function writeFileSyncUrl() { const enc = new TextEncoder(); @@ -40,7 +39,7 @@ unitTest( }, ); -unitTest({ permissions: { write: true } }, function writeFileSyncFail() { +Deno.test({ permissions: { write: true } }, function writeFileSyncFail() { const enc = new TextEncoder(); const data = enc.encode("Hello"); const filename = "/baddir/test.txt"; @@ -50,7 +49,7 @@ unitTest({ permissions: { write: true } }, function writeFileSyncFail() { }, Deno.errors.NotFound); }); -unitTest({ permissions: { write: false } }, function writeFileSyncPerm() { +Deno.test({ permissions: { write: false } }, function writeFileSyncPerm() { const enc = new TextEncoder(); const data = enc.encode("Hello"); const filename = "/baddir/test.txt"; @@ -60,7 +59,7 @@ unitTest({ permissions: { write: false } }, function writeFileSyncPerm() { }, Deno.errors.PermissionDenied); }); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function writeFileSyncUpdateMode() { if (Deno.build.os !== "windows") { @@ -75,7 +74,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function writeFileSyncCreate() { const enc = new TextEncoder(); @@ -96,7 +95,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function writeFileSyncAppend() { const enc = new TextEncoder(); @@ -121,7 +120,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function writeFileSuccess() { const enc = new TextEncoder(); @@ -135,7 +134,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function writeFileUrl() { const enc = new TextEncoder(); @@ -154,7 +153,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function writeFileNotFound() { const enc = new TextEncoder(); @@ -167,7 +166,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: false } }, async function writeFilePerm() { const enc = new TextEncoder(); @@ -180,7 +179,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function writeFileUpdateMode() { if (Deno.build.os !== "windows") { @@ -195,7 +194,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function writeFileCreate() { const enc = new TextEncoder(); @@ -216,7 +215,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function writeFileAppend() { const enc = new TextEncoder(); @@ -241,7 +240,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function writeFileAbortSignal(): Promise { const ac = new AbortController(); @@ -260,7 +259,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function writeFileAbortSignalPreAborted(): Promise { const ac = new AbortController(); diff --git a/cli/tests/unit/write_text_file_test.ts b/cli/tests/unit/write_text_file_test.ts index 4424db7db5..ed92b0f35b 100644 --- a/cli/tests/unit/write_text_file_test.ts +++ b/cli/tests/unit/write_text_file_test.ts @@ -3,10 +3,9 @@ import { assertEquals, assertRejects, assertThrows, - unitTest, } from "./test_util.ts"; -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function writeTextFileSyncSuccess() { const filename = Deno.makeTempDirSync() + "/test.txt"; @@ -16,7 +15,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function writeTextFileSyncByUrl() { const tempDir = Deno.makeTempDirSync(); @@ -31,7 +30,7 @@ unitTest( }, ); -unitTest({ permissions: { write: true } }, function writeTextFileSyncFail() { +Deno.test({ permissions: { write: true } }, function writeTextFileSyncFail() { const filename = "/baddir/test.txt"; // The following should fail because /baddir doesn't exist (hopefully). assertThrows(() => { @@ -39,7 +38,7 @@ unitTest({ permissions: { write: true } }, function writeTextFileSyncFail() { }, Deno.errors.NotFound); }); -unitTest({ permissions: { write: false } }, function writeTextFileSyncPerm() { +Deno.test({ permissions: { write: false } }, function writeTextFileSyncPerm() { const filename = "/baddir/test.txt"; // The following should fail due to no write permission assertThrows(() => { @@ -47,7 +46,7 @@ unitTest({ permissions: { write: false } }, function writeTextFileSyncPerm() { }, Deno.errors.PermissionDenied); }); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function writeTextFileSyncUpdateMode() { if (Deno.build.os !== "windows") { @@ -61,7 +60,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function writeTextFileSyncCreate() { const data = "Hello"; @@ -83,7 +82,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, function writeTextFileSyncAppend() { const data = "Hello"; @@ -100,7 +99,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function writeTextFileSuccess() { const filename = Deno.makeTempDirSync() + "/test.txt"; @@ -110,7 +109,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function writeTextFileByUrl() { const tempDir = Deno.makeTempDirSync(); @@ -125,7 +124,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function writeTextFileNotFound() { const filename = "/baddir/test.txt"; @@ -136,7 +135,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { write: false } }, async function writeTextFilePerm() { const filename = "/baddir/test.txt"; @@ -147,7 +146,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function writeTextFileUpdateMode() { if (Deno.build.os !== "windows") { @@ -161,7 +160,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function writeTextFileCreate() { const data = "Hello"; @@ -183,7 +182,7 @@ unitTest( }, ); -unitTest( +Deno.test( { permissions: { read: true, write: true } }, async function writeTextFileAppend() { const data = "Hello";