1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -05:00

chore: replace calls to assertThrowsAsync with assertRejects (#12176)

This commit is contained in:
Casper Beyer 2021-09-22 21:21:11 +08:00 committed by GitHub
parent 82cfb46bd1
commit 20692f3e84
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 113 additions and 134 deletions

View file

@ -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!);
});
});

View file

@ -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);
});

View file

@ -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);

View file

@ -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);
},

View file

@ -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",

View file

@ -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);
},

View file

@ -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);
},

View file

@ -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);
});

View file

@ -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();

View file

@ -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);
});

View file

@ -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);
});

View file

@ -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,
});

View file

@ -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);
});

View file

@ -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());
},
);

View file

@ -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);
});

View file

@ -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);
},

View file

@ -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);
});

View file

@ -16,7 +16,6 @@ export {
assertStrictEquals,
assertStringIncludes,
assertThrows,
assertThrowsAsync,
fail,
unimplemented,
unreachable,

View file

@ -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,

View file

@ -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);
});

View file

@ -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);
},

View file

@ -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);

View file

@ -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,

View file

@ -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);

View file

@ -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);
},