diff options
Diffstat (limited to 'cli/tests')
25 files changed, 113 insertions, 134 deletions
diff --git a/cli/tests/unit/buffer_test.ts b/cli/tests/unit/buffer_test.ts index 30198d0b9..ceeb3fb8a 100644 --- a/cli/tests/unit/buffer_test.ts +++ b/cli/tests/unit/buffer_test.ts @@ -8,8 +8,8 @@ import { assert, assertEquals, + assertRejects, assertThrows, - assertThrowsAsync, unitTest, } from "./test_util.ts"; @@ -200,7 +200,7 @@ unitTest( const reader = new Deno.Buffer(new ArrayBuffer(MAX_SIZE + 1)); const buf = new Deno.Buffer(); - await assertThrowsAsync( + await assertRejects( async () => { await buf.readFrom(reader); }, @@ -302,7 +302,7 @@ unitTest(async function bufferReadFrom() { const fub = new Uint8Array(testString.length); await empty(b, s, fub); } - assertThrowsAsync(async function () { + assertRejects(async function () { await new Deno.Buffer().readFrom(null!); }); }); diff --git a/cli/tests/unit/chmod_test.ts b/cli/tests/unit/chmod_test.ts index 5908ea09a..5844c0ef8 100644 --- a/cli/tests/unit/chmod_test.ts +++ b/cli/tests/unit/chmod_test.ts @@ -2,8 +2,8 @@ import { assert, assertEquals, + assertRejects, assertThrows, - assertThrowsAsync, unitTest, } from "./test_util.ts"; @@ -158,14 +158,14 @@ unitTest( ); unitTest({ perms: { write: true } }, async function chmodFailure() { - await assertThrowsAsync(async () => { + await assertRejects(async () => { const filename = "/badfile.txt"; await Deno.chmod(filename, 0o777); }, Deno.errors.NotFound); }); unitTest({ perms: { write: false } }, async function chmodPerm() { - await assertThrowsAsync(async () => { + 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 a8d264a6c..447f1bde0 100644 --- a/cli/tests/unit/chown_test.ts +++ b/cli/tests/unit/chown_test.ts @@ -1,8 +1,8 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. import { assertEquals, + assertRejects, assertThrows, - assertThrowsAsync, unitTest, } from "./test_util.ts"; @@ -33,7 +33,7 @@ unitTest( { ignore: Deno.build.os == "windows" }, async function chownNoWritePermission() { const filePath = "chown_test_file.txt"; - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno.chown(filePath, 1000, 1000); }, Deno.errors.PermissionDenied); }, @@ -57,7 +57,7 @@ unitTest( const { uid, gid } = await getUidAndGid(); const filePath = (await Deno.makeTempDir()) + "/chown_test_file.txt"; - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno.chown(filePath, uid, gid); }, Deno.errors.NotFound); }, @@ -85,7 +85,7 @@ unitTest( const filePath = dirPath + "/chown_test_file.txt"; await Deno.writeTextFile(filePath, "Hello"); - await assertThrowsAsync(async () => { + await assertRejects(async () => { // try changing the file's owner to root await Deno.chown(filePath, 0, 0); }, Deno.errors.PermissionDenied); diff --git a/cli/tests/unit/copy_file_test.ts b/cli/tests/unit/copy_file_test.ts index f89c1c9ee..c9b82c77e 100644 --- a/cli/tests/unit/copy_file_test.ts +++ b/cli/tests/unit/copy_file_test.ts @@ -1,8 +1,8 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. import { assertEquals, + assertRejects, assertThrows, - assertThrowsAsync, unitTest, } from "./test_util.ts"; @@ -162,7 +162,7 @@ unitTest( const fromFilename = tempDir + "/from.txt"; const toFilename = tempDir + "/to.txt"; // We skip initial writing here, from.txt does not exist - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno.copyFile(fromFilename, toFilename); }, Deno.errors.NotFound); @@ -192,7 +192,7 @@ unitTest( unitTest( { perms: { read: false, write: true } }, async function copyFilePerm1() { - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno.copyFile("/from.txt", "/to.txt"); }, Deno.errors.PermissionDenied); }, @@ -201,7 +201,7 @@ unitTest( unitTest( { perms: { read: true, write: false } }, async function copyFilePerm2() { - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno.copyFile("/from.txt", "/to.txt"); }, Deno.errors.PermissionDenied); }, diff --git a/cli/tests/unit/fetch_test.ts b/cli/tests/unit/fetch_test.ts index c26718d02..a1609c775 100644 --- a/cli/tests/unit/fetch_test.ts +++ b/cli/tests/unit/fetch_test.ts @@ -2,7 +2,7 @@ import { assert, assertEquals, - assertThrowsAsync, + assertRejects, deferred, fail, unimplemented, @@ -13,7 +13,7 @@ import { Buffer } from "../../../test_util/std/io/buffer.ts"; unitTest( { perms: { net: true } }, async function fetchRequiresOneArgument() { - await assertThrowsAsync( + await assertRejects( fetch as unknown as () => Promise<void>, TypeError, ); @@ -21,7 +21,7 @@ unitTest( ); unitTest({ perms: { net: true } }, async function fetchProtocolError() { - await assertThrowsAsync( + await assertRejects( async () => { await fetch("file:///"); }, @@ -58,7 +58,7 @@ unitTest( { perms: { net: true } }, async function fetchConnectionError() { const port = findClosedPortInRange(4000, 9999); - await assertThrowsAsync( + await assertRejects( async () => { await fetch(`http://localhost:${port}`); }, @@ -71,7 +71,7 @@ unitTest( unitTest( { perms: { net: true } }, async function fetchDnsError() { - await assertThrowsAsync( + await assertRejects( async () => { await fetch("http://nil/"); }, @@ -84,7 +84,7 @@ unitTest( unitTest( { perms: { net: true } }, async function fetchInvalidUriError() { - await assertThrowsAsync( + await assertRejects( async () => { await fetch("http://<invalid>/"); }, @@ -100,7 +100,7 @@ unitTest({ perms: { net: true } }, async function fetchJsonSuccess() { }); unitTest(async function fetchPerm() { - await assertThrowsAsync(async () => { + await assertRejects(async () => { await fetch("http://localhost:4545/fixture.json"); }, Deno.errors.PermissionDenied); }); @@ -258,7 +258,7 @@ unitTest( ); assert(response.body !== null); - await assertThrowsAsync( + await assertRejects( async () => { await response.formData(); }, @@ -410,7 +410,7 @@ unitTest( perms: { net: true }, }, async function fetchWithInfRedirection() { - await assertThrowsAsync( + await assertRejects( () => fetch("http://localhost:4549"), TypeError, "redirect", @@ -760,7 +760,7 @@ unitTest( perms: { net: true }, }, async function fetchWithErrorRedirection() { - await assertThrowsAsync( + await assertRejects( () => fetch("http://localhost:4546/", { redirect: "error", @@ -790,7 +790,7 @@ unitTest(async function responseWithoutBody() { assertEquals(blob.size, 0); assertEquals(await blob.arrayBuffer(), new ArrayBuffer(0)); assertEquals(await response.text(), ""); - await assertThrowsAsync(async () => { + await assertRejects(async () => { await response.json(); }); }); @@ -1176,7 +1176,7 @@ unitTest( }, }); const nonExistantHostname = "http://localhost:47582"; - await assertThrowsAsync(async () => { + await assertRejects(async () => { await fetch(nonExistantHostname, { body, method: "POST" }); }, TypeError); await done; @@ -1196,7 +1196,7 @@ unitTest( unitTest( { perms: { read: true, net: true } }, async function fetchClientCertWrongPrivateKey(): Promise<void> { - await assertThrowsAsync(async () => { + await assertRejects(async () => { const client = Deno.createHttpClient({ certChain: "bad data", privateKey: await Deno.readTextFile( @@ -1213,7 +1213,7 @@ unitTest( unitTest( { perms: { read: true, net: true } }, async function fetchClientCertBadPrivateKey(): Promise<void> { - await assertThrowsAsync(async () => { + await assertRejects(async () => { const client = Deno.createHttpClient({ certChain: await Deno.readTextFile( "cli/tests/testdata/tls/localhost.crt", @@ -1230,7 +1230,7 @@ unitTest( unitTest( { perms: { read: true, net: true } }, async function fetchClientCertNotPrivateKey(): Promise<void> { - await assertThrowsAsync(async () => { + await assertRejects(async () => { const client = Deno.createHttpClient({ certChain: await Deno.readTextFile( "cli/tests/testdata/tls/localhost.crt", diff --git a/cli/tests/unit/files_test.ts b/cli/tests/unit/files_test.ts index fed7c3252..65504f23f 100644 --- a/cli/tests/unit/files_test.ts +++ b/cli/tests/unit/files_test.ts @@ -2,12 +2,7 @@ // deno-lint-ignore-file no-deprecated-deno-api -import { - assert, - assertEquals, - assertThrowsAsync, - unitTest, -} from "./test_util.ts"; +import { assert, assertEquals, assertRejects, unitTest } from "./test_util.ts"; import { copy } from "../../../test_util/std/io/util.ts"; unitTest(function filesStdioFileDescriptors() { @@ -256,7 +251,7 @@ unitTest( const filename = "tests/hello.txt"; const openOptions: Deno.OpenOptions[] = [{ write: true }, { append: true }]; for (const options of openOptions) { - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno.open(filename, options); }, Deno.errors.PermissionDenied); } @@ -265,7 +260,7 @@ unitTest( unitTest(async function openOptions() { const filename = "cli/tests/testdata/fixture.json"; - await assertThrowsAsync( + await assertRejects( async () => { await Deno.open(filename, { write: false }); }, @@ -273,7 +268,7 @@ unitTest(async function openOptions() { "OpenOptions requires at least one option to be true", ); - await assertThrowsAsync( + await assertRejects( async () => { await Deno.open(filename, { truncate: true, write: false }); }, @@ -281,7 +276,7 @@ unitTest(async function openOptions() { "'truncate' option requires 'write' option", ); - await assertThrowsAsync( + await assertRejects( async () => { await Deno.open(filename, { create: true, write: false }); }, @@ -289,7 +284,7 @@ unitTest(async function openOptions() { "'create' or 'createNew' options require 'write' or 'append' option", ); - await assertThrowsAsync( + await assertRejects( async () => { await Deno.open(filename, { createNew: true, append: false }); }, @@ -299,7 +294,7 @@ unitTest(async function openOptions() { }); unitTest({ perms: { read: false } }, async function readPermFailure() { - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno.open("package.json", { read: true }); }, Deno.errors.PermissionDenied); }); @@ -317,7 +312,7 @@ unitTest( const file = await Deno.open(filename, w); // writing null should throw an error - await assertThrowsAsync( + await assertRejects( async () => { // deno-lint-ignore no-explicit-any await file.write(null as any); @@ -345,7 +340,7 @@ unitTest( assert(bytesRead === 0); // reading file into null buffer should throw an error - await assertThrowsAsync(async () => { + await assertRejects(async () => { // deno-lint-ignore no-explicit-any await file.read(null as any); }, TypeError); @@ -360,7 +355,7 @@ unitTest( { perms: { write: false, read: false } }, async function readWritePermFailure() { const filename = "tests/hello.txt"; - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno.open(filename, { read: true }); }, Deno.errors.PermissionDenied); }, @@ -630,7 +625,7 @@ unitTest({ perms: { read: true } }, function seekSyncEnd() { unitTest({ perms: { read: true } }, async function seekMode() { const filename = "cli/tests/testdata/hello.txt"; const file = await Deno.open(filename); - await assertThrowsAsync( + await assertRejects( async () => { await file.seek(1, -1); }, diff --git a/cli/tests/unit/make_temp_test.ts b/cli/tests/unit/make_temp_test.ts index 5b28c210b..99559623f 100644 --- a/cli/tests/unit/make_temp_test.ts +++ b/cli/tests/unit/make_temp_test.ts @@ -2,8 +2,8 @@ import { assert, assertEquals, + assertRejects, assertThrows, - assertThrowsAsync, unitTest, } from "./test_util.ts"; @@ -64,7 +64,7 @@ unitTest( assert(dir3.startsWith(dir1)); assert(/^[\\\/]/.test(dir3.slice(dir1.length))); // Check that creating a temp dir inside a nonexisting directory fails. - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno.makeTempDir({ dir: "/baddir" }); }, Deno.errors.NotFound); }, @@ -140,7 +140,7 @@ unitTest( assert(file3.startsWith(dir)); assert(/^[\\\/]/.test(file3.slice(dir.length))); // Check that creating a temp file inside a nonexisting directory fails. - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno.makeTempFile({ dir: "/baddir" }); }, Deno.errors.NotFound); }, diff --git a/cli/tests/unit/mkdir_test.ts b/cli/tests/unit/mkdir_test.ts index 586c1ebe3..931462743 100644 --- a/cli/tests/unit/mkdir_test.ts +++ b/cli/tests/unit/mkdir_test.ts @@ -2,8 +2,8 @@ import { assert, assertEquals, + assertRejects, assertThrows, - assertThrowsAsync, pathToAbsoluteFileUrl, unitTest, } from "./test_util.ts"; @@ -65,7 +65,7 @@ unitTest({ perms: { write: true } }, function mkdirErrSyncIfExists() { }); unitTest({ perms: { write: true } }, async function mkdirErrIfExists() { - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno.mkdir("."); }, Deno.errors.AlreadyExists); }); diff --git a/cli/tests/unit/net_test.ts b/cli/tests/unit/net_test.ts index bd949b02d..597bc4be1 100644 --- a/cli/tests/unit/net_test.ts +++ b/cli/tests/unit/net_test.ts @@ -3,8 +3,8 @@ import { assert, assertEquals, assertNotEquals, + assertRejects, assertThrows, - assertThrowsAsync, deferred, delay, unitTest, @@ -111,7 +111,7 @@ unitTest( const listener = Deno.listen({ port: 4501 }); const p = listener.accept(); listener.close(); - await assertThrowsAsync( + await assertRejects( async () => { await p; }, @@ -131,7 +131,7 @@ unitTest( }); const p = listener.accept(); listener.close(); - await assertThrowsAsync( + await assertRejects( async () => { await p; }, @@ -537,7 +537,7 @@ unitTest( assertEquals(3, buf[2]); // Verify that the write end of the socket is closed. // TODO(piscisaureus): assert that thrown error is of a specific type. - await assertThrowsAsync(async () => { + await assertRejects(async () => { await conn.write(new Uint8Array([1, 2, 3])); }); closeDeferred.resolve(); diff --git a/cli/tests/unit/permissions_test.ts b/cli/tests/unit/permissions_test.ts index 45ba39b96..f1e66fb3c 100644 --- a/cli/tests/unit/permissions_test.ts +++ b/cli/tests/unit/permissions_test.ts @@ -2,20 +2,20 @@ import { assert, assertEquals, + assertRejects, assertThrows, - assertThrowsAsync, unitTest, } from "./test_util.ts"; unitTest(async function permissionInvalidName() { - await assertThrowsAsync(async () => { + await assertRejects(async () => { // deno-lint-ignore no-explicit-any await Deno.permissions.query({ name: "foo" as any }); }, TypeError); }); unitTest(async function permissionNetInvalidHost() { - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno.permissions.query({ name: "net", host: ":" }); }, URIError); }); diff --git a/cli/tests/unit/read_dir_test.ts b/cli/tests/unit/read_dir_test.ts index 4f02fae9b..49f899feb 100644 --- a/cli/tests/unit/read_dir_test.ts +++ b/cli/tests/unit/read_dir_test.ts @@ -2,8 +2,8 @@ import { assert, assertEquals, + assertRejects, assertThrows, - assertThrowsAsync, pathToAbsoluteFileUrl, unitTest, } from "./test_util.ts"; @@ -70,7 +70,7 @@ unitTest({ perms: { read: true } }, async function readDirWithUrl() { }); unitTest({ perms: { read: false } }, async function readDirPerm() { - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno.readDir("tests/")[Symbol.asyncIterator]().next(); }, Deno.errors.PermissionDenied); }); diff --git a/cli/tests/unit/read_file_test.ts b/cli/tests/unit/read_file_test.ts index 7dd2b5621..8291877b4 100644 --- a/cli/tests/unit/read_file_test.ts +++ b/cli/tests/unit/read_file_test.ts @@ -2,8 +2,8 @@ import { assert, assertEquals, + assertRejects, assertThrows, - assertThrowsAsync, pathToAbsoluteFileUrl, unitTest, } from "./test_util.ts"; @@ -61,7 +61,7 @@ unitTest({ perms: { read: true } }, async function readFileSuccess() { }); unitTest({ perms: { read: false } }, async function readFilePerm() { - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno.readFile("cli/tests/testdata/fixture.json"); }, Deno.errors.PermissionDenied); }); @@ -76,7 +76,7 @@ unitTest( { perms: { read: true } }, async function readFileDoesNotLeakResources() { const resourcesBefore = Deno.resources(); - await assertThrowsAsync(async () => await Deno.readFile("cli")); + await assertRejects(async () => await Deno.readFile("cli")); assertEquals(resourcesBefore, Deno.resources()); }, ); @@ -95,7 +95,7 @@ unitTest( async function readFileWithAbortSignal() { const ac = new AbortController(); queueMicrotask(() => ac.abort()); - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno.readFile("cli/tests/testdata/fixture.json", { signal: ac.signal, }); @@ -108,7 +108,7 @@ unitTest( async function readTextileWithAbortSignal() { const ac = new AbortController(); queueMicrotask(() => ac.abort()); - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno.readTextFile("cli/tests/testdata/fixture.json", { signal: ac.signal, }); diff --git a/cli/tests/unit/read_link_test.ts b/cli/tests/unit/read_link_test.ts index 3d00cda1a..3e3fbe4f1 100644 --- a/cli/tests/unit/read_link_test.ts +++ b/cli/tests/unit/read_link_test.ts @@ -1,8 +1,8 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. import { assertEquals, + assertRejects, assertThrows, - assertThrowsAsync, pathToAbsoluteFileUrl, unitTest, } from "./test_util.ts"; @@ -80,7 +80,7 @@ unitTest( ); unitTest({ perms: { read: false } }, async function readLinkPerm() { - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno.readLink("/symlink"); }, Deno.errors.PermissionDenied); }); diff --git a/cli/tests/unit/read_text_file_test.ts b/cli/tests/unit/read_text_file_test.ts index 3d7ccfaa6..518b6fa48 100644 --- a/cli/tests/unit/read_text_file_test.ts +++ b/cli/tests/unit/read_text_file_test.ts @@ -1,8 +1,8 @@ import { assert, assertEquals, + assertRejects, assertThrows, - assertThrowsAsync, pathToAbsoluteFileUrl, unitTest, } from "./test_util.ts"; @@ -55,7 +55,7 @@ unitTest({ perms: { read: true } }, async function readTextFileByUrl() { }); unitTest({ perms: { read: false } }, async function readTextFilePerm() { - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno.readTextFile("cli/tests/testdata/fixture.json"); }, Deno.errors.PermissionDenied); }); @@ -70,7 +70,7 @@ unitTest( { perms: { read: true } }, async function readTextFileDoesNotLeakResources() { const resourcesBefore = Deno.resources(); - await assertThrowsAsync(async () => await Deno.readTextFile("cli")); + await assertRejects(async () => await Deno.readTextFile("cli")); assertEquals(resourcesBefore, Deno.resources()); }, ); diff --git a/cli/tests/unit/real_path_test.ts b/cli/tests/unit/real_path_test.ts index 8c0728ca9..542d06996 100644 --- a/cli/tests/unit/real_path_test.ts +++ b/cli/tests/unit/real_path_test.ts @@ -3,8 +3,8 @@ import { assert, assertEquals, assertMatch, + assertRejects, assertThrows, - assertThrowsAsync, pathToAbsoluteFileUrl, unitTest, } from "./test_util.ts"; @@ -103,13 +103,13 @@ unitTest( ); unitTest({ perms: { read: false } }, async function realPathPerm() { - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno.realPath("some_file"); }, Deno.errors.PermissionDenied); }); unitTest({ perms: { read: true } }, async function realPathNotFound() { - await assertThrowsAsync(async () => { + 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 5f39b1c79..36b5cc051 100644 --- a/cli/tests/unit/remove_test.ts +++ b/cli/tests/unit/remove_test.ts @@ -1,10 +1,5 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -import { - assert, - assertThrows, - assertThrowsAsync, - unitTest, -} from "./test_util.ts"; +import { assert, assertRejects, assertThrows, unitTest } from "./test_util.ts"; const REMOVE_METHODS = ["remove", "removeSync"] as const; @@ -85,13 +80,13 @@ unitTest( const subPathInfo = Deno.statSync(subPath); assert(subPathInfo.isDirectory); // check exist first - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno[method](path); }, Error); // TODO(ry) Is Other really the error we should get here? What would Go do? // NON-EXISTENT DIRECTORY/FILE - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno[method]("/baddir"); }, Deno.errors.NotFound); } @@ -148,7 +143,7 @@ unitTest( unitTest({ perms: { write: false } }, async function removePerm() { for (const method of REMOVE_METHODS) { - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno[method]("/baddir"); }, Deno.errors.PermissionDenied); } @@ -215,7 +210,7 @@ unitTest( unitTest({ perms: { write: true } }, async function removeAllFail() { for (const method of REMOVE_METHODS) { // NON-EXISTENT DIRECTORY/FILE - await assertThrowsAsync(async () => { + await assertRejects(async () => { // Non-existent await Deno[method]("/baddir", { recursive: true }); }, Deno.errors.NotFound); @@ -224,7 +219,7 @@ unitTest({ perms: { write: true } }, async function removeAllFail() { unitTest({ perms: { write: false } }, async function removeAllPerm() { for (const method of REMOVE_METHODS) { - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno[method]("/baddir", { recursive: true }); }, Deno.errors.PermissionDenied); } @@ -263,7 +258,7 @@ if (Deno.build.os === "windows") { assert(await symlink.status()); symlink.close(); await Deno.remove("file_link"); - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno.lstat("file_link"); }, Deno.errors.NotFound); }, @@ -281,7 +276,7 @@ if (Deno.build.os === "windows") { symlink.close(); await Deno.remove("dir_link"); - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno.lstat("dir_link"); }, Deno.errors.NotFound); }, diff --git a/cli/tests/unit/stat_test.ts b/cli/tests/unit/stat_test.ts index 7db9dee71..3630e369c 100644 --- a/cli/tests/unit/stat_test.ts +++ b/cli/tests/unit/stat_test.ts @@ -2,8 +2,8 @@ import { assert, assertEquals, + assertRejects, assertThrows, - assertThrowsAsync, pathToAbsoluteFileUrl, unitTest, } from "./test_util.ts"; @@ -220,13 +220,13 @@ unitTest( ); unitTest({ perms: { read: false } }, async function statPerm() { - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno.stat("README.md"); }, Deno.errors.PermissionDenied); }); unitTest({ perms: { read: true } }, async function statNotFound() { - await assertThrowsAsync( + await assertRejects( async () => { await Deno.stat("bad_file_name"), Deno.errors.NotFound; }, @@ -262,13 +262,13 @@ unitTest({ perms: { read: true } }, async function lstatSuccess() { }); unitTest({ perms: { read: false } }, async function lstatPerm() { - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno.lstat("README.md"); }, Deno.errors.PermissionDenied); }); unitTest({ perms: { read: true } }, async function lstatNotFound() { - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno.lstat("bad_file_name"); }, Deno.errors.NotFound); }); diff --git a/cli/tests/unit/test_util.ts b/cli/tests/unit/test_util.ts index 6508abd20..420a5fd9a 100644 --- a/cli/tests/unit/test_util.ts +++ b/cli/tests/unit/test_util.ts @@ -16,7 +16,6 @@ export { assertStrictEquals, assertStringIncludes, assertThrows, - assertThrowsAsync, fail, unimplemented, unreachable, diff --git a/cli/tests/unit/tls_test.ts b/cli/tests/unit/tls_test.ts index 12fe9bd50..ae5a6562d 100644 --- a/cli/tests/unit/tls_test.ts +++ b/cli/tests/unit/tls_test.ts @@ -3,9 +3,9 @@ import { assert, assertEquals, assertNotEquals, + assertRejects, assertStrictEquals, assertThrows, - assertThrowsAsync, Deferred, deferred, unitTest, @@ -26,7 +26,7 @@ function unreachable(): never { } unitTest(async function connectTLSNoPerm() { - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno.connectTls({ hostname: "deno.land", port: 443 }); }, Deno.errors.PermissionDenied); }); @@ -41,7 +41,7 @@ unitTest( keyFile: "cli/tests/testdata/tls/localhost.key", }); - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno.connectTls({ hostname: "127.0.0.1", port: 3567 }); }, TypeError); @@ -50,7 +50,7 @@ unitTest( ); unitTest(async function connectTLSCertFileNoReadPerm() { - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno.connectTls({ hostname: "deno.land", port: 443, @@ -405,7 +405,7 @@ async function sendAlotReceiveNothing(conn: Deno.Conn) { conn.close(); // Read op should be canceled. - await assertThrowsAsync( + await assertRejects( async () => await readPromise, Deno.errors.Interrupted, ); @@ -471,7 +471,7 @@ async function sendReceiveEmptyBuf(conn: Deno.Conn) { n = await conn.write(emptyBuf); assertStrictEquals(n, 0); - await assertThrowsAsync(async () => { + await assertRejects(async () => { await conn.write(byteBuf); }, Deno.errors.BrokenPipe); @@ -627,22 +627,22 @@ async function tlsWithTcpFailureTestImpl( } const tlsTrafficPromise1 = Promise.all([ - assertThrowsAsync( + assertRejects( () => sendBytes(tlsConn1, 0x01, 1), expectedError, ), - assertThrowsAsync( + assertRejects( () => receiveBytes(tlsConn1, 0x02, 1), expectedError, ), ]); const tlsTrafficPromise2 = Promise.all([ - assertThrowsAsync( + assertRejects( () => sendBytes(tlsConn2, 0x02, 1), Deno.errors.UnexpectedEof, ), - assertThrowsAsync( + assertRejects( () => receiveBytes(tlsConn2, 0x01, 1), Deno.errors.UnexpectedEof, ), @@ -684,7 +684,7 @@ async function tlsWithTcpFailureTestImpl( switch (failureMode) { case "corruption": await sendBytes(tcpConn1, 0xff, 1 << 14 /* 16 kB */); - await assertThrowsAsync( + await assertRejects( () => receiveEof(tlsConn1), Deno.errors.InvalidData, ); @@ -990,7 +990,7 @@ unitTest( unitTest( { perms: { read: true, net: true } }, async function connectTLSBadClientCertPrivateKey(): Promise<void> { - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno.connectTls({ hostname: "deno.land", port: 443, @@ -1006,7 +1006,7 @@ unitTest( unitTest( { perms: { read: true, net: true } }, async function connectTLSBadPrivateKey(): Promise<void> { - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno.connectTls({ hostname: "deno.land", port: 443, @@ -1022,7 +1022,7 @@ unitTest( unitTest( { perms: { read: true, net: true } }, async function connectTLSNotPrivateKey(): Promise<void> { - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno.connectTls({ hostname: "deno.land", port: 443, diff --git a/cli/tests/unit/truncate_test.ts b/cli/tests/unit/truncate_test.ts index 14309d0c1..89ca12634 100644 --- a/cli/tests/unit/truncate_test.ts +++ b/cli/tests/unit/truncate_test.ts @@ -1,8 +1,8 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. import { assertEquals, + assertRejects, assertThrows, - assertThrowsAsync, unitTest, } from "./test_util.ts"; @@ -87,7 +87,7 @@ unitTest({ perms: { write: false } }, function truncateSyncPerm() { }); unitTest({ perms: { write: false } }, async function truncatePerm() { - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno.truncate("/test_truncatePermission.txt"); }, Deno.errors.PermissionDenied); }); diff --git a/cli/tests/unit/utime_test.ts b/cli/tests/unit/utime_test.ts index f5647d220..d5f3fd464 100644 --- a/cli/tests/unit/utime_test.ts +++ b/cli/tests/unit/utime_test.ts @@ -1,8 +1,8 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. import { assertEquals, + assertRejects, assertThrows, - assertThrowsAsync, pathToAbsoluteFileUrl, unitTest, } from "./test_util.ts"; @@ -271,7 +271,7 @@ unitTest( const atime = 1000; const mtime = 50000; - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno.utime("/baddir", atime, mtime); }, Deno.errors.NotFound); }, @@ -283,7 +283,7 @@ unitTest( const atime = 1000; const mtime = 50000; - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno.utime("/some_dir", atime, mtime); }, Deno.errors.PermissionDenied); }, diff --git a/cli/tests/unit/wasm_test.ts b/cli/tests/unit/wasm_test.ts index 938eeab7a..7fcc33d96 100644 --- a/cli/tests/unit/wasm_test.ts +++ b/cli/tests/unit/wasm_test.ts @@ -1,9 +1,4 @@ -import { - assert, - assertEquals, - assertThrowsAsync, - unitTest, -} from "./test_util.ts"; +import { assert, assertEquals, assertRejects, unitTest } from "./test_util.ts"; // The following blob can be created by taking the following s-expr and pass // it through wat2wasm. @@ -39,7 +34,7 @@ unitTest(async function wasmInstantiateWorksWithBuffer() { // check that our implementation of the callback disallows it. unitTest( async function wasmInstantiateStreamingFailsWithBuffer() { - await assertThrowsAsync(async () => { + await assertRejects(async () => { await WebAssembly.instantiateStreaming( // Bypassing the type system simpleWasm as unknown as Promise<Response>, @@ -50,7 +45,7 @@ unitTest( unitTest( async function wasmInstantiateStreamingNoContentType() { - await assertThrowsAsync( + await assertRejects( async () => { const response = Promise.resolve(new Response(simpleWasm)); await WebAssembly.instantiateStreaming(response); diff --git a/cli/tests/unit/webcrypto_test.ts b/cli/tests/unit/webcrypto_test.ts index 7a2bed758..639c623f9 100644 --- a/cli/tests/unit/webcrypto_test.ts +++ b/cli/tests/unit/webcrypto_test.ts @@ -1,9 +1,4 @@ -import { - assert, - assertEquals, - assertThrowsAsync, - unitTest, -} from "./test_util.ts"; +import { assert, assertEquals, assertRejects, unitTest } from "./test_util.ts"; // https://github.com/denoland/deno/issues/11664 unitTest(async function testImportArrayBufferKey() { @@ -141,7 +136,7 @@ unitTest(async function testEncryptDecrypt() { const badPlainText = new Uint8Array(plainText.byteLength + 1); badPlainText.set(plainText, 0); badPlainText.set(new Uint8Array([32]), plainText.byteLength); - await assertThrowsAsync(async () => { + await assertRejects(async () => { // Should fail await subtle.encrypt( encryptAlgorithm, @@ -232,7 +227,7 @@ unitTest(async function testECDSASignVerifyFail() { const encoded = new Uint8Array([1]); // Signing with a public key (InvalidAccessError) - await assertThrowsAsync(async () => { + await assertRejects(async () => { await window.crypto.subtle.sign( { name: "ECDSA", hash: "SHA-384" }, key.publicKey, @@ -249,7 +244,7 @@ unitTest(async function testECDSASignVerifyFail() { ); // Verifying with a private key (InvalidAccessError) - await assertThrowsAsync(async () => { + await assertRejects(async () => { await window.crypto.subtle.verify( { hash: { name: "SHA-384" }, name: "ECDSA" }, key.privateKey, diff --git a/cli/tests/unit/write_file_test.ts b/cli/tests/unit/write_file_test.ts index c4c437708..265edbd95 100644 --- a/cli/tests/unit/write_file_test.ts +++ b/cli/tests/unit/write_file_test.ts @@ -1,8 +1,8 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. import { assertEquals, + assertRejects, assertThrows, - assertThrowsAsync, unitTest, } from "./test_util.ts"; @@ -160,7 +160,7 @@ unitTest( const data = enc.encode("Hello"); const filename = "/baddir/test.txt"; // The following should fail because /baddir doesn't exist (hopefully). - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno.writeFile(filename, data); }, Deno.errors.NotFound); }, @@ -173,7 +173,7 @@ unitTest( const data = enc.encode("Hello"); const filename = "/baddir/test.txt"; // The following should fail due to no write permission - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno.writeFile(filename, data); }, Deno.errors.PermissionDenied); }, @@ -201,7 +201,7 @@ unitTest( const data = enc.encode("Hello"); const filename = Deno.makeTempDirSync() + "/test.txt"; // if create turned off, the file won't be created - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno.writeFile(filename, data, { create: false }); }, Deno.errors.NotFound); diff --git a/cli/tests/unit/write_text_file_test.ts b/cli/tests/unit/write_text_file_test.ts index 2d14dc712..0ac421116 100644 --- a/cli/tests/unit/write_text_file_test.ts +++ b/cli/tests/unit/write_text_file_test.ts @@ -1,8 +1,8 @@ import { assert, assertEquals, + assertRejects, assertThrows, - assertThrowsAsync, unitTest, } from "./test_util.ts"; @@ -130,7 +130,7 @@ unitTest( async function writeTextFileNotFound() { const filename = "/baddir/test.txt"; // The following should fail because /baddir doesn't exist (hopefully). - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno.writeTextFile(filename, "Hello"); }, Deno.errors.NotFound); }, @@ -141,7 +141,7 @@ unitTest( async function writeTextFilePerm() { const filename = "/baddir/test.txt"; // The following should fail due to no write permission - await assertThrowsAsync(async () => { + await assertRejects(async () => { await Deno.writeTextFile(filename, "Hello"); }, Deno.errors.PermissionDenied); }, |