1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

refactor(cli/tests): remove unnecessary void return types (#11577)

This commit is contained in:
Leo K 2021-08-05 13:08:58 +02:00 committed by GitHub
parent 299c7cfe54
commit 3f0cf9619f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
121 changed files with 1095 additions and 1177 deletions

View file

@ -1,10 +1,10 @@
setTimeout((): void => {
setTimeout(() => {
console.log("World");
}, 10);
console.log("Hello");
const id = setTimeout((): void => {
const id = setTimeout(() => {
console.log("Not printed");
}, 10000);

View file

@ -1,6 +1,6 @@
// Check that we can use the async keyword.
async function main(): Promise<void> {
await new Promise((resolve): void => {
async function main() {
await new Promise((resolve) => {
console.log("2");
setTimeout(resolve, 100);
});

View file

@ -1,4 +1,4 @@
(async (): Promise<void> => {
(async () => {
const { returnsHi, returnsFoo2, printHello3 } = await import(
"./subdir/mod1.ts"
);

View file

@ -4,6 +4,6 @@ import "./subdir/auto_print_hello.ts";
import "./subdir/auto_print_hello.ts";
(async (): Promise<void> => {
(async () => {
await import("./subdir/auto_print_hello.ts");
})();

View file

@ -1,6 +1,6 @@
// This is to test if Deno would die at 2nd await
// See https://github.com/denoland/deno/issues/919
(async (): Promise<void> => {
(async () => {
const currDirInfo = await Deno.stat(".");
const parentDirInfo = await Deno.stat("..");
console.log(currDirInfo.isDirectory);

View file

@ -1,7 +1,7 @@
function fn(): Promise<never> {
throw new Error("message");
}
async function call(): Promise<void> {
async function call() {
try {
console.log("before await fn()");
await fn();
@ -11,4 +11,4 @@ async function call(): Promise<void> {
}
console.log("after try-catch");
}
call().catch((): void => console.log("outer catch"));
call().catch(() => console.log("outer catch"));

View file

@ -1,4 +1,4 @@
window.onload = async (): Promise<void> => {
window.onload = async () => {
console.log(performance.now() % 2 !== 0);
await Deno.permissions.revoke({ name: "hrtime" });
console.log(performance.now() % 2 === 0);

View file

@ -1,3 +1,3 @@
Deno.args.forEach((arg): void => {
Deno.args.forEach((arg) => {
console.log(arg);
});

View file

@ -1,7 +1,7 @@
import { assert } from "../../../test_util/std/testing/asserts.ts";
import "./nest_imported.ts";
const handler = (e: Event): void => {
const handler = (e: Event) => {
assert(!e.cancelable);
console.log(`got ${e.type} event in event handler (imported)`);
};

View file

@ -4,7 +4,7 @@ import "./imported.ts";
assert(window.hasOwnProperty("onload"));
assert(window.onload === null);
const eventHandler = (e: Event): void => {
const eventHandler = (e: Event) => {
assert(!e.cancelable);
console.log(`got ${e.type} event in event handler (main)`);
};
@ -13,12 +13,12 @@ window.addEventListener("load", eventHandler);
window.addEventListener("unload", eventHandler);
window.onload = (e: Event): void => {
window.onload = (e: Event) => {
assert(!e.cancelable);
console.log(`got ${e.type} event in onload function`);
};
window.onunload = (e: Event): void => {
window.onunload = (e: Event) => {
assert(!e.cancelable);
console.log(`got ${e.type} event in onunload function`);
};

View file

@ -1,6 +1,6 @@
import { assert } from "../../../test_util/std/testing/asserts.ts";
const handler = (e: Event): void => {
const handler = (e: Event) => {
assert(!e.cancelable);
console.log(`got ${e.type} event in event handler (nest_imported)`);
};

View file

@ -4,7 +4,7 @@ import { assertEquals } from "../../test_util/std/testing/asserts.ts";
const addr = Deno.args[1] || "127.0.0.1:4555";
async function proxyServer(): Promise<void> {
async function proxyServer() {
const server = serve(addr);
console.log(`Proxy server listening on http://${addr}/`);
@ -13,7 +13,7 @@ async function proxyServer(): Promise<void> {
}
}
async function proxyRequest(req: ServerRequest): Promise<void> {
async function proxyRequest(req: ServerRequest) {
console.log(`Proxy request to: ${req.url}`);
const proxyAuthorization = req.headers.get("proxy-authorization");
if (proxyAuthorization) {
@ -31,7 +31,7 @@ async function proxyRequest(req: ServerRequest): Promise<void> {
});
}
async function testFetch(): Promise<void> {
async function testFetch() {
const c = Deno.run({
cmd: [
Deno.execPath(),
@ -52,7 +52,7 @@ async function testFetch(): Promise<void> {
c.close();
}
async function testModuleDownload(): Promise<void> {
async function testModuleDownload() {
const http = Deno.run({
cmd: [
Deno.execPath(),
@ -72,7 +72,7 @@ async function testModuleDownload(): Promise<void> {
http.close();
}
async function testFetchNoProxy(): Promise<void> {
async function testFetchNoProxy() {
const c = Deno.run({
cmd: [
Deno.execPath(),
@ -94,7 +94,7 @@ async function testFetchNoProxy(): Promise<void> {
c.close();
}
async function testModuleDownloadNoProxy(): Promise<void> {
async function testModuleDownloadNoProxy() {
const http = Deno.run({
cmd: [
Deno.execPath(),
@ -115,7 +115,7 @@ async function testModuleDownloadNoProxy(): Promise<void> {
http.close();
}
async function testFetchProgrammaticProxy(): Promise<void> {
async function testFetchProgrammaticProxy() {
const c = Deno.run({
cmd: [
Deno.execPath(),

View file

@ -22,7 +22,7 @@
"code": "file://[WILDCARD]/cli/tests/subdir/subdir2/mod2.ts"
}
],
"size": 320,
"size": 308,
"mediaType": "TypeScript",
"local": "[WILDCARD]mod1.ts",
[WILDCARD]
@ -30,7 +30,7 @@
{
"specifier": "file://[WILDCARD]/cli/tests/subdir/print_hello.ts",
"dependencies": [],
"size": 63,
"size": 57,
"mediaType": "TypeScript",
"local": "[WILDCARD]print_hello.ts",
[WILDCARD]
@ -43,11 +43,11 @@
"code": "file://[WILDCARD]/cli/tests/subdir/print_hello.ts"
}
],
"size": 163,
"size": 157,
"mediaType": "TypeScript",
"local": "[WILDCARD]mod2.ts",
[WILDCARD]
}
],
"size": 757
"size": 733
}

View file

@ -26,10 +26,10 @@
"code": "file://[WILDCARD]/cli/tests/recursive_imports/common.ts"
}
],
"size": 114,
"size": 108,
"mediaType": "TypeScript",
"local": "[WILDCARD]A.ts",
"checksum": "da204c16d3114763810864083af8891a887d65fbe34e4c8b5bf985dbc8f0b01f"
"checksum": "3b45a105d892584298490cb73372b2cac57118e1e42a677a1d5cacea704d8d3a"
},
{
"specifier": "file://[WILDCARD]/cli/tests/recursive_imports/B.ts",
@ -43,10 +43,10 @@
"code": "file://[WILDCARD]/cli/tests/recursive_imports/common.ts"
}
],
"size": 114,
"size": 108,
"mediaType": "TypeScript",
"local": "[WILDCARD]B.ts",
"checksum": "060ef62435d7e3a3276e8894307b19cf17772210a20dd091d24a670fadec6b83"
"checksum": "b12b0437ef9a91c4a4b1f66e8e4339f986b60bd8134031ccb296ce49df15b54e"
},
{
"specifier": "file://[WILDCARD]/cli/tests/recursive_imports/C.ts",
@ -60,19 +60,19 @@
"code": "file://[WILDCARD]/cli/tests/recursive_imports/common.ts"
}
],
"size": 132,
"size": 126,
"mediaType": "TypeScript",
"local": "[WILDCARD]C.ts",
"checksum": "5190563583617a69f190f1cc76e6552df878df278cfaa5d5e30ebe0938cf5e0b"
"checksum": "605875a410741bfaeeade28cbccf45f219ad99d987ea695e35eda75d2c53a658"
},
{
"specifier": "file://[WILDCARD]/cli/tests/recursive_imports/common.ts",
"dependencies": [],
"size": 34,
"size": 28,
"mediaType": "TypeScript",
"local": "[WILDCARD]common.ts",
"checksum": "01b595d69514bfd001ba2cf421feabeaef559513f10697bf1a22781f8a8ed7f0"
"checksum": "c70025f0b936c02980c3be1fbd78f6f36b6241927c44ea67580821a6e664d8b3"
}
],
"size": 475
"size": 451
}

View file

@ -2,7 +2,7 @@ import { a as defaultA, O } from "./subdir/m.ts";
export { O } from "./subdir/m.ts";
interface AOptions {
a?(): void;
a?();
c?: O;
}

View file

@ -8,10 +8,10 @@ export function returnsFoo2(): string {
return returnsFoo();
}
export function printHello3(): void {
export function printHello3() {
printHello2();
}
export function throwsError(): void {
export function throwsError() {
throw Error("exception from mod1");
}

View file

@ -1,5 +1,5 @@
import { copy } from "../../test_util/std/io/util.ts";
async function main(): Promise<void> {
async function main() {
for (let i = 1; i < Deno.args.length; i++) {
const filename = Deno.args[i];
const file = await Deno.open(filename);

View file

@ -2,18 +2,18 @@
const name = Deno.args[0];
// deno-lint-ignore no-explicit-any
const test: { [key: string]: (...args: any[]) => void | Promise<void> } = {
read(files: string[]): void {
read(files: string[]) {
files.forEach((file) => Deno.readFileSync(file));
},
write(files: string[]): void {
write(files: string[]) {
files.forEach((file) =>
Deno.writeFileSync(file, new Uint8Array(0), { append: true })
);
},
netFetch(urls: string[]): void {
netFetch(urls: string[]) {
urls.forEach((url) => fetch(url));
},
netListen(endpoints: string[]): void {
netListen(endpoints: string[]) {
endpoints.forEach((endpoint) => {
const index = endpoint.lastIndexOf(":");
const [hostname, port] = [
@ -28,7 +28,7 @@ const test: { [key: string]: (...args: any[]) => void | Promise<void> } = {
listener.close();
});
},
async netConnect(endpoints: string[]): Promise<void> {
async netConnect(endpoints: string[]) {
for (const endpoint of endpoints) {
const index = endpoint.lastIndexOf(":");
const [hostname, port] = [

View file

@ -1,4 +1,4 @@
function echo(args: string[]): void {
function echo(args: string[]) {
const msg = args.join(", ");
Deno.stdout.write(new TextEncoder().encode(msg));
}

View file

@ -4,7 +4,7 @@ const [hostname, port] = addr.split(":");
const listener = Deno.listen({ hostname, port: Number(port) });
console.log("listening on", addr);
listener.accept().then(
async (conn): Promise<void> => {
async (conn) => {
console.log("received bytes:", await copy(conn, conn));
conn.close();
listener.close();

View file

@ -2,7 +2,7 @@ function foo(): never {
throw Error("bad");
}
function bar(): void {
function bar() {
foo();
}

View file

@ -1,6 +1,6 @@
import { throwsError } from "./subdir/mod1.ts";
function foo(): void {
function foo() {
throwsError();
}

View file

@ -1,3 +1,3 @@
(async (): Promise<void> => {
(async () => {
const _badModule = await import("./bad-module.ts");
})();

View file

@ -1,3 +1,3 @@
(async (): Promise<void> => {
(async () => {
const _badModule = await import("bad-module.ts");
})();

View file

@ -1,4 +1,4 @@
const p = (async (): Promise<void> => {
const p = (async () => {
await Promise.resolve().then((): never => {
throw new Error("async");
});

View file

@ -1,5 +1,5 @@
import { A } from "./recursive_imports/A.ts";
export function test(): void {
export function test() {
A();
}

View file

@ -1,3 +1,3 @@
function define(_foo: string[]): void {}
function define(_foo: string[]) {}
define(["long"]);
console.log("ok");

View file

@ -1,4 +1,4 @@
{
"http://127.0.0.1:4545/cli/tests/subdir/print_hello.ts": "fe7bbccaedb6579200a8b582f905139296402d06b1b91109d6e12c41a23125da",
"http://127.0.0.1:4545/cli/tests/subdir/print_hello.ts": "fa6692c8f9ff3fb107e773c3ece5274e9d08be282867a1e3ded1d9c00fcaa63c",
"http://127.0.0.1:4545/cli/tests/003_relative_import.ts": "bad"
}

View file

@ -1,5 +1,5 @@
{
"http://127.0.0.1:4545/cli/tests/subdir/mod1.ts": "bc699ebc05dec9a4baf2109258f03e6ec8dd5498e2f8c5469b62073b3b241657",
"http://127.0.0.1:4545/cli/tests/subdir/print_hello.ts": "fe7bbccaedb6579200a8b582f905139296402d06b1b91109d6e12c41a23125da",
"http://127.0.0.1:4545/cli/tests/subdir/mod1.ts": "bfc1037b02c99abc20367f739bca7455813a5950066abd77965bff33b6eece0f",
"http://127.0.0.1:4545/cli/tests/subdir/print_hello.ts": "fa6692c8f9ff3fb107e773c3ece5274e9d08be282867a1e3ded1d9c00fcaa63c",
"http://127.0.0.1:4545/cli/tests/subdir/subdir2/mod2.ts": "bad"
}

View file

@ -1,4 +1,4 @@
{
"http://127.0.0.1:4545/cli/tests/subdir/print_hello.ts": "fe7bbccaedb6579200a8b582f905139296402d06b1b91109d6e12c41a23125da",
"http://127.0.0.1:4545/cli/tests/subdir/print_hello.ts": "fa6692c8f9ff3fb107e773c3ece5274e9d08be282867a1e3ded1d9c00fcaa63c",
"http://127.0.0.1:4545/cli/tests/003_relative_import.ts": "aa9e16de824f81871a1c7164d5bd6857df7db2e18621750bd66b0bde4df07f21"
}

View file

@ -1,6 +1,6 @@
{
"http://127.0.0.1:4545/cli/tests/013_dynamic_import.ts": "c875f10de49bded1ad76f1709d68e6cf2c0cfb8e8e862542a3fcb4ab09257b99",
"http://127.0.0.1:4545/cli/tests/subdir/mod1.ts": "bc699ebc05dec9a4baf2109258f03e6ec8dd5498e2f8c5469b62073b3b241657",
"http://127.0.0.1:4545/cli/tests/subdir/print_hello.ts": "fe7bbccaedb6579200a8b582f905139296402d06b1b91109d6e12c41a23125da",
"http://127.0.0.1:4545/cli/tests/013_dynamic_import.ts": "f0d2d108c100e769cda9f26b74326f21e44cab81611aa7f6cd2b731d4cbc1995",
"http://127.0.0.1:4545/cli/tests/subdir/mod1.ts": "bfc1037b02c99abc20367f739bca7455813a5950066abd77965bff33b6eece0f",
"http://127.0.0.1:4545/cli/tests/subdir/print_hello.ts": "fa6692c8f9ff3fb107e773c3ece5274e9d08be282867a1e3ded1d9c00fcaa63c",
"http://127.0.0.1:4545/cli/tests/subdir/subdir2/mod2.ts": "bad"
}

View file

@ -2,20 +2,20 @@
const name = Deno.args[0];
// deno-lint-ignore no-explicit-any
const test: { [key: string]: (...args: any[]) => void | Promise<void> } = {
readRequired(): Promise<void> {
readRequired() {
Deno.readFileSync("README.md");
return Promise.resolve();
},
writeRequired(): void {
writeRequired() {
Deno.makeTempDirSync();
},
envRequired(): void {
envRequired() {
Deno.env.get("home");
},
netRequired(): void {
netRequired() {
Deno.listen({ transport: "tcp", port: 4541 });
},
runRequired(): void {
runRequired() {
const p = Deno.run({
cmd: Deno.build.os === "windows"
? ["cmd.exe", "/c", "echo hello"]

View file

@ -1,7 +1,7 @@
import { B } from "./B.ts";
import { thing } from "./common.ts";
export function A(): void {
export function A() {
thing();
B();
}

View file

@ -1,7 +1,7 @@
import { C } from "./C.ts";
import { thing } from "./common.ts";
export function B(): void {
export function B() {
thing();
C();
}

View file

@ -1,7 +1,7 @@
import { A } from "./A.ts";
import { thing } from "./common.ts";
export function C(): void {
export function C() {
if (A != null) {
thing();
}

View file

@ -1,2 +1,2 @@
export function thing(): void {
export function thing() {
}

View file

@ -1,6 +1,6 @@
import * as circular2 from "./circular2.ts";
export function f1(): void {
export function f1() {
console.log("f1");
}

View file

@ -1,6 +1,6 @@
import * as circular1 from "./circular1.ts";
export function f2(): void {
export function f2() {
console.log("f2");
}

View file

@ -8,10 +8,10 @@ export function returnsFoo2(): string {
return returnsFoo();
}
export function printHello3(): void {
export function printHello3() {
printHello2();
}
export function throwsError(): void {
export function throwsError() {
throw Error("exception from mod1");
}

View file

@ -1,3 +1,3 @@
export function printHello(): void {
export function printHello() {
console.log("Hello");
}

View file

@ -1,4 +1,4 @@
(async (): Promise<void> => {
(async () => {
const { printHello } = await import("../mod2.ts");
printHello();
})();

View file

@ -4,6 +4,6 @@ export function returnsFoo(): string {
return "Foo";
}
export function printHello2(): void {
export function printHello2() {
printHello();
}

View file

@ -18,7 +18,7 @@ function Decorator() {
class SomeClass {
@Decorator()
async test(): Promise<void> {}
async test() {}
}
new SomeClass().test();

View file

@ -1,6 +1,6 @@
import { foo } from "./export_type_def.ts";
function bar(a: number): void {
function bar(a: number) {
console.log(a);
}

View file

@ -14,7 +14,7 @@ unitTest(function signalCallsOnabort() {
const controller = new AbortController();
const { signal } = controller;
let called = false;
signal.onabort = (evt): void => {
signal.onabort = (evt) => {
assert(evt);
assertEquals(evt.type, "abort");
called = true;
@ -41,7 +41,7 @@ unitTest(function onlyAbortsOnce() {
const { signal } = controller;
let called = 0;
signal.addEventListener("abort", () => called++);
signal.onabort = (): void => {
signal.onabort = () => {
called++;
};
controller.abort();

View file

@ -7,14 +7,14 @@ import {
} from "./test_util.ts";
import { concat } from "../../../test_util/std/bytes/mod.ts";
unitTest(function blobString(): void {
unitTest(function blobString() {
const b1 = new Blob(["Hello World"]);
const str = "Test";
const b2 = new Blob([b1, str]);
assertEquals(b2.size, b1.size + str.length);
});
unitTest(function blobBuffer(): void {
unitTest(function blobBuffer() {
const buffer = new ArrayBuffer(12);
const u8 = new Uint8Array(buffer);
const f1 = new Float32Array(buffer);
@ -24,7 +24,7 @@ unitTest(function blobBuffer(): void {
assertEquals(b2.size, 3 * u8.length);
});
unitTest(function blobSlice(): void {
unitTest(function blobSlice() {
const blob = new Blob(["Deno", "Foo"]);
const b1 = blob.slice(0, 3, "Text/HTML");
assert(b1 instanceof Blob);
@ -38,7 +38,7 @@ unitTest(function blobSlice(): void {
assertEquals(b4.size, blob.size);
});
unitTest(function blobInvalidType(): void {
unitTest(function blobInvalidType() {
const blob = new Blob(["foo"], {
type: "\u0521",
});
@ -46,7 +46,7 @@ unitTest(function blobInvalidType(): void {
assertEquals(blob.type, "");
});
unitTest(function blobShouldNotThrowError(): void {
unitTest(function blobShouldNotThrowError() {
let hasThrown = false;
try {
@ -66,7 +66,7 @@ unitTest(function blobShouldNotThrowError(): void {
});
/* TODO https://github.com/denoland/deno/issues/7540
unitTest(function nativeEndLine(): void {
unitTest(function nativeEndLine() {
const options = {
ending: "native",
} as const;
@ -76,12 +76,12 @@ unitTest(function nativeEndLine(): void {
});
*/
unitTest(async function blobText(): Promise<void> {
unitTest(async function blobText() {
const blob = new Blob(["Hello World"]);
assertEquals(await blob.text(), "Hello World");
});
unitTest(async function blobStream(): Promise<void> {
unitTest(async function blobStream() {
const blob = new Blob(["Hello World"]);
const stream = blob.stream();
assert(stream instanceof ReadableStream);
@ -99,18 +99,18 @@ unitTest(async function blobStream(): Promise<void> {
assertEquals(decoder.decode(bytes), "Hello World");
});
unitTest(async function blobArrayBuffer(): Promise<void> {
unitTest(async function blobArrayBuffer() {
const uint = new Uint8Array([102, 111, 111]);
const blob = new Blob([uint]);
assertEquals(await blob.arrayBuffer(), uint.buffer);
});
unitTest(function blobConstructorNameIsBlob(): void {
unitTest(function blobConstructorNameIsBlob() {
const blob = new Blob();
assertEquals(blob.constructor.name, "Blob");
});
unitTest(function blobCustomInspectFunction(): void {
unitTest(function blobCustomInspectFunction() {
const blob = new Blob();
assertEquals(
Deno.inspect(blob),

View file

@ -23,7 +23,7 @@ const intArrays = [
Float32Array,
Float64Array,
];
unitTest(async function arrayBufferFromByteArrays(): Promise<void> {
unitTest(async function arrayBufferFromByteArrays() {
const buffer = new TextEncoder().encode("ahoyhoy8").buffer;
for (const type of intArrays) {
@ -36,7 +36,7 @@ unitTest(async function arrayBufferFromByteArrays(): Promise<void> {
//FormData
unitTest(
{ perms: { net: true } },
async function bodyMultipartFormData(): Promise<void> {
async function bodyMultipartFormData() {
const response = await fetch(
"http://localhost:4545/multipart_form_data.txt",
);
@ -55,7 +55,7 @@ unitTest(
unitTest(
{ perms: { net: true } },
async function bodyURLEncodedFormData(): Promise<void> {
async function bodyURLEncodedFormData() {
const response = await fetch(
"http://localhost:4545/cli/tests/subdir/form_urlencoded.txt",
);
@ -73,14 +73,14 @@ unitTest(
},
);
unitTest({ perms: {} }, async function bodyURLSearchParams(): Promise<void> {
unitTest({ perms: {} }, async function bodyURLSearchParams() {
const body = buildBody(new URLSearchParams({ hello: "world" }));
const text = await body.text();
assertEquals(text, "hello=world");
});
unitTest(async function bodyArrayBufferMultipleParts(): Promise<void> {
unitTest(async function bodyArrayBufferMultipleParts() {
const parts: Uint8Array[] = [];
let size = 0;
for (let i = 0; i <= 150000; i++) {
@ -91,7 +91,7 @@ unitTest(async function bodyArrayBufferMultipleParts(): Promise<void> {
let offset = 0;
const stream = new ReadableStream({
pull(controller): void {
pull(controller) {
// parts.shift() takes forever: https://github.com/denoland/deno/issues/5259
const chunk = parts[offset++];
if (!chunk) return controller.close();

View file

@ -21,7 +21,7 @@ let testString: string | null;
const ignoreMaxSizeTests = true;
function init(): void {
function init() {
if (testBytes == null) {
testBytes = new Uint8Array(N);
for (let i = 0; i < N; i++) {
@ -32,7 +32,7 @@ function init(): void {
}
}
function check(buf: Deno.Buffer, s: string): void {
function check(buf: Deno.Buffer, s: string) {
const bytes = buf.bytes();
assertEquals(buf.length, bytes.byteLength);
const decoder = new TextDecoder();
@ -67,7 +67,7 @@ async function empty(
buf: Deno.Buffer,
s: string,
fub: Uint8Array,
): Promise<void> {
) {
check(buf, s);
while (true) {
const r = await buf.read(fub);
@ -87,7 +87,7 @@ function repeat(c: string, bytes: number): Uint8Array {
return ui8;
}
unitTest(function bufferNewBuffer(): void {
unitTest(function bufferNewBuffer() {
init();
assert(testBytes);
assert(testString);
@ -95,7 +95,7 @@ unitTest(function bufferNewBuffer(): void {
check(buf, testString);
});
unitTest(async function bufferBasicOperations(): Promise<void> {
unitTest(async function bufferBasicOperations() {
init();
assert(testBytes);
assert(testString);
@ -135,7 +135,7 @@ unitTest(async function bufferBasicOperations(): Promise<void> {
}
});
unitTest(async function bufferReadEmptyAtEOF(): Promise<void> {
unitTest(async function bufferReadEmptyAtEOF() {
// check that EOF of 'buf' is not reached (even though it's empty) if
// results are written to buffer that has 0 length (ie. it can't store any data)
const buf = new Deno.Buffer();
@ -144,7 +144,7 @@ unitTest(async function bufferReadEmptyAtEOF(): Promise<void> {
assertEquals(result, 0);
});
unitTest(async function bufferLargeByteWrites(): Promise<void> {
unitTest(async function bufferLargeByteWrites() {
init();
const buf = new Deno.Buffer();
const limit = 9;
@ -155,7 +155,7 @@ unitTest(async function bufferLargeByteWrites(): Promise<void> {
check(buf, "");
});
unitTest(async function bufferTooLargeByteWrites(): Promise<void> {
unitTest(async function bufferTooLargeByteWrites() {
init();
const tmp = new Uint8Array(72);
const growLen = Number.MAX_VALUE;
@ -174,7 +174,7 @@ unitTest(async function bufferTooLargeByteWrites(): Promise<void> {
unitTest(
{ ignore: ignoreMaxSizeTests },
function bufferGrowWriteMaxBuffer(): void {
function bufferGrowWriteMaxBuffer() {
const bufSize = 16 * 1024;
const capacities = [MAX_SIZE, MAX_SIZE - 1];
for (const capacity of capacities) {
@ -196,7 +196,7 @@ unitTest(
unitTest(
{ ignore: ignoreMaxSizeTests },
async function bufferGrowReadCloseMaxBufferPlus1(): Promise<void> {
async function bufferGrowReadCloseMaxBufferPlus1() {
const reader = new Deno.Buffer(new ArrayBuffer(MAX_SIZE + 1));
const buf = new Deno.Buffer();
@ -212,7 +212,7 @@ unitTest(
unitTest(
{ ignore: ignoreMaxSizeTests },
function bufferGrowReadSyncCloseMaxBufferPlus1(): void {
function bufferGrowReadSyncCloseMaxBufferPlus1() {
const reader = new Deno.Buffer(new ArrayBuffer(MAX_SIZE + 1));
const buf = new Deno.Buffer();
@ -228,7 +228,7 @@ unitTest(
unitTest(
{ ignore: ignoreMaxSizeTests },
function bufferGrowReadSyncCloseToMaxBuffer(): void {
function bufferGrowReadSyncCloseToMaxBuffer() {
const capacities = [MAX_SIZE, MAX_SIZE - 1];
for (const capacity of capacities) {
const reader = new Deno.Buffer(new ArrayBuffer(capacity));
@ -242,7 +242,7 @@ unitTest(
unitTest(
{ ignore: ignoreMaxSizeTests },
async function bufferGrowReadCloseToMaxBuffer(): Promise<void> {
async function bufferGrowReadCloseToMaxBuffer() {
const capacities = [MAX_SIZE, MAX_SIZE - 1];
for (const capacity of capacities) {
const reader = new Deno.Buffer(new ArrayBuffer(capacity));
@ -255,7 +255,7 @@ unitTest(
unitTest(
{ ignore: ignoreMaxSizeTests },
async function bufferReadCloseToMaxBufferWithInitialGrow(): Promise<void> {
async function bufferReadCloseToMaxBufferWithInitialGrow() {
const capacities = [MAX_SIZE, MAX_SIZE - 1, MAX_SIZE - 512];
for (const capacity of capacities) {
const reader = new Deno.Buffer(new ArrayBuffer(capacity));
@ -267,7 +267,7 @@ unitTest(
},
);
unitTest(async function bufferLargeByteReads(): Promise<void> {
unitTest(async function bufferLargeByteReads() {
init();
assert(testBytes);
assert(testString);
@ -280,12 +280,12 @@ unitTest(async function bufferLargeByteReads(): Promise<void> {
check(buf, "");
});
unitTest(function bufferCapWithPreallocatedSlice(): void {
unitTest(function bufferCapWithPreallocatedSlice() {
const buf = new Deno.Buffer(new ArrayBuffer(10));
assertEquals(buf.capacity, 10);
});
unitTest(async function bufferReadFrom(): Promise<void> {
unitTest(async function bufferReadFrom() {
init();
assert(testBytes);
assert(testString);
@ -307,7 +307,7 @@ unitTest(async function bufferReadFrom(): Promise<void> {
});
});
unitTest(async function bufferReadFromSync(): Promise<void> {
unitTest(async function bufferReadFromSync() {
init();
assert(testBytes);
assert(testString);
@ -329,7 +329,7 @@ unitTest(async function bufferReadFromSync(): Promise<void> {
});
});
unitTest(async function bufferTestGrow(): Promise<void> {
unitTest(async function bufferTestGrow() {
const tmp = new Uint8Array(72);
for (const startLen of [0, 100, 1000, 10000]) {
const xBytes = repeat("x", startLen);
@ -353,7 +353,7 @@ unitTest(async function bufferTestGrow(): Promise<void> {
}
});
unitTest(async function testReadAll(): Promise<void> {
unitTest(async function testReadAll() {
init();
assert(testBytes);
const reader = new Deno.Buffer(testBytes.buffer as ArrayBuffer);
@ -364,7 +364,7 @@ unitTest(async function testReadAll(): Promise<void> {
}
});
unitTest(function testReadAllSync(): void {
unitTest(function testReadAllSync() {
init();
assert(testBytes);
const reader = new Deno.Buffer(testBytes.buffer as ArrayBuffer);
@ -375,7 +375,7 @@ unitTest(function testReadAllSync(): void {
}
});
unitTest(async function testWriteAll(): Promise<void> {
unitTest(async function testWriteAll() {
init();
assert(testBytes);
const writer = new Deno.Buffer();
@ -387,7 +387,7 @@ unitTest(async function testWriteAll(): Promise<void> {
}
});
unitTest(function testWriteAllSync(): void {
unitTest(function testWriteAllSync() {
init();
assert(testBytes);
const writer = new Deno.Buffer();
@ -399,7 +399,7 @@ unitTest(function testWriteAllSync(): void {
}
});
unitTest(function testBufferBytesArrayBufferLength(): void {
unitTest(function testBufferBytesArrayBufferLength() {
// defaults to copy
const args = [{}, { copy: undefined }, undefined, { copy: true }];
for (const arg of args) {
@ -418,7 +418,7 @@ unitTest(function testBufferBytesArrayBufferLength(): void {
}
});
unitTest(function testBufferBytesCopyFalse(): void {
unitTest(function testBufferBytesCopyFalse() {
const bufSize = 64 * 1024;
const bytes = new TextEncoder().encode("a".repeat(bufSize));
const reader = new Deno.Buffer();
@ -433,7 +433,7 @@ unitTest(function testBufferBytesCopyFalse(): void {
assert(actualBytes.buffer.byteLength > actualBytes.byteLength);
});
unitTest(function testBufferBytesCopyFalseGrowExactBytes(): void {
unitTest(function testBufferBytesCopyFalseGrowExactBytes() {
const bufSize = 64 * 1024;
const bytes = new TextEncoder().encode("a".repeat(bufSize));
const reader = new Deno.Buffer();

View file

@ -1,7 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assert, unitTest } from "./test_util.ts";
unitTest(function buildInfo(): void {
unitTest(function buildInfo() {
// Deno.build is injected by rollup at compile time. Here
// we check it has been properly transformed.
const { arch, os } = Deno.build;

View file

@ -9,7 +9,7 @@ import {
unitTest(
{ ignore: Deno.build.os === "windows", perms: { read: true, write: true } },
function chmodSyncSuccess(): void {
function chmodSyncSuccess() {
const enc = new TextEncoder();
const data = enc.encode("Hello");
const tempDir = Deno.makeTempDirSync();
@ -26,7 +26,7 @@ unitTest(
unitTest(
{ ignore: Deno.build.os === "windows", perms: { read: true, write: true } },
function chmodSyncUrl(): void {
function chmodSyncUrl() {
const enc = new TextEncoder();
const data = enc.encode("Hello");
const tempDir = Deno.makeTempDirSync();
@ -49,7 +49,7 @@ unitTest(
ignore: Deno.build.os === "windows",
perms: { read: true, write: true },
},
function chmodSyncSymlinkSuccess(): void {
function chmodSyncSymlinkSuccess() {
const enc = new TextEncoder();
const data = enc.encode("Hello");
const tempDir = Deno.makeTempDirSync();
@ -75,14 +75,14 @@ unitTest(
},
);
unitTest({ perms: { write: true } }, function chmodSyncFailure(): void {
unitTest({ perms: { write: true } }, function chmodSyncFailure() {
assertThrows(() => {
const filename = "/badfile.txt";
Deno.chmodSync(filename, 0o777);
}, Deno.errors.NotFound);
});
unitTest({ perms: { write: false } }, function chmodSyncPerm(): void {
unitTest({ perms: { write: false } }, function chmodSyncPerm() {
assertThrows(() => {
Deno.chmodSync("/somefile.txt", 0o777);
}, Deno.errors.PermissionDenied);
@ -90,7 +90,7 @@ unitTest({ perms: { write: false } }, function chmodSyncPerm(): void {
unitTest(
{ ignore: Deno.build.os === "windows", perms: { read: true, write: true } },
async function chmodSuccess(): Promise<void> {
async function chmodSuccess() {
const enc = new TextEncoder();
const data = enc.encode("Hello");
const tempDir = Deno.makeTempDirSync();
@ -107,7 +107,7 @@ unitTest(
unitTest(
{ ignore: Deno.build.os === "windows", perms: { read: true, write: true } },
async function chmodUrl(): Promise<void> {
async function chmodUrl() {
const enc = new TextEncoder();
const data = enc.encode("Hello");
const tempDir = Deno.makeTempDirSync();
@ -131,7 +131,7 @@ unitTest(
ignore: Deno.build.os === "windows",
perms: { read: true, write: true },
},
async function chmodSymlinkSuccess(): Promise<void> {
async function chmodSymlinkSuccess() {
const enc = new TextEncoder();
const data = enc.encode("Hello");
const tempDir = Deno.makeTempDirSync();
@ -157,18 +157,14 @@ unitTest(
},
);
unitTest({ perms: { write: true } }, async function chmodFailure(): Promise<
void
> {
unitTest({ perms: { write: true } }, async function chmodFailure() {
await assertThrowsAsync(async () => {
const filename = "/badfile.txt";
await Deno.chmod(filename, 0o777);
}, Deno.errors.NotFound);
});
unitTest({ perms: { write: false } }, async function chmodPerm(): Promise<
void
> {
unitTest({ perms: { write: false } }, async function chmodPerm() {
await assertThrowsAsync(async () => {
await Deno.chmod("/somefile.txt", 0o777);
}, Deno.errors.PermissionDenied);

View file

@ -31,7 +31,7 @@ async function getUidAndGid(): Promise<{ uid: number; gid: number }> {
unitTest(
{ ignore: Deno.build.os == "windows" },
async function chownNoWritePermission(): Promise<void> {
async function chownNoWritePermission() {
const filePath = "chown_test_file.txt";
await assertThrowsAsync(async () => {
await Deno.chown(filePath, 1000, 1000);
@ -41,7 +41,7 @@ unitTest(
unitTest(
{ perms: { run: true, write: true }, ignore: Deno.build.os == "windows" },
async function chownSyncFileNotExist(): Promise<void> {
async function chownSyncFileNotExist() {
const { uid, gid } = await getUidAndGid();
const filePath = Deno.makeTempDirSync() + "/chown_test_file.txt";
@ -53,7 +53,7 @@ unitTest(
unitTest(
{ perms: { run: true, write: true }, ignore: Deno.build.os == "windows" },
async function chownFileNotExist(): Promise<void> {
async function chownFileNotExist() {
const { uid, gid } = await getUidAndGid();
const filePath = (await Deno.makeTempDir()) + "/chown_test_file.txt";
@ -65,7 +65,7 @@ unitTest(
unitTest(
{ perms: { write: true }, ignore: Deno.build.os == "windows" },
function chownSyncPermissionDenied(): void {
function chownSyncPermissionDenied() {
const dirPath = Deno.makeTempDirSync();
const filePath = dirPath + "/chown_test_file.txt";
Deno.writeTextFileSync(filePath, "Hello");
@ -80,7 +80,7 @@ unitTest(
unitTest(
{ perms: { write: true }, ignore: Deno.build.os == "windows" },
async function chownPermissionDenied(): Promise<void> {
async function chownPermissionDenied() {
const dirPath = await Deno.makeTempDir();
const filePath = dirPath + "/chown_test_file.txt";
await Deno.writeTextFile(filePath, "Hello");
@ -95,7 +95,7 @@ unitTest(
unitTest(
{ perms: { run: true, write: true }, ignore: Deno.build.os == "windows" },
async function chownSyncSucceed(): Promise<void> {
async function chownSyncSucceed() {
// TODO(bartlomieju): when a file's owner is actually being changed,
// chown only succeeds if run under priviledged user (root)
// The test script has no such privilege, so need to find a better way to test this case
@ -115,7 +115,7 @@ unitTest(
unitTest(
{ perms: { run: true, write: true }, ignore: Deno.build.os == "windows" },
async function chownSyncWithUrl(): Promise<void> {
async function chownSyncWithUrl() {
const { uid, gid } = await getUidAndGid();
const dirPath = Deno.makeTempDirSync();
const fileUrl = new URL(`file://${dirPath}/chown_test_file.txt`);
@ -127,7 +127,7 @@ unitTest(
unitTest(
{ perms: { run: true, write: true }, ignore: Deno.build.os == "windows" },
async function chownSucceed(): Promise<void> {
async function chownSucceed() {
const { uid, gid } = await getUidAndGid();
const dirPath = await Deno.makeTempDir();
const filePath = dirPath + "/chown_test_file.txt";
@ -139,7 +139,7 @@ unitTest(
unitTest(
{ perms: { run: true, write: true }, ignore: Deno.build.os == "windows" },
async function chownUidOnly(): Promise<void> {
async function chownUidOnly() {
const { uid } = await getUidAndGid();
const dirPath = await Deno.makeTempDir();
const filePath = dirPath + "/chown_test_file.txt";
@ -151,7 +151,7 @@ unitTest(
unitTest(
{ perms: { run: true, write: true }, ignore: Deno.build.os == "windows" },
async function chownWithUrl(): Promise<void> {
async function chownWithUrl() {
// TODO(bartlomieju): same as chownSyncSucceed
const { uid, gid } = await getUidAndGid();

View file

@ -64,7 +64,7 @@ function cssToAnsiEsc(css: Css, prevCss: Css | null = null): string {
// test cases from web-platform-tests
// via https://github.com/web-platform-tests/wpt/blob/master/console/console-is-a-namespace.any.js
unitTest(function consoleShouldBeANamespace(): void {
unitTest(function consoleShouldBeANamespace() {
const prototype1 = Object.getPrototypeOf(console);
const prototype2 = Object.getPrototypeOf(prototype1);
@ -72,12 +72,12 @@ unitTest(function consoleShouldBeANamespace(): void {
assertEquals(prototype2, Object.prototype);
});
unitTest(function consoleHasRightInstance(): void {
unitTest(function consoleHasRightInstance() {
assert(console instanceof Console);
assertEquals({} instanceof Console, false);
});
unitTest(function consoleTestAssertShouldNotThrowError(): void {
unitTest(function consoleTestAssertShouldNotThrowError() {
mockConsole((console) => {
console.assert(true);
let hasThrown = undefined;
@ -91,14 +91,14 @@ unitTest(function consoleTestAssertShouldNotThrowError(): void {
});
});
unitTest(function consoleTestStringifyComplexObjects(): void {
unitTest(function consoleTestStringifyComplexObjects() {
assertEquals(stringify("foo"), "foo");
assertEquals(stringify(["foo", "bar"]), `[ "foo", "bar" ]`);
assertEquals(stringify({ foo: "bar" }), `{ foo: "bar" }`);
});
unitTest(
function consoleTestStringifyComplexObjectsWithEscapedSequences(): void {
function consoleTestStringifyComplexObjectsWithEscapedSequences() {
assertEquals(
stringify(
["foo\b", "foo\f", "foo\n", "foo\r", "foo\t", "foo\v", "foo\0"],
@ -167,14 +167,14 @@ unitTest(
},
);
unitTest(function consoleTestStringifyQuotes(): void {
unitTest(function consoleTestStringifyQuotes() {
assertEquals(stringify(["\\"]), `[ "\\\\" ]`);
assertEquals(stringify(['\\,"']), `[ '\\\\,"' ]`);
assertEquals(stringify([`\\,",'`]), `[ \`\\\\,",'\` ]`);
assertEquals(stringify(["\\,\",',`"]), `[ "\\\\,\\",',\`" ]`);
});
unitTest(function consoleTestStringifyLongStrings(): void {
unitTest(function consoleTestStringifyLongStrings() {
const veryLongString = "a".repeat(200);
// If we stringify an object containing the long string, it gets abbreviated.
let actual = stringify({ veryLongString });
@ -185,7 +185,7 @@ unitTest(function consoleTestStringifyLongStrings(): void {
assertEquals(actual, veryLongString);
});
unitTest(function consoleTestStringifyCircular(): void {
unitTest(function consoleTestStringifyCircular() {
class Base {
a = 1;
m1() {}
@ -283,11 +283,11 @@ unitTest(function consoleTestStringifyCircular(): void {
assertEquals(stringify(undefined), "undefined");
assertEquals(stringify(new Extended()), "Extended { a: 1, b: 2 }");
assertEquals(
stringify(function f(): void {}),
stringify(function f() {}),
"[Function: f]",
);
assertEquals(
stringify(async function af(): Promise<void> {}),
stringify(async function af() {}),
"[AsyncFunction: af]",
);
assertEquals(
@ -354,7 +354,7 @@ unitTest(function consoleTestStringifyCircular(): void {
assertEquals(stripColor(Deno.inspect(nestedObj)), nestedObjExpected);
});
unitTest(function consoleTestStringifyFunctionWithPrototypeRemoved(): void {
unitTest(function consoleTestStringifyFunctionWithPrototypeRemoved() {
const f = function f() {};
Reflect.setPrototypeOf(f, null);
assertEquals(stringify(f), "[Function: f]");
@ -369,7 +369,7 @@ unitTest(function consoleTestStringifyFunctionWithPrototypeRemoved(): void {
assertEquals(stringify(agf), "[Function: agf]");
});
unitTest(function consoleTestStringifyFunctionWithProperties(): void {
unitTest(function consoleTestStringifyFunctionWithProperties() {
const f = () => "test";
f.x = () => "foo";
f.y = 3;
@ -413,7 +413,7 @@ unitTest(function consoleTestStringifyFunctionWithProperties(): void {
);
});
unitTest(function consoleTestStringifyWithDepth(): void {
unitTest(function consoleTestStringifyWithDepth() {
// deno-lint-ignore no-explicit-any
const nestedObj: any = { a: { b: { c: { d: { e: { f: 42 } } } } } };
assertEquals(
@ -436,7 +436,7 @@ unitTest(function consoleTestStringifyWithDepth(): void {
);
});
unitTest(function consoleTestStringifyLargeObject(): void {
unitTest(function consoleTestStringifyLargeObject() {
const obj = {
a: 2,
o: {
@ -768,7 +768,7 @@ unitTest(function consoleTestStringifyIterable() {
*/
});
unitTest(function consoleTestStringifyIterableWhenGrouped(): void {
unitTest(function consoleTestStringifyIterableWhenGrouped() {
const withOddNumberOfEls = new Float64Array(
[
2.1,
@ -846,7 +846,7 @@ unitTest(function consoleTestStringifyIterableWhenGrouped(): void {
);
});
unitTest(async function consoleTestStringifyPromises(): Promise<void> {
unitTest(async function consoleTestStringifyPromises() {
const pendingPromise = new Promise((_res, _rej) => {});
assertEquals(stringify(pendingPromise), "Promise { <pending> }");
@ -869,7 +869,7 @@ unitTest(async function consoleTestStringifyPromises(): Promise<void> {
assertEquals(strLines[1], " <rejected> Error: Whoops");
});
unitTest(function consoleTestWithCustomInspector(): void {
unitTest(function consoleTestWithCustomInspector() {
class A {
[customInspect](): string {
return "b";
@ -879,7 +879,7 @@ unitTest(function consoleTestWithCustomInspector(): void {
assertEquals(stringify(new A()), "b");
});
unitTest(function consoleTestWithCustomInspectorUsingInspectFunc(): void {
unitTest(function consoleTestWithCustomInspectorUsingInspectFunc() {
class A {
[customInspect](
inspect: (v: unknown, opts?: Deno.InspectOptions) => string,
@ -891,7 +891,7 @@ unitTest(function consoleTestWithCustomInspectorUsingInspectFunc(): void {
assertEquals(stringify(new A()), "b { c: 1 }");
});
unitTest(function consoleTestWithCustomInspectorError(): void {
unitTest(function consoleTestWithCustomInspectorError() {
class A {
[customInspect](): never {
throw new Error("BOOM");
@ -913,7 +913,7 @@ unitTest(function consoleTestWithCustomInspectorError(): void {
);
});
unitTest(function consoleTestWithCustomInspectFunction(): void {
unitTest(function consoleTestWithCustomInspectFunction() {
function a() {}
Object.assign(a, {
[customInspect]() {
@ -924,7 +924,7 @@ unitTest(function consoleTestWithCustomInspectFunction(): void {
assertEquals(stringify(a), "b");
});
unitTest(function consoleTestWithIntegerFormatSpecifier(): void {
unitTest(function consoleTestWithIntegerFormatSpecifier() {
assertEquals(stringify("%i"), "%i");
assertEquals(stringify("%i", 42.0), "42");
assertEquals(stringify("%i", 42), "42");
@ -942,7 +942,7 @@ unitTest(function consoleTestWithIntegerFormatSpecifier(): void {
);
});
unitTest(function consoleTestWithFloatFormatSpecifier(): void {
unitTest(function consoleTestWithFloatFormatSpecifier() {
assertEquals(stringify("%f"), "%f");
assertEquals(stringify("%f", 42.0), "42");
assertEquals(stringify("%f", 42), "42");
@ -957,7 +957,7 @@ unitTest(function consoleTestWithFloatFormatSpecifier(): void {
assertEquals(stringify("%f %f", 42), "42 %f");
});
unitTest(function consoleTestWithStringFormatSpecifier(): void {
unitTest(function consoleTestWithStringFormatSpecifier() {
assertEquals(stringify("%s"), "%s");
assertEquals(stringify("%s", undefined), "undefined");
assertEquals(stringify("%s", "foo"), "foo");
@ -968,7 +968,7 @@ unitTest(function consoleTestWithStringFormatSpecifier(): void {
assertEquals(stringify("%s", Symbol("foo")), "Symbol(foo)");
});
unitTest(function consoleTestWithObjectFormatSpecifier(): void {
unitTest(function consoleTestWithObjectFormatSpecifier() {
assertEquals(stringify("%o"), "%o");
assertEquals(stringify("%o", 42), "42");
assertEquals(stringify("%o", "foo"), `"foo"`);
@ -980,13 +980,13 @@ unitTest(function consoleTestWithObjectFormatSpecifier(): void {
);
});
unitTest(function consoleTestWithStyleSpecifier(): void {
unitTest(function consoleTestWithStyleSpecifier() {
assertEquals(stringify("%cfoo%cbar"), "%cfoo%cbar");
assertEquals(stringify("%cfoo%cbar", ""), "foo%cbar");
assertEquals(stripColor(stringify("%cfoo%cbar", "", "color: red")), "foobar");
});
unitTest(function consoleParseCssColor(): void {
unitTest(function consoleParseCssColor() {
assertEquals(parseCssColor("black"), [0, 0, 0]);
assertEquals(parseCssColor("darkmagenta"), [139, 0, 139]);
assertEquals(parseCssColor("slateblue"), [106, 90, 205]);
@ -1005,7 +1005,7 @@ unitTest(function consoleParseCssColor(): void {
);
});
unitTest(function consoleParseCss(): void {
unitTest(function consoleParseCss() {
assertEquals(
parseCss("background-color: red"),
{ ...DEFAULT_CSS, backgroundColor: [255, 0, 0] },
@ -1059,7 +1059,7 @@ unitTest(function consoleParseCss(): void {
);
});
unitTest(function consoleCssToAnsi(): void {
unitTest(function consoleCssToAnsi() {
assertEquals(
cssToAnsiEsc({ ...DEFAULT_CSS, backgroundColor: [200, 201, 202] }),
"_[48;2;200;201;202m",
@ -1099,7 +1099,7 @@ unitTest(function consoleCssToAnsi(): void {
);
});
unitTest(function consoleTestWithVariousOrInvalidFormatSpecifier(): void {
unitTest(function consoleTestWithVariousOrInvalidFormatSpecifier() {
assertEquals(stringify("%s:%s"), "%s:%s");
assertEquals(stringify("%i:%i"), "%i:%i");
assertEquals(stringify("%d:%d"), "%d:%d");
@ -1115,13 +1115,13 @@ unitTest(function consoleTestWithVariousOrInvalidFormatSpecifier(): void {
assertEquals(stringify("abc%", 1), "abc% 1");
});
unitTest(function consoleTestCallToStringOnLabel(): void {
unitTest(function consoleTestCallToStringOnLabel() {
const methods = ["count", "countReset", "time", "timeLog", "timeEnd"];
mockConsole((console) => {
for (const method of methods) {
let hasCalled = false;
console[method]({
toString(): void {
toString() {
hasCalled = true;
},
});
@ -1130,7 +1130,7 @@ unitTest(function consoleTestCallToStringOnLabel(): void {
});
});
unitTest(function consoleTestError(): void {
unitTest(function consoleTestError() {
class MyError extends Error {
constructor(errStr: string) {
super(errStr);
@ -1148,7 +1148,7 @@ unitTest(function consoleTestError(): void {
}
});
unitTest(function consoleTestClear(): void {
unitTest(function consoleTestClear() {
mockConsole((console, out) => {
console.clear();
assertEquals(out.toString(), "\x1b[1;1H" + "\x1b[0J");
@ -1156,7 +1156,7 @@ unitTest(function consoleTestClear(): void {
});
// Test bound this issue
unitTest(function consoleDetachedLog(): void {
unitTest(function consoleDetachedLog() {
mockConsole((console) => {
const log = console.log;
const dir = console.dir;
@ -1197,7 +1197,7 @@ unitTest(function consoleDetachedLog(): void {
class StringBuffer {
chunks: string[] = [];
add(x: string): void {
add(x: string) {
this.chunks.push(x);
}
toString(): string {
@ -1213,12 +1213,12 @@ type ConsoleExamineFunc = (
both?: StringBuffer,
) => void;
function mockConsole(f: ConsoleExamineFunc): void {
function mockConsole(f: ConsoleExamineFunc) {
const out = new StringBuffer();
const err = new StringBuffer();
const both = new StringBuffer();
const csl = new Console(
(x: string, level: number, printsNewLine: boolean): void => {
(x: string, level: number, printsNewLine: boolean) => {
const content = x + (printsNewLine ? "\n" : "");
const buf = level > 1 ? err : out;
buf.add(content);
@ -1229,8 +1229,8 @@ function mockConsole(f: ConsoleExamineFunc): void {
}
// console.group test
unitTest(function consoleGroup(): void {
mockConsole((console, out): void => {
unitTest(function consoleGroup() {
mockConsole((console, out) => {
console.group("1");
console.log("2");
console.group("3");
@ -1254,8 +1254,8 @@ unitTest(function consoleGroup(): void {
});
// console.group with console.warn test
unitTest(function consoleGroupWarn(): void {
mockConsole((console, _out, _err, both): void => {
unitTest(function consoleGroupWarn() {
mockConsole((console, _out, _err, both) => {
assert(both);
console.warn("1");
console.group();
@ -1284,8 +1284,8 @@ unitTest(function consoleGroupWarn(): void {
});
// console.table test
unitTest(function consoleTable(): void {
mockConsole((console, out): void => {
unitTest(function consoleTable() {
mockConsole((console, out) => {
console.table({ a: "test", b: 1 });
assertEquals(
stripColor(out.toString()),
@ -1298,7 +1298,7 @@ unitTest(function consoleTable(): void {
`,
);
});
mockConsole((console, out): void => {
mockConsole((console, out) => {
console.table({ a: { b: 10 }, b: { b: 20, c: 30 } }, ["c"]);
assertEquals(
stripColor(out.toString()),
@ -1311,7 +1311,7 @@ unitTest(function consoleTable(): void {
`,
);
});
mockConsole((console, out): void => {
mockConsole((console, out) => {
console.table([1, 2, [3, [4]], [5, 6], [[7], [8]]]);
assertEquals(
stripColor(out.toString()),
@ -1327,7 +1327,7 @@ unitTest(function consoleTable(): void {
`,
);
});
mockConsole((console, out): void => {
mockConsole((console, out) => {
console.table(new Set([1, 2, 3, "test"]));
assertEquals(
stripColor(out.toString()),
@ -1342,7 +1342,7 @@ unitTest(function consoleTable(): void {
`,
);
});
mockConsole((console, out): void => {
mockConsole((console, out) => {
console.table(
new Map([
[1, "one"],
@ -1360,7 +1360,7 @@ unitTest(function consoleTable(): void {
`,
);
});
mockConsole((console, out): void => {
mockConsole((console, out) => {
console.table({
a: true,
b: { c: { d: 10 }, e: [1, 2, [5, 6]] },
@ -1382,7 +1382,7 @@ unitTest(function consoleTable(): void {
`,
);
});
mockConsole((console, out): void => {
mockConsole((console, out) => {
console.table([
1,
"test",
@ -1404,7 +1404,7 @@ unitTest(function consoleTable(): void {
`,
);
});
mockConsole((console, out): void => {
mockConsole((console, out) => {
console.table([]);
assertEquals(
stripColor(out.toString()),
@ -1415,7 +1415,7 @@ unitTest(function consoleTable(): void {
`,
);
});
mockConsole((console, out): void => {
mockConsole((console, out) => {
console.table({});
assertEquals(
stripColor(out.toString()),
@ -1426,7 +1426,7 @@ unitTest(function consoleTable(): void {
`,
);
});
mockConsole((console, out): void => {
mockConsole((console, out) => {
console.table(new Set());
assertEquals(
stripColor(out.toString()),
@ -1437,7 +1437,7 @@ unitTest(function consoleTable(): void {
`,
);
});
mockConsole((console, out): void => {
mockConsole((console, out) => {
console.table(new Map());
assertEquals(
stripColor(out.toString()),
@ -1448,11 +1448,11 @@ unitTest(function consoleTable(): void {
`,
);
});
mockConsole((console, out): void => {
mockConsole((console, out) => {
console.table("test");
assertEquals(out.toString(), "test\n");
});
mockConsole((console, out): void => {
mockConsole((console, out) => {
console.table(["Hello", "你好", "Amapá"]);
assertEquals(
stripColor(out.toString()),
@ -1466,7 +1466,7 @@ unitTest(function consoleTable(): void {
`,
);
});
mockConsole((console, out): void => {
mockConsole((console, out) => {
console.table([
[1, 2],
[3, 4],
@ -1482,7 +1482,7 @@ unitTest(function consoleTable(): void {
`,
);
});
mockConsole((console, out): void => {
mockConsole((console, out) => {
console.table({ 1: { a: 4, b: 5 }, 2: null, 3: { b: 6, c: 7 } }, ["b"]);
assertEquals(
stripColor(out.toString()),
@ -1532,7 +1532,7 @@ unitTest(function consoleTable(): void {
});
// console.log(Error) test
unitTest(function consoleLogShouldNotThrowError(): void {
unitTest(function consoleLogShouldNotThrowError() {
mockConsole((console) => {
let result = 0;
try {
@ -1545,14 +1545,14 @@ unitTest(function consoleLogShouldNotThrowError(): void {
});
// output errors to the console should not include "Uncaught"
mockConsole((console, out): void => {
mockConsole((console, out) => {
console.log(new Error("foo"));
assertEquals(out.toString().includes("Uncaught"), false);
});
});
// console.log(Invalid Date) test
unitTest(function consoleLogShoultNotThrowErrorWhenInvalidDateIsPassed(): void {
unitTest(function consoleLogShoultNotThrowErrorWhenInvalidDateIsPassed() {
mockConsole((console, out) => {
const invalidDate = new Date("test");
console.log(invalidDate);
@ -1561,39 +1561,39 @@ unitTest(function consoleLogShoultNotThrowErrorWhenInvalidDateIsPassed(): void {
});
// console.dir test
unitTest(function consoleDir(): void {
mockConsole((console, out): void => {
unitTest(function consoleDir() {
mockConsole((console, out) => {
console.dir("DIR");
assertEquals(out.toString(), "DIR\n");
});
mockConsole((console, out): void => {
mockConsole((console, out) => {
console.dir("DIR", { indentLevel: 2 });
assertEquals(out.toString(), " DIR\n");
});
});
// console.dir test
unitTest(function consoleDirXml(): void {
mockConsole((console, out): void => {
unitTest(function consoleDirXml() {
mockConsole((console, out) => {
console.dirxml("DIRXML");
assertEquals(out.toString(), "DIRXML\n");
});
mockConsole((console, out): void => {
mockConsole((console, out) => {
console.dirxml("DIRXML", { indentLevel: 2 });
assertEquals(out.toString(), " DIRXML\n");
});
});
// console.trace test
unitTest(function consoleTrace(): void {
mockConsole((console, _out, err): void => {
unitTest(function consoleTrace() {
mockConsole((console, _out, err) => {
console.trace("%s", "custom message");
assert(err);
assert(err.toString().includes("Trace: custom message"));
});
});
unitTest(function inspectString(): void {
unitTest(function inspectString() {
assertEquals(
stripColor(Deno.inspect("\0")),
`"\\x00"`,
@ -1604,7 +1604,7 @@ unitTest(function inspectString(): void {
);
});
unitTest(function inspectGetters(): void {
unitTest(function inspectGetters() {
assertEquals(
stripColor(Deno.inspect({
get foo() {
@ -1633,12 +1633,12 @@ unitTest(function inspectGetters(): void {
);
});
unitTest(function inspectPrototype(): void {
unitTest(function inspectPrototype() {
class A {}
assertEquals(Deno.inspect(A.prototype), "A {}");
});
unitTest(function inspectSorted(): void {
unitTest(function inspectSorted() {
assertEquals(
stripColor(Deno.inspect({ b: 2, a: 1 }, { sorted: true })),
"{ a: 1, b: 2 }",
@ -1659,7 +1659,7 @@ unitTest(function inspectSorted(): void {
);
});
unitTest(function inspectTrailingComma(): void {
unitTest(function inspectTrailingComma() {
assertEquals(
stripColor(Deno.inspect(
[
@ -1714,7 +1714,7 @@ unitTest(function inspectTrailingComma(): void {
);
});
unitTest(function inspectCompact(): void {
unitTest(function inspectCompact() {
assertEquals(
stripColor(Deno.inspect({ a: 1, b: 2 }, { compact: false })),
`{
@ -1724,7 +1724,7 @@ unitTest(function inspectCompact(): void {
);
});
unitTest(function inspectIterableLimit(): void {
unitTest(function inspectIterableLimit() {
assertEquals(
stripColor(Deno.inspect(["a", "b", "c"], { iterableLimit: 2 })),
`[ "a", "b", ... 1 more items ]`,
@ -1746,7 +1746,7 @@ unitTest(function inspectIterableLimit(): void {
);
});
unitTest(function inspectProxy(): void {
unitTest(function inspectProxy() {
assertEquals(
stripColor(Deno.inspect(
new Proxy([1, 2, 3], {}),
@ -1785,7 +1785,7 @@ unitTest(function inspectProxy(): void {
);
assertEquals(
stripColor(Deno.inspect(
new Proxy([1, 2, 3], { get(): void {} }),
new Proxy([1, 2, 3], { get() {} }),
{ showProxy: true },
)),
"Proxy [ [ 1, 2, 3 ], { get: [Function: get] } ]",
@ -1803,7 +1803,7 @@ unitTest(function inspectProxy(): void {
);
assertEquals(
stripColor(Deno.inspect(
new Proxy([1, 2, 3, 4, 5, 6, 7], { get(): void {} }),
new Proxy([1, 2, 3, 4, 5, 6, 7], { get() {} }),
{ showProxy: true },
)),
`Proxy [ [
@ -1813,14 +1813,14 @@ unitTest(function inspectProxy(): void {
);
assertEquals(
stripColor(Deno.inspect(
new Proxy(function fn() {}, { get(): void {} }),
new Proxy(function fn() {}, { get() {} }),
{ showProxy: true },
)),
"Proxy [ [Function: fn], { get: [Function: get] } ]",
);
});
unitTest(function inspectColors(): void {
unitTest(function inspectColors() {
assertEquals(Deno.inspect(1), "1");
assertStringIncludes(Deno.inspect(1, { colors: true }), "\x1b[");
});

View file

@ -12,7 +12,7 @@ function readFileString(filename: string | URL): string {
return dec.decode(dataRead);
}
function writeFileString(filename: string | URL, s: string): void {
function writeFileString(filename: string | URL, s: string) {
const enc = new TextEncoder();
const data = enc.encode(s);
Deno.writeFileSync(filename, data, { mode: 0o666 });
@ -21,7 +21,7 @@ function writeFileString(filename: string | URL, s: string): void {
function assertSameContent(
filename1: string | URL,
filename2: string | URL,
): void {
) {
const data1 = Deno.readFileSync(filename1);
const data2 = Deno.readFileSync(filename2);
assertEquals(data1, data2);
@ -29,7 +29,7 @@ function assertSameContent(
unitTest(
{ perms: { read: true, write: true } },
function copyFileSyncSuccess(): void {
function copyFileSyncSuccess() {
const tempDir = Deno.makeTempDirSync();
const fromFilename = tempDir + "/from.txt";
const toFilename = tempDir + "/to.txt";
@ -46,7 +46,7 @@ unitTest(
unitTest(
{ perms: { read: true, write: true } },
function copyFileSyncByUrl(): void {
function copyFileSyncByUrl() {
const tempDir = Deno.makeTempDirSync();
const fromUrl = new URL(
`file://${Deno.build.os === "windows" ? "/" : ""}${tempDir}/from.txt`,
@ -67,7 +67,7 @@ unitTest(
unitTest(
{ perms: { write: true, read: true } },
function copyFileSyncFailure(): void {
function copyFileSyncFailure() {
const tempDir = Deno.makeTempDirSync();
const fromFilename = tempDir + "/from.txt";
const toFilename = tempDir + "/to.txt";
@ -82,7 +82,7 @@ unitTest(
unitTest(
{ perms: { write: true, read: false } },
function copyFileSyncPerm1(): void {
function copyFileSyncPerm1() {
assertThrows(() => {
Deno.copyFileSync("/from.txt", "/to.txt");
}, Deno.errors.PermissionDenied);
@ -91,7 +91,7 @@ unitTest(
unitTest(
{ perms: { write: false, read: true } },
function copyFileSyncPerm2(): void {
function copyFileSyncPerm2() {
assertThrows(() => {
Deno.copyFileSync("/from.txt", "/to.txt");
}, Deno.errors.PermissionDenied);
@ -100,7 +100,7 @@ unitTest(
unitTest(
{ perms: { read: true, write: true } },
function copyFileSyncOverwrite(): void {
function copyFileSyncOverwrite() {
const tempDir = Deno.makeTempDirSync();
const fromFilename = tempDir + "/from.txt";
const toFilename = tempDir + "/to.txt";
@ -119,7 +119,7 @@ unitTest(
unitTest(
{ perms: { read: true, write: true } },
async function copyFileSuccess(): Promise<void> {
async function copyFileSuccess() {
const tempDir = Deno.makeTempDirSync();
const fromFilename = tempDir + "/from.txt";
const toFilename = tempDir + "/to.txt";
@ -136,7 +136,7 @@ unitTest(
unitTest(
{ perms: { read: true, write: true } },
async function copyFileByUrl(): Promise<void> {
async function copyFileByUrl() {
const tempDir = Deno.makeTempDirSync();
const fromUrl = new URL(
`file://${Deno.build.os === "windows" ? "/" : ""}${tempDir}/from.txt`,
@ -157,7 +157,7 @@ unitTest(
unitTest(
{ perms: { read: true, write: true } },
async function copyFileFailure(): Promise<void> {
async function copyFileFailure() {
const tempDir = Deno.makeTempDirSync();
const fromFilename = tempDir + "/from.txt";
const toFilename = tempDir + "/to.txt";
@ -172,7 +172,7 @@ unitTest(
unitTest(
{ perms: { read: true, write: true } },
async function copyFileOverwrite(): Promise<void> {
async function copyFileOverwrite() {
const tempDir = Deno.makeTempDirSync();
const fromFilename = tempDir + "/from.txt";
const toFilename = tempDir + "/to.txt";
@ -191,7 +191,7 @@ unitTest(
unitTest(
{ perms: { read: false, write: true } },
async function copyFilePerm1(): Promise<void> {
async function copyFilePerm1() {
await assertThrowsAsync(async () => {
await Deno.copyFile("/from.txt", "/to.txt");
}, Deno.errors.PermissionDenied);
@ -200,7 +200,7 @@ unitTest(
unitTest(
{ perms: { read: true, write: false } },
async function copyFilePerm2(): Promise<void> {
async function copyFilePerm2() {
await assertThrowsAsync(async () => {
await Deno.copyFile("/from.txt", "/to.txt");
}, Deno.errors.PermissionDenied);

View file

@ -1,7 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assertEquals, unitTest } from "./test_util.ts";
unitTest(function customEventInitializedWithDetail(): void {
unitTest(function customEventInitializedWithDetail() {
const type = "touchstart";
const detail = { message: "hello" };
const customEventInit = {
@ -20,7 +20,7 @@ unitTest(function customEventInitializedWithDetail(): void {
assertEquals(event.type, type);
});
unitTest(function toStringShouldBeWebCompatibility(): void {
unitTest(function toStringShouldBeWebCompatibility() {
const type = "touchstart";
const event = new CustomEvent(type, {});
assertEquals(event.toString(), "[object CustomEvent]");

View file

@ -1,13 +1,13 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assert, assertEquals, assertThrows, unitTest } from "./test_util.ts";
unitTest({ perms: { read: true } }, function dirCwdNotNull(): void {
unitTest({ perms: { read: true } }, function dirCwdNotNull() {
assert(Deno.cwd() != null);
});
unitTest(
{ perms: { read: true, write: true } },
function dirCwdChdirSuccess(): void {
function dirCwdChdirSuccess() {
const initialdir = Deno.cwd();
const path = Deno.makeTempDirSync();
Deno.chdir(path);
@ -21,7 +21,7 @@ unitTest(
},
);
unitTest({ perms: { read: true, write: true } }, function dirCwdError(): void {
unitTest({ perms: { read: true, write: true } }, function dirCwdError() {
// excluding windows since it throws resource busy, while removeSync
if (["linux", "darwin"].includes(Deno.build.os)) {
const initialdir = Deno.cwd();
@ -38,7 +38,7 @@ unitTest({ perms: { read: true, write: true } }, function dirCwdError(): void {
}
});
unitTest({ perms: { read: false } }, function dirCwdPermError(): void {
unitTest({ perms: { read: false } }, function dirCwdPermError() {
assertThrows(
() => {
Deno.cwd();
@ -50,7 +50,7 @@ unitTest({ perms: { read: false } }, function dirCwdPermError(): void {
unitTest(
{ perms: { read: true, write: true } },
function dirChdirError(): void {
function dirChdirError() {
const path = Deno.makeTempDirSync() + "test";
assertThrows(() => {
Deno.chdir(path);

View file

@ -1,6 +1,6 @@
import { assertEquals, assertStringIncludes, unitTest } from "./test_util.ts";
unitTest(function customInspectFunction(): void {
unitTest(function customInspectFunction() {
const blob = new DOMException("test");
assertEquals(
Deno.inspect(blob),

View file

@ -1,7 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assert, assertEquals, assertMatch, unitTest } from "./test_util.ts";
unitTest(function errorStackMessageLine(): void {
unitTest(function errorStackMessageLine() {
const e1 = new Error();
e1.name = "Foo";
e1.message = "bar";
@ -41,8 +41,8 @@ unitTest(function errorStackMessageLine(): void {
assertMatch(e6.stack!, /^null: null\n/);
});
unitTest(function captureStackTrace(): void {
function foo(): void {
unitTest(function captureStackTrace() {
function foo() {
const error = new Error();
const stack1 = error.stack!;
Error.captureStackTrace(error, foo);
@ -55,7 +55,7 @@ unitTest(function captureStackTrace(): void {
// FIXME(bartlomieju): no longer works after migrating
// to JavaScript runtime code
unitTest({ ignore: true }, function applySourceMap(): void {
unitTest({ ignore: true }, function applySourceMap() {
const result = Deno.applySourceMap({
fileName: "CLI_SNAPSHOT.js",
lineNumber: 23,

View file

@ -1,7 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assertEquals, unitTest } from "./test_util.ts";
unitTest(function addEventListenerTest(): void {
unitTest(function addEventListenerTest() {
const document = new EventTarget();
assertEquals(document.addEventListener("x", null, false), undefined);
@ -9,12 +9,12 @@ unitTest(function addEventListenerTest(): void {
assertEquals(document.addEventListener("x", null), undefined);
});
unitTest(function constructedEventTargetCanBeUsedAsExpected(): void {
unitTest(function constructedEventTargetCanBeUsedAsExpected() {
const target = new EventTarget();
const event = new Event("foo", { bubbles: true, cancelable: false });
let callCount = 0;
const listener = (e: Event): void => {
const listener = (e: Event) => {
assertEquals(e, event);
++callCount;
};
@ -32,13 +32,13 @@ unitTest(function constructedEventTargetCanBeUsedAsExpected(): void {
assertEquals(callCount, 2);
});
unitTest(function anEventTargetCanBeSubclassed(): void {
unitTest(function anEventTargetCanBeSubclassed() {
class NicerEventTarget extends EventTarget {
on(
type: string,
callback: ((e: Event) => void) | null,
options?: AddEventListenerOptions,
): void {
) {
this.addEventListener(type, callback, options);
}
@ -46,7 +46,7 @@ unitTest(function anEventTargetCanBeSubclassed(): void {
type: string,
callback: ((e: Event) => void) | null,
options?: EventListenerOptions,
): void {
) {
this.removeEventListener(type, callback, options);
}
}
@ -55,7 +55,7 @@ unitTest(function anEventTargetCanBeSubclassed(): void {
new Event("foo", { bubbles: true, cancelable: false });
let callCount = 0;
const listener = (): void => {
const listener = () => {
++callCount;
};
@ -66,19 +66,19 @@ unitTest(function anEventTargetCanBeSubclassed(): void {
assertEquals(callCount, 0);
});
unitTest(function removingNullEventListenerShouldSucceed(): void {
unitTest(function removingNullEventListenerShouldSucceed() {
const document = new EventTarget();
assertEquals(document.removeEventListener("x", null, false), undefined);
assertEquals(document.removeEventListener("x", null, true), undefined);
assertEquals(document.removeEventListener("x", null), undefined);
});
unitTest(function constructedEventTargetUseObjectPrototype(): void {
unitTest(function constructedEventTargetUseObjectPrototype() {
const target = new EventTarget();
const event = new Event("toString", { bubbles: true, cancelable: false });
let callCount = 0;
const listener = (e: Event): void => {
const listener = (e: Event) => {
assertEquals(e, event);
++callCount;
};
@ -96,12 +96,12 @@ unitTest(function constructedEventTargetUseObjectPrototype(): void {
assertEquals(callCount, 2);
});
unitTest(function toStringShouldBeWebCompatible(): void {
unitTest(function toStringShouldBeWebCompatible() {
const target = new EventTarget();
assertEquals(target.toString(), "[object EventTarget]");
});
unitTest(function dispatchEventShouldNotThrowError(): void {
unitTest(function dispatchEventShouldNotThrowError() {
let hasThrown = false;
try {
@ -110,7 +110,7 @@ unitTest(function dispatchEventShouldNotThrowError(): void {
bubbles: true,
cancelable: false,
});
const listener = (): void => {};
const listener = () => {};
target.addEventListener("hasOwnProperty", listener);
target.dispatchEvent(event);
} catch {
@ -120,7 +120,7 @@ unitTest(function dispatchEventShouldNotThrowError(): void {
assertEquals(hasThrown, false);
});
unitTest(function eventTargetThisShouldDefaultToWindow(): void {
unitTest(function eventTargetThisShouldDefaultToWindow() {
const {
addEventListener,
dispatchEvent,
@ -128,7 +128,7 @@ unitTest(function eventTargetThisShouldDefaultToWindow(): void {
} = EventTarget.prototype;
let n = 1;
const event = new Event("hello");
const listener = (): void => {
const listener = () => {
n = 2;
};
@ -149,13 +149,13 @@ unitTest(function eventTargetThisShouldDefaultToWindow(): void {
assertEquals(n, 1);
});
unitTest(function eventTargetShouldAcceptEventListenerObject(): void {
unitTest(function eventTargetShouldAcceptEventListenerObject() {
const target = new EventTarget();
const event = new Event("foo", { bubbles: true, cancelable: false });
let callCount = 0;
const listener = {
handleEvent(e: Event): void {
handleEvent(e: Event) {
assertEquals(e, event);
++callCount;
},
@ -174,12 +174,12 @@ unitTest(function eventTargetShouldAcceptEventListenerObject(): void {
assertEquals(callCount, 2);
});
unitTest(function eventTargetShouldAcceptAsyncFunction(): void {
unitTest(function eventTargetShouldAcceptAsyncFunction() {
const target = new EventTarget();
const event = new Event("foo", { bubbles: true, cancelable: false });
let callCount = 0;
const listener = (e: Event): void => {
const listener = (e: Event) => {
assertEquals(e, event);
++callCount;
};
@ -198,13 +198,13 @@ unitTest(function eventTargetShouldAcceptAsyncFunction(): void {
});
unitTest(
function eventTargetShouldAcceptAsyncFunctionForEventListenerObject(): void {
function eventTargetShouldAcceptAsyncFunctionForEventListenerObject() {
const target = new EventTarget();
const event = new Event("foo", { bubbles: true, cancelable: false });
let callCount = 0;
const listener = {
handleEvent(e: Event): void {
handleEvent(e: Event) {
assertEquals(e, event);
++callCount;
},
@ -223,7 +223,7 @@ unitTest(
assertEquals(callCount, 2);
},
);
unitTest(function eventTargetDispatchShouldSetTargetNoListener(): void {
unitTest(function eventTargetDispatchShouldSetTargetNoListener() {
const target = new EventTarget();
const event = new Event("foo");
assertEquals(event.target, null);
@ -231,7 +231,7 @@ unitTest(function eventTargetDispatchShouldSetTargetNoListener(): void {
assertEquals(event.target, target);
});
unitTest(function eventTargetDispatchShouldSetTargetInListener(): void {
unitTest(function eventTargetDispatchShouldSetTargetInListener() {
const target = new EventTarget();
const event = new Event("foo");
assertEquals(event.target, null);

View file

@ -6,7 +6,7 @@ import {
unitTest,
} from "./test_util.ts";
unitTest(function eventInitializedWithType(): void {
unitTest(function eventInitializedWithType() {
const type = "click";
const event = new Event(type);
@ -18,7 +18,7 @@ unitTest(function eventInitializedWithType(): void {
assertEquals(event.cancelable, false);
});
unitTest(function eventInitializedWithTypeAndDict(): void {
unitTest(function eventInitializedWithTypeAndDict() {
const init = "submit";
const eventInit = { bubbles: true, cancelable: true } as EventInit;
const event = new Event(init, eventInit);
@ -31,7 +31,7 @@ unitTest(function eventInitializedWithTypeAndDict(): void {
assertEquals(event.cancelable, true);
});
unitTest(function eventComposedPathSuccess(): void {
unitTest(function eventComposedPathSuccess() {
const type = "click";
const event = new Event(type);
const composedPath = event.composedPath();
@ -39,7 +39,7 @@ unitTest(function eventComposedPathSuccess(): void {
assertEquals(composedPath, []);
});
unitTest(function eventStopPropagationSuccess(): void {
unitTest(function eventStopPropagationSuccess() {
const type = "click";
const event = new Event(type);
@ -48,7 +48,7 @@ unitTest(function eventStopPropagationSuccess(): void {
assertEquals(event.cancelBubble, true);
});
unitTest(function eventStopImmediatePropagationSuccess(): void {
unitTest(function eventStopImmediatePropagationSuccess() {
const type = "click";
const event = new Event(type);
@ -57,7 +57,7 @@ unitTest(function eventStopImmediatePropagationSuccess(): void {
assertEquals(event.cancelBubble, true);
});
unitTest(function eventPreventDefaultSuccess(): void {
unitTest(function eventPreventDefaultSuccess() {
const type = "click";
const event = new Event(type);
@ -72,7 +72,7 @@ unitTest(function eventPreventDefaultSuccess(): void {
assertEquals(cancelableEvent.defaultPrevented, true);
});
unitTest(function eventInitializedWithNonStringType(): void {
unitTest(function eventInitializedWithNonStringType() {
// deno-lint-ignore no-explicit-any
const type: any = undefined;
const event = new Event(type);
@ -86,7 +86,7 @@ unitTest(function eventInitializedWithNonStringType(): void {
});
// ref https://github.com/web-platform-tests/wpt/blob/master/dom/events/Event-isTrusted.any.js
unitTest(function eventIsTrusted(): void {
unitTest(function eventIsTrusted() {
const desc1 = Object.getOwnPropertyDescriptor(new Event("x"), "isTrusted");
assert(desc1);
assertEquals(typeof desc1.get, "function");
@ -98,7 +98,7 @@ unitTest(function eventIsTrusted(): void {
assertEquals(desc1!.get, desc2!.get);
});
unitTest(function eventInspectOutput(): void {
unitTest(function eventInspectOutput() {
// deno-lint-ignore no-explicit-any
const cases: Array<[any, (event: any) => string]> = [
[
@ -133,7 +133,7 @@ unitTest(function eventInspectOutput(): void {
}
});
unitTest(function inspectEvent(): void {
unitTest(function inspectEvent() {
// has a customInspect implementation that previously would throw on a getter
assertEquals(
Deno.inspect(Event.prototype),

View file

@ -12,7 +12,7 @@ import { Buffer } from "../../../test_util/std/io/buffer.ts";
unitTest(
{ perms: { net: true } },
async function fetchRequiresOneArgument(): Promise<void> {
async function fetchRequiresOneArgument() {
await assertThrowsAsync(
fetch as unknown as () => Promise<void>,
TypeError,
@ -20,11 +20,9 @@ unitTest(
},
);
unitTest({ perms: { net: true } }, async function fetchProtocolError(): Promise<
void
> {
unitTest({ perms: { net: true } }, async function fetchProtocolError() {
await assertThrowsAsync(
async (): Promise<void> => {
async () => {
await fetch("file:///");
},
TypeError,
@ -58,10 +56,10 @@ function findClosedPortInRange(
unitTest(
{ perms: { net: true } },
async function fetchConnectionError(): Promise<void> {
async function fetchConnectionError() {
const port = findClosedPortInRange(4000, 9999);
await assertThrowsAsync(
async (): Promise<void> => {
async () => {
await fetch(`http://localhost:${port}`);
},
TypeError,
@ -72,9 +70,9 @@ unitTest(
unitTest(
{ perms: { net: true } },
async function fetchDnsError(): Promise<void> {
async function fetchDnsError() {
await assertThrowsAsync(
async (): Promise<void> => {
async () => {
await fetch("http://nil/");
},
TypeError,
@ -85,9 +83,9 @@ unitTest(
unitTest(
{ perms: { net: true } },
async function fetchInvalidUriError(): Promise<void> {
async function fetchInvalidUriError() {
await assertThrowsAsync(
async (): Promise<void> => {
async () => {
await fetch("http://<invalid>/");
},
TypeError,
@ -95,27 +93,25 @@ unitTest(
},
);
unitTest({ perms: { net: true } }, async function fetchJsonSuccess(): Promise<
void
> {
unitTest({ perms: { net: true } }, async function fetchJsonSuccess() {
const response = await fetch("http://localhost:4545/cli/tests/fixture.json");
const json = await response.json();
assertEquals(json.name, "deno");
});
unitTest(async function fetchPerm(): Promise<void> {
unitTest(async function fetchPerm() {
await assertThrowsAsync(async () => {
await fetch("http://localhost:4545/cli/tests/fixture.json");
}, Deno.errors.PermissionDenied);
});
unitTest({ perms: { net: true } }, async function fetchUrl(): Promise<void> {
unitTest({ perms: { net: true } }, async function fetchUrl() {
const response = await fetch("http://localhost:4545/cli/tests/fixture.json");
assertEquals(response.url, "http://localhost:4545/cli/tests/fixture.json");
const _json = await response.json();
});
unitTest({ perms: { net: true } }, async function fetchURL(): Promise<void> {
unitTest({ perms: { net: true } }, async function fetchURL() {
const response = await fetch(
new URL("http://localhost:4545/cli/tests/fixture.json"),
);
@ -123,16 +119,14 @@ unitTest({ perms: { net: true } }, async function fetchURL(): Promise<void> {
const _json = await response.json();
});
unitTest({ perms: { net: true } }, async function fetchHeaders(): Promise<
void
> {
unitTest({ perms: { net: true } }, async function fetchHeaders() {
const response = await fetch("http://localhost:4545/cli/tests/fixture.json");
const headers = response.headers;
assertEquals(headers.get("Content-Type"), "application/json");
const _json = await response.json();
});
unitTest({ perms: { net: true } }, async function fetchBlob(): Promise<void> {
unitTest({ perms: { net: true } }, async function fetchBlob() {
const response = await fetch("http://localhost:4545/cli/tests/fixture.json");
const headers = response.headers;
const blob = await response.blob();
@ -142,7 +136,7 @@ unitTest({ perms: { net: true } }, async function fetchBlob(): Promise<void> {
unitTest(
{ perms: { net: true } },
async function fetchBodyUsedReader(): Promise<void> {
async function fetchBodyUsedReader() {
const response = await fetch(
"http://localhost:4545/cli/tests/fixture.json",
);
@ -160,7 +154,7 @@ unitTest(
unitTest(
{ perms: { net: true } },
async function fetchBodyUsedCancelStream(): Promise<void> {
async function fetchBodyUsedCancelStream() {
const response = await fetch(
"http://localhost:4545/cli/tests/fixture.json",
);
@ -173,9 +167,7 @@ unitTest(
},
);
unitTest({ perms: { net: true } }, async function fetchAsyncIterator(): Promise<
void
> {
unitTest({ perms: { net: true } }, async function fetchAsyncIterator() {
const response = await fetch("http://localhost:4545/cli/tests/fixture.json");
const headers = response.headers;
@ -189,9 +181,7 @@ unitTest({ perms: { net: true } }, async function fetchAsyncIterator(): Promise<
assertEquals(total, Number(headers.get("Content-Length")));
});
unitTest({ perms: { net: true } }, async function fetchBodyReader(): Promise<
void
> {
unitTest({ perms: { net: true } }, async function fetchBodyReader() {
const response = await fetch("http://localhost:4545/cli/tests/fixture.json");
const headers = response.headers;
assert(response.body !== null);
@ -210,7 +200,7 @@ unitTest({ perms: { net: true } }, async function fetchBodyReader(): Promise<
unitTest(
{ perms: { net: true } },
async function fetchBodyReaderBigBody(): Promise<void> {
async function fetchBodyReaderBigBody() {
const data = "a".repeat(10 << 10); // 10mb
const response = await fetch("http://localhost:4545/echo_server", {
method: "POST",
@ -230,9 +220,7 @@ unitTest(
},
);
unitTest({ perms: { net: true } }, async function responseClone(): Promise<
void
> {
unitTest({ perms: { net: true } }, async function responseClone() {
const response = await fetch("http://localhost:4545/cli/tests/fixture.json");
const response1 = response.clone();
assert(response !== response1);
@ -247,7 +235,7 @@ unitTest({ perms: { net: true } }, async function responseClone(): Promise<
unitTest(
{ perms: { net: true } },
async function fetchMultipartFormDataSuccess(): Promise<void> {
async function fetchMultipartFormDataSuccess() {
const response = await fetch(
"http://localhost:4545/multipart_form_data.txt",
);
@ -264,14 +252,14 @@ unitTest(
unitTest(
{ perms: { net: true } },
async function fetchMultipartFormBadContentType(): Promise<void> {
async function fetchMultipartFormBadContentType() {
const response = await fetch(
"http://localhost:4545/multipart_form_bad_content_type",
);
assert(response.body !== null);
await assertThrowsAsync(
async (): Promise<void> => {
async () => {
await response.formData();
},
TypeError,
@ -282,7 +270,7 @@ unitTest(
unitTest(
{ perms: { net: true } },
async function fetchURLEncodedFormDataSuccess(): Promise<void> {
async function fetchURLEncodedFormDataSuccess() {
const response = await fetch(
"http://localhost:4545/cli/tests/subdir/form_urlencoded.txt",
);
@ -296,7 +284,7 @@ unitTest(
unitTest(
{ perms: { net: true } },
async function fetchInitFormDataBinaryFileBody(): Promise<void> {
async function fetchInitFormDataBinaryFileBody() {
// Some random bytes
// deno-fmt-ignore
const binaryFile = new Uint8Array([108,2,0,0,145,22,162,61,157,227,166,77,138,75,180,56,119,188,177,183]);
@ -315,7 +303,7 @@ unitTest(
unitTest(
{ perms: { net: true } },
async function fetchInitFormDataMultipleFilesBody(): Promise<void> {
async function fetchInitFormDataMultipleFilesBody() {
const files = [
{
// deno-fmt-ignore
@ -371,7 +359,7 @@ unitTest(
{
perms: { net: true },
},
async function fetchWithRedirection(): Promise<void> {
async function fetchWithRedirection() {
const response = await fetch("http://localhost:4546/README.md");
assertEquals(response.status, 200);
assertEquals(response.statusText, "OK");
@ -385,7 +373,7 @@ unitTest(
{
perms: { net: true },
},
async function fetchWithRelativeRedirection(): Promise<void> {
async function fetchWithRelativeRedirection() {
const response = await fetch(
"http://localhost:4545/cli/tests/001_hello.js",
);
@ -400,7 +388,7 @@ unitTest(
{
perms: { net: true },
},
async function fetchWithRelativeRedirectionUrl(): Promise<void> {
async function fetchWithRelativeRedirectionUrl() {
const cases = [
["end", "http://localhost:4550/a/b/end"],
["/end", "http://localhost:4550/end"],
@ -421,7 +409,7 @@ unitTest(
{
perms: { net: true },
},
async function fetchWithInfRedirection(): Promise<void> {
async function fetchWithInfRedirection() {
await assertThrowsAsync(
() => fetch("http://localhost:4549/cli/tests"),
TypeError,
@ -432,7 +420,7 @@ unitTest(
unitTest(
{ perms: { net: true } },
async function fetchInitStringBody(): Promise<void> {
async function fetchInitStringBody() {
const data = "Hello World";
const response = await fetch("http://localhost:4545/echo_server", {
method: "POST",
@ -446,7 +434,7 @@ unitTest(
unitTest(
{ perms: { net: true } },
async function fetchRequestInitStringBody(): Promise<void> {
async function fetchRequestInitStringBody() {
const data = "Hello World";
const req = new Request("http://localhost:4545/echo_server", {
method: "POST",
@ -460,7 +448,7 @@ unitTest(
unitTest(
{ perms: { net: true } },
async function fetchSeparateInit(): Promise<void> {
async function fetchSeparateInit() {
// related to: https://github.com/denoland/deno/issues/10396
const req = new Request("http://localhost:4545/cli/tests/001_hello.js");
const init = {
@ -475,7 +463,7 @@ unitTest(
unitTest(
{ perms: { net: true } },
async function fetchInitTypedArrayBody(): Promise<void> {
async function fetchInitTypedArrayBody() {
const data = "Hello World";
const response = await fetch("http://localhost:4545/echo_server", {
method: "POST",
@ -488,7 +476,7 @@ unitTest(
unitTest(
{ perms: { net: true } },
async function fetchInitArrayBufferBody(): Promise<void> {
async function fetchInitArrayBufferBody() {
const data = "Hello World";
const response = await fetch("http://localhost:4545/echo_server", {
method: "POST",
@ -501,7 +489,7 @@ unitTest(
unitTest(
{ perms: { net: true } },
async function fetchInitURLSearchParamsBody(): Promise<void> {
async function fetchInitURLSearchParamsBody() {
const data = "param1=value1&param2=value2";
const params = new URLSearchParams(data);
const response = await fetch("http://localhost:4545/echo_server", {
@ -518,9 +506,7 @@ unitTest(
},
);
unitTest({ perms: { net: true } }, async function fetchInitBlobBody(): Promise<
void
> {
unitTest({ perms: { net: true } }, async function fetchInitBlobBody() {
const data = "const a = 1";
const blob = new Blob([data], {
type: "text/javascript",
@ -536,7 +522,7 @@ unitTest({ perms: { net: true } }, async function fetchInitBlobBody(): Promise<
unitTest(
{ perms: { net: true } },
async function fetchInitFormDataBody(): Promise<void> {
async function fetchInitFormDataBody() {
const form = new FormData();
form.append("field", "value");
const response = await fetch("http://localhost:4545/echo_server", {
@ -550,7 +536,7 @@ unitTest(
unitTest(
{ perms: { net: true } },
async function fetchInitFormDataBlobFilenameBody(): Promise<void> {
async function fetchInitFormDataBlobFilenameBody() {
const form = new FormData();
form.append("field", "value");
form.append("file", new Blob([new TextEncoder().encode("deno")]));
@ -568,7 +554,7 @@ unitTest(
unitTest(
{ perms: { net: true } },
async function fetchInitFormDataTextFileBody(): Promise<void> {
async function fetchInitFormDataTextFileBody() {
const fileContent = "deno land";
const form = new FormData();
form.append("field", "value");
@ -596,9 +582,7 @@ unitTest(
},
);
unitTest({ perms: { net: true } }, async function fetchUserAgent(): Promise<
void
> {
unitTest({ perms: { net: true } }, async function fetchUserAgent() {
const data = "Hello World";
const response = await fetch("http://localhost:4545/echo_server", {
method: "POST",
@ -658,7 +642,7 @@ unitTest(
{
perms: { net: true },
},
async function fetchRequest(): Promise<void> {
async function fetchRequest() {
const addr = "127.0.0.1:4501";
const buf = bufferServer(addr);
const response = await fetch(`http://${addr}/blah`, {
@ -690,7 +674,7 @@ unitTest(
{
perms: { net: true },
},
async function fetchPostBodyString(): Promise<void> {
async function fetchPostBodyString() {
const addr = "127.0.0.1:4502";
const buf = bufferServer(addr);
const body = "hello world";
@ -727,7 +711,7 @@ unitTest(
{
perms: { net: true },
},
async function fetchPostBodyTypedArray(): Promise<void> {
async function fetchPostBodyTypedArray() {
const addr = "127.0.0.1:4503";
const buf = bufferServer(addr);
const bodyStr = "hello world";
@ -764,7 +748,7 @@ unitTest(
{
perms: { net: true },
},
async function fetchWithNonAsciiRedirection(): Promise<void> {
async function fetchWithNonAsciiRedirection() {
const response = await fetch("http://localhost:4545/non_ascii_redirect", {
redirect: "manual",
});
@ -778,7 +762,7 @@ unitTest(
{
perms: { net: true },
},
async function fetchWithManualRedirection(): Promise<void> {
async function fetchWithManualRedirection() {
const response = await fetch("http://localhost:4546/", {
redirect: "manual",
}); // will redirect to http://localhost:4545/
@ -794,7 +778,7 @@ unitTest(
{
perms: { net: true },
},
async function fetchWithErrorRedirection(): Promise<void> {
async function fetchWithErrorRedirection() {
await assertThrowsAsync(
() =>
fetch("http://localhost:4546/", {
@ -806,7 +790,7 @@ unitTest(
},
);
unitTest(function responseRedirect(): void {
unitTest(function responseRedirect() {
const redir = Response.redirect("example.com/newLocation", 301);
assertEquals(redir.status, 301);
assertEquals(redir.statusText, "");
@ -818,7 +802,7 @@ unitTest(function responseRedirect(): void {
assertEquals(redir.type, "default");
});
unitTest(async function responseWithoutBody(): Promise<void> {
unitTest(async function responseWithoutBody() {
const response = new Response();
assertEquals(await response.arrayBuffer(), new ArrayBuffer(0));
const blob = await response.blob();
@ -830,9 +814,7 @@ unitTest(async function responseWithoutBody(): Promise<void> {
});
});
unitTest({ perms: { net: true } }, async function fetchBodyReadTwice(): Promise<
void
> {
unitTest({ perms: { net: true } }, async function fetchBodyReadTwice() {
const response = await fetch("http://localhost:4545/cli/tests/fixture.json");
// Read body
@ -855,7 +837,7 @@ unitTest({ perms: { net: true } }, async function fetchBodyReadTwice(): Promise<
unitTest(
{ perms: { net: true } },
async function fetchBodyReaderAfterRead(): Promise<void> {
async function fetchBodyReaderAfterRead() {
const response = await fetch(
"http://localhost:4545/cli/tests/fixture.json",
);
@ -878,7 +860,7 @@ unitTest(
unitTest(
{ perms: { net: true } },
async function fetchBodyReaderWithCancelAndNewReader(): Promise<void> {
async function fetchBodyReaderWithCancelAndNewReader() {
const data = "a".repeat(1 << 10);
const response = await fetch("http://localhost:4545/echo_server", {
method: "POST",
@ -906,7 +888,7 @@ unitTest(
unitTest(
{ perms: { net: true } },
async function fetchBodyReaderWithReadCancelAndNewReader(): Promise<void> {
async function fetchBodyReaderWithReadCancelAndNewReader() {
const data = "a".repeat(1 << 10);
const response = await fetch("http://localhost:4545/echo_server", {
@ -936,7 +918,7 @@ unitTest(
unitTest(
{ perms: { net: true } },
async function fetchResourceCloseAfterStreamCancel(): Promise<void> {
async function fetchResourceCloseAfterStreamCancel() {
const res = await fetch("http://localhost:4545/cli/tests/fixture.json");
assert(res.body !== null);
@ -954,7 +936,7 @@ unitTest(
// the software in your host machine. (os error 10053)
unitTest(
{ perms: { net: true }, ignore: Deno.build.os == "windows" },
async function fetchNullBodyStatus(): Promise<void> {
async function fetchNullBodyStatus() {
const nullBodyStatus = [101, 204, 205, 304];
for (const status of nullBodyStatus) {
@ -972,7 +954,7 @@ unitTest(
unitTest(
{ perms: { net: true } },
async function fetchResponseContentLength(): Promise<void> {
async function fetchResponseContentLength() {
const body = new Uint8Array(2 ** 16);
const headers = new Headers([["content-type", "application/octet-stream"]]);
const res = await fetch("http://localhost:4545/echo_server", {
@ -989,7 +971,7 @@ unitTest(
},
);
unitTest(function fetchResponseConstructorNullBody(): void {
unitTest(function fetchResponseConstructorNullBody() {
const nullBodyStatus = [204, 205, 304];
for (const status of nullBodyStatus) {
@ -1006,7 +988,7 @@ unitTest(function fetchResponseConstructorNullBody(): void {
}
});
unitTest(function fetchResponseConstructorInvalidStatus(): void {
unitTest(function fetchResponseConstructorInvalidStatus() {
const invalidStatus = [101, 600, 199, null, "", NaN];
for (const status of invalidStatus) {
@ -1022,7 +1004,7 @@ unitTest(function fetchResponseConstructorInvalidStatus(): void {
}
});
unitTest(function fetchResponseEmptyConstructor(): void {
unitTest(function fetchResponseEmptyConstructor() {
const response = new Response();
assertEquals(response.status, 200);
assertEquals(response.body, null);
@ -1099,7 +1081,7 @@ unitTest(
{
perms: { net: true },
},
async function fetchPostBodyReadableStream(): Promise<void> {
async function fetchPostBodyReadableStream() {
const addr = "127.0.0.1:4502";
const buf = bufferServer(addr);
const stream = new TransformStream();
@ -1143,7 +1125,7 @@ unitTest(
},
);
unitTest({}, function fetchWritableRespProps(): void {
unitTest({}, function fetchWritableRespProps() {
const original = new Response("https://deno.land", {
status: 404,
headers: { "x-deno": "foo" },

View file

@ -2,7 +2,7 @@
import { assert, assertEquals, unitTest } from "./test_util.ts";
// deno-lint-ignore no-explicit-any
function testFirstArgument(arg1: any[], expectedSize: number): void {
function testFirstArgument(arg1: any[], expectedSize: number) {
const file = new File(arg1, "name");
assert(file instanceof File);
assertEquals(file.name, "name");
@ -10,47 +10,47 @@ function testFirstArgument(arg1: any[], expectedSize: number): void {
assertEquals(file.type, "");
}
unitTest(function fileEmptyFileBits(): void {
unitTest(function fileEmptyFileBits() {
testFirstArgument([], 0);
});
unitTest(function fileStringFileBits(): void {
unitTest(function fileStringFileBits() {
testFirstArgument(["bits"], 4);
});
unitTest(function fileUnicodeStringFileBits(): void {
unitTest(function fileUnicodeStringFileBits() {
testFirstArgument(["𝓽𝓮𝔁𝓽"], 16);
});
unitTest(function fileStringObjectFileBits(): void {
unitTest(function fileStringObjectFileBits() {
testFirstArgument([new String("string object")], 13);
});
unitTest(function fileEmptyBlobFileBits(): void {
unitTest(function fileEmptyBlobFileBits() {
testFirstArgument([new Blob()], 0);
});
unitTest(function fileBlobFileBits(): void {
unitTest(function fileBlobFileBits() {
testFirstArgument([new Blob(["bits"])], 4);
});
unitTest(function fileEmptyFileFileBits(): void {
unitTest(function fileEmptyFileFileBits() {
testFirstArgument([new File([], "world.txt")], 0);
});
unitTest(function fileFileFileBits(): void {
unitTest(function fileFileFileBits() {
testFirstArgument([new File(["bits"], "world.txt")], 4);
});
unitTest(function fileArrayBufferFileBits(): void {
unitTest(function fileArrayBufferFileBits() {
testFirstArgument([new ArrayBuffer(8)], 8);
});
unitTest(function fileTypedArrayFileBits(): void {
unitTest(function fileTypedArrayFileBits() {
testFirstArgument([new Uint8Array([0x50, 0x41, 0x53, 0x53])], 4);
});
unitTest(function fileVariousFileBits(): void {
unitTest(function fileVariousFileBits() {
testFirstArgument(
[
"bits",
@ -64,45 +64,45 @@ unitTest(function fileVariousFileBits(): void {
);
});
unitTest(function fileNumberInFileBits(): void {
unitTest(function fileNumberInFileBits() {
testFirstArgument([12], 2);
});
unitTest(function fileArrayInFileBits(): void {
unitTest(function fileArrayInFileBits() {
testFirstArgument([[1, 2, 3]], 5);
});
unitTest(function fileObjectInFileBits(): void {
unitTest(function fileObjectInFileBits() {
// "[object Object]"
testFirstArgument([{}], 15);
});
// deno-lint-ignore no-explicit-any
function testSecondArgument(arg2: any, expectedFileName: string): void {
function testSecondArgument(arg2: any, expectedFileName: string) {
const file = new File(["bits"], arg2);
assert(file instanceof File);
assertEquals(file.name, expectedFileName);
}
unitTest(function fileUsingFileName(): void {
unitTest(function fileUsingFileName() {
testSecondArgument("dummy", "dummy");
});
unitTest(function fileUsingNullFileName(): void {
unitTest(function fileUsingNullFileName() {
testSecondArgument(null, "null");
});
unitTest(function fileUsingNumberFileName(): void {
unitTest(function fileUsingNumberFileName() {
testSecondArgument(1, "1");
});
unitTest(function fileUsingEmptyStringFileName(): void {
unitTest(function fileUsingEmptyStringFileName() {
testSecondArgument("", "");
});
unitTest(
{ perms: { read: true, write: true } },
function fileTruncateSyncSuccess(): void {
function fileTruncateSyncSuccess() {
const filename = Deno.makeTempDirSync() + "/test_fileTruncateSync.txt";
const file = Deno.openSync(filename, {
create: true,
@ -124,7 +124,7 @@ unitTest(
unitTest(
{ perms: { read: true, write: true } },
async function fileTruncateSuccess(): Promise<void> {
async function fileTruncateSuccess() {
const filename = Deno.makeTempDirSync() + "/test_fileTruncate.txt";
const file = await Deno.open(filename, {
create: true,
@ -144,7 +144,7 @@ unitTest(
},
);
unitTest({ perms: { read: true } }, function fileStatSyncSuccess(): void {
unitTest({ perms: { read: true } }, function fileStatSyncSuccess() {
const file = Deno.openSync("README.md");
const fileInfo = file.statSync();
assert(fileInfo.isFile);
@ -159,9 +159,7 @@ unitTest({ perms: { read: true } }, function fileStatSyncSuccess(): void {
file.close();
});
unitTest({ perms: { read: true } }, async function fileStatSuccess(): Promise<
void
> {
unitTest({ perms: { read: true } }, async function fileStatSuccess() {
const file = await Deno.open("README.md");
const fileInfo = await file.stat();
assert(fileInfo.isFile);

View file

@ -1,7 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assertEquals, unitTest } from "./test_util.ts";
unitTest(function fileReaderConstruct(): void {
unitTest(function fileReaderConstruct() {
const fr = new FileReader();
assertEquals(fr.readyState, FileReader.EMPTY);
@ -10,7 +10,7 @@ unitTest(function fileReaderConstruct(): void {
assertEquals(FileReader.DONE, 2);
});
unitTest(async function fileReaderLoadBlob(): Promise<void> {
unitTest(async function fileReaderLoadBlob() {
await new Promise<void>((resolve) => {
const fr = new FileReader();
const b1 = new Blob(["Hello World"]);
@ -44,18 +44,18 @@ unitTest(async function fileReaderLoadBlob(): Promise<void> {
hasDispatchedEvents.progress += 1;
});
fr.onloadstart = (): void => {
fr.onloadstart = () => {
hasOnEvents.loadstart = true;
};
fr.onprogress = (): void => {
fr.onprogress = () => {
assertEquals(fr.readyState, FileReader.LOADING);
hasOnEvents.progress += 1;
};
fr.onload = (): void => {
fr.onload = () => {
hasOnEvents.load = true;
};
fr.onloadend = (ev): void => {
fr.onloadend = (ev) => {
hasOnEvents.loadend = true;
result = fr.result as string;
@ -77,7 +77,7 @@ unitTest(async function fileReaderLoadBlob(): Promise<void> {
});
});
unitTest(async function fileReaderLoadBlobDouble(): Promise<void> {
unitTest(async function fileReaderLoadBlobDouble() {
// impl note from https://w3c.github.io/FileAPI/
// Event handler for the load or error events could have started another load,
// if that happens the loadend event for the first load is not fired
@ -89,7 +89,7 @@ unitTest(async function fileReaderLoadBlobDouble(): Promise<void> {
await new Promise<void>((resolve) => {
let result: string | null = null;
fr.onload = (): void => {
fr.onload = () => {
result = fr.result as string;
assertEquals(result === "First load" || result === "Second load", true);
@ -97,7 +97,7 @@ unitTest(async function fileReaderLoadBlobDouble(): Promise<void> {
fr.readAsText(b2);
}
};
fr.onloadend = (): void => {
fr.onloadend = () => {
assertEquals(result, "Second load");
resolve();
@ -107,13 +107,13 @@ unitTest(async function fileReaderLoadBlobDouble(): Promise<void> {
});
});
unitTest(async function fileReaderLoadBlobArrayBuffer(): Promise<void> {
unitTest(async function fileReaderLoadBlobArrayBuffer() {
await new Promise<void>((resolve) => {
const fr = new FileReader();
const b1 = new Blob(["Hello World"]);
let result: ArrayBuffer | null = null;
fr.onloadend = (ev): void => {
fr.onloadend = (ev) => {
assertEquals(fr.result instanceof ArrayBuffer, true);
result = fr.result as ArrayBuffer;
@ -129,13 +129,13 @@ unitTest(async function fileReaderLoadBlobArrayBuffer(): Promise<void> {
});
});
unitTest(async function fileReaderLoadBlobDataUrl(): Promise<void> {
unitTest(async function fileReaderLoadBlobDataUrl() {
await new Promise<void>((resolve) => {
const fr = new FileReader();
const b1 = new Blob(["Hello World"]);
let result: string | null = null;
fr.onloadend = (ev): void => {
fr.onloadend = (ev) => {
result = fr.result as string;
assertEquals(
result,
@ -149,7 +149,7 @@ unitTest(async function fileReaderLoadBlobDataUrl(): Promise<void> {
});
});
unitTest(async function fileReaderLoadBlobAbort(): Promise<void> {
unitTest(async function fileReaderLoadBlobAbort() {
await new Promise<void>((resolve) => {
const fr = new FileReader();
const b1 = new Blob(["Hello World"]);
@ -160,10 +160,10 @@ unitTest(async function fileReaderLoadBlobAbort(): Promise<void> {
abort: false,
};
fr.onload = (): void => {
fr.onload = () => {
hasOnEvents.load = true;
};
fr.onloadend = (ev): void => {
fr.onloadend = (ev) => {
hasOnEvents.loadend = true;
assertEquals(hasOnEvents.load, false);
@ -175,7 +175,7 @@ unitTest(async function fileReaderLoadBlobAbort(): Promise<void> {
assertEquals(ev.lengthComputable, false);
resolve();
};
fr.onabort = (): void => {
fr.onabort = () => {
hasOnEvents.abort = true;
};
@ -184,7 +184,7 @@ unitTest(async function fileReaderLoadBlobAbort(): Promise<void> {
});
});
unitTest(async function fileReaderLoadBlobAbort(): Promise<void> {
unitTest(async function fileReaderLoadBlobAbort() {
await new Promise<void>((resolve) => {
const fr = new FileReader();
const b1 = new Blob(["Hello World"]);
@ -195,10 +195,10 @@ unitTest(async function fileReaderLoadBlobAbort(): Promise<void> {
abort: false,
};
fr.onload = (): void => {
fr.onload = () => {
hasOnEvents.load = true;
};
fr.onloadend = (ev): void => {
fr.onloadend = (ev) => {
hasOnEvents.loadend = true;
assertEquals(hasOnEvents.load, false);
@ -210,7 +210,7 @@ unitTest(async function fileReaderLoadBlobAbort(): Promise<void> {
assertEquals(ev.lengthComputable, false);
resolve();
};
fr.onabort = (): void => {
fr.onabort = () => {
hasOnEvents.abort = true;
};
@ -220,7 +220,7 @@ unitTest(async function fileReaderLoadBlobAbort(): Promise<void> {
});
unitTest(
async function fileReaderDispatchesEventsInCorrectOrder(): Promise<void> {
async function fileReaderDispatchesEventsInCorrectOrder() {
await new Promise<void>((resolve) => {
const fr = new FileReader();
const b1 = new Blob(["Hello World"]);
@ -228,7 +228,7 @@ unitTest(
fr.addEventListener("loadend", () => {
out += "1";
});
fr.onloadend = (_ev): void => {
fr.onloadend = (_ev) => {
out += "2";
};
fr.addEventListener("loadend", () => {

View file

@ -10,15 +10,13 @@ import {
} from "./test_util.ts";
import { copy } from "../../../test_util/std/io/util.ts";
unitTest(function filesStdioFileDescriptors(): void {
unitTest(function filesStdioFileDescriptors() {
assertEquals(Deno.stdin.rid, 0);
assertEquals(Deno.stdout.rid, 1);
assertEquals(Deno.stderr.rid, 2);
});
unitTest({ perms: { read: true } }, async function filesCopyToStdout(): Promise<
void
> {
unitTest({ perms: { read: true } }, async function filesCopyToStdout() {
const filename = "cli/tests/fixture.json";
const file = await Deno.open(filename);
assert(file.rid > 2);
@ -28,7 +26,7 @@ unitTest({ perms: { read: true } }, async function filesCopyToStdout(): Promise<
file.close();
});
unitTest({ perms: { read: true } }, async function filesIter(): Promise<void> {
unitTest({ perms: { read: true } }, async function filesIter() {
const filename = "cli/tests/hello.txt";
const file = await Deno.open(filename);
@ -43,7 +41,7 @@ unitTest({ perms: { read: true } }, async function filesIter(): Promise<void> {
unitTest(
{ perms: { read: true } },
async function filesIterCustomBufSize(): Promise<void> {
async function filesIterCustomBufSize() {
const filename = "cli/tests/hello.txt";
const file = await Deno.open(filename);
@ -60,7 +58,7 @@ unitTest(
},
);
unitTest({ perms: { read: true } }, function filesIterSync(): void {
unitTest({ perms: { read: true } }, function filesIterSync() {
const filename = "cli/tests/hello.txt";
const file = Deno.openSync(filename);
@ -75,7 +73,7 @@ unitTest({ perms: { read: true } }, function filesIterSync(): void {
unitTest(
{ perms: { read: true } },
function filesIterSyncCustomBufSize(): void {
function filesIterSyncCustomBufSize() {
const filename = "cli/tests/hello.txt";
const file = Deno.openSync(filename);
@ -92,7 +90,7 @@ unitTest(
},
);
unitTest(async function readerIter(): Promise<void> {
unitTest(async function readerIter() {
// ref: https://github.com/denoland/deno/issues/2330
const encoder = new TextEncoder();
@ -127,7 +125,7 @@ unitTest(async function readerIter(): Promise<void> {
assertEquals(totalSize, 12);
});
unitTest(async function readerIterSync(): Promise<void> {
unitTest(async function readerIterSync() {
// ref: https://github.com/denoland/deno/issues/2330
const encoder = new TextEncoder();
@ -166,7 +164,7 @@ unitTest(
{
perms: { read: true, write: true },
},
function openSyncMode(): void {
function openSyncMode() {
const path = Deno.makeTempDirSync() + "/test_openSync.txt";
const file = Deno.openSync(path, {
write: true,
@ -185,7 +183,7 @@ unitTest(
{
perms: { read: true, write: true },
},
async function openMode(): Promise<void> {
async function openMode() {
const path = (await Deno.makeTempDir()) + "/test_open.txt";
const file = await Deno.open(path, {
write: true,
@ -204,7 +202,7 @@ unitTest(
{
perms: { read: true, write: true },
},
function openSyncUrl(): void {
function openSyncUrl() {
const tempDir = Deno.makeTempDirSync();
const fileUrl = new URL(
`file://${
@ -230,7 +228,7 @@ unitTest(
{
perms: { read: true, write: true },
},
async function openUrl(): Promise<void> {
async function openUrl() {
const tempDir = await Deno.makeTempDir();
const fileUrl = new URL(
`file://${
@ -254,7 +252,7 @@ unitTest(
unitTest(
{ perms: { write: false } },
async function writePermFailure(): Promise<void> {
async function writePermFailure() {
const filename = "tests/hello.txt";
const openOptions: Deno.OpenOptions[] = [{ write: true }, { append: true }];
for (const options of openOptions) {
@ -265,10 +263,10 @@ unitTest(
},
);
unitTest(async function openOptions(): Promise<void> {
unitTest(async function openOptions() {
const filename = "cli/tests/fixture.json";
await assertThrowsAsync(
async (): Promise<void> => {
async () => {
await Deno.open(filename, { write: false });
},
Error,
@ -276,7 +274,7 @@ unitTest(async function openOptions(): Promise<void> {
);
await assertThrowsAsync(
async (): Promise<void> => {
async () => {
await Deno.open(filename, { truncate: true, write: false });
},
Error,
@ -284,7 +282,7 @@ unitTest(async function openOptions(): Promise<void> {
);
await assertThrowsAsync(
async (): Promise<void> => {
async () => {
await Deno.open(filename, { create: true, write: false });
},
Error,
@ -292,7 +290,7 @@ unitTest(async function openOptions(): Promise<void> {
);
await assertThrowsAsync(
async (): Promise<void> => {
async () => {
await Deno.open(filename, { createNew: true, append: false });
},
Error,
@ -300,9 +298,7 @@ unitTest(async function openOptions(): Promise<void> {
);
});
unitTest({ perms: { read: false } }, async function readPermFailure(): Promise<
void
> {
unitTest({ perms: { read: false } }, async function readPermFailure() {
await assertThrowsAsync(async () => {
await Deno.open("package.json", { read: true });
}, Deno.errors.PermissionDenied);
@ -310,7 +306,7 @@ unitTest({ perms: { read: false } }, async function readPermFailure(): Promise<
unitTest(
{ perms: { write: true } },
async function writeNullBufferFailure(): Promise<void> {
async function writeNullBufferFailure() {
const tempDir = Deno.makeTempDirSync();
const filename = tempDir + "hello.txt";
const w = {
@ -322,7 +318,7 @@ unitTest(
// writing null should throw an error
await assertThrowsAsync(
async (): Promise<void> => {
async () => {
// deno-lint-ignore no-explicit-any
await file.write(null as any);
},
@ -334,7 +330,7 @@ unitTest(
unitTest(
{ perms: { write: true, read: true } },
async function readNullBufferFailure(): Promise<void> {
async function readNullBufferFailure() {
const tempDir = Deno.makeTempDirSync();
const filename = tempDir + "hello.txt";
const file = await Deno.open(filename, {
@ -362,7 +358,7 @@ unitTest(
unitTest(
{ perms: { write: false, read: false } },
async function readWritePermFailure(): Promise<void> {
async function readWritePermFailure() {
const filename = "tests/hello.txt";
await assertThrowsAsync(async () => {
await Deno.open(filename, { read: true });
@ -372,7 +368,7 @@ unitTest(
unitTest(
{ perms: { read: true, write: true } },
async function createFile(): Promise<void> {
async function createFile() {
const tempDir = await Deno.makeTempDir();
const filename = tempDir + "/test.txt";
const f = await Deno.create(filename);
@ -393,7 +389,7 @@ unitTest(
unitTest(
{ perms: { read: true, write: true } },
async function createFileWithUrl(): Promise<void> {
async function createFileWithUrl() {
const tempDir = await Deno.makeTempDir();
const fileUrl = new URL(
`file://${Deno.build.os === "windows" ? "/" : ""}${tempDir}/test.txt`,
@ -415,7 +411,7 @@ unitTest(
unitTest(
{ perms: { read: true, write: true } },
async function createSyncFile(): Promise<void> {
async function createSyncFile() {
const tempDir = await Deno.makeTempDir();
const filename = tempDir + "/test.txt";
const f = Deno.createSync(filename);
@ -436,7 +432,7 @@ unitTest(
unitTest(
{ perms: { read: true, write: true } },
async function createSyncFileWithUrl(): Promise<void> {
async function createSyncFileWithUrl() {
const tempDir = await Deno.makeTempDir();
const fileUrl = new URL(
`file://${Deno.build.os === "windows" ? "/" : ""}${tempDir}/test.txt`,
@ -458,7 +454,7 @@ unitTest(
unitTest(
{ perms: { read: true, write: true } },
async function openModeWrite(): Promise<void> {
async function openModeWrite() {
const tempDir = Deno.makeTempDirSync();
const encoder = new TextEncoder();
const filename = tempDir + "hello.txt";
@ -501,7 +497,7 @@ unitTest(
unitTest(
{ perms: { read: true, write: true } },
async function openModeWriteRead(): Promise<void> {
async function openModeWriteRead() {
const tempDir = Deno.makeTempDirSync();
const encoder = new TextEncoder();
const filename = tempDir + "hello.txt";
@ -535,7 +531,7 @@ unitTest(
},
);
unitTest({ perms: { read: true } }, async function seekStart(): Promise<void> {
unitTest({ perms: { read: true } }, async function seekStart() {
const filename = "cli/tests/hello.txt";
const file = await Deno.open(filename);
const seekPosition = 6;
@ -552,7 +548,7 @@ unitTest({ perms: { read: true } }, async function seekStart(): Promise<void> {
file.close();
});
unitTest({ perms: { read: true } }, function seekSyncStart(): void {
unitTest({ perms: { read: true } }, function seekSyncStart() {
const filename = "cli/tests/hello.txt";
const file = Deno.openSync(filename);
const seekPosition = 6;
@ -569,9 +565,7 @@ unitTest({ perms: { read: true } }, function seekSyncStart(): void {
file.close();
});
unitTest({ perms: { read: true } }, async function seekCurrent(): Promise<
void
> {
unitTest({ perms: { read: true } }, async function seekCurrent() {
const filename = "cli/tests/hello.txt";
const file = await Deno.open(filename);
// Deliberately move 1 step forward
@ -588,7 +582,7 @@ unitTest({ perms: { read: true } }, async function seekCurrent(): Promise<
file.close();
});
unitTest({ perms: { read: true } }, function seekSyncCurrent(): void {
unitTest({ perms: { read: true } }, function seekSyncCurrent() {
const filename = "cli/tests/hello.txt";
const file = Deno.openSync(filename);
// Deliberately move 1 step forward
@ -605,7 +599,7 @@ unitTest({ perms: { read: true } }, function seekSyncCurrent(): void {
file.close();
});
unitTest({ perms: { read: true } }, async function seekEnd(): Promise<void> {
unitTest({ perms: { read: true } }, async function seekEnd() {
const filename = "cli/tests/hello.txt";
const file = await Deno.open(filename);
const seekPosition = -6;
@ -619,7 +613,7 @@ unitTest({ perms: { read: true } }, async function seekEnd(): Promise<void> {
file.close();
});
unitTest({ perms: { read: true } }, function seekSyncEnd(): void {
unitTest({ perms: { read: true } }, function seekSyncEnd() {
const filename = "cli/tests/hello.txt";
const file = Deno.openSync(filename);
const seekPosition = -6;
@ -633,11 +627,11 @@ unitTest({ perms: { read: true } }, function seekSyncEnd(): void {
file.close();
});
unitTest({ perms: { read: true } }, async function seekMode(): Promise<void> {
unitTest({ perms: { read: true } }, async function seekMode() {
const filename = "cli/tests/hello.txt";
const file = await Deno.open(filename);
await assertThrowsAsync(
async (): Promise<void> => {
async () => {
await file.seek(1, -1);
},
TypeError,

View file

@ -38,7 +38,7 @@ async function getTwoEvents(
unitTest(
{ perms: { read: true, write: true } },
async function watchFsBasic(): Promise<void> {
async function watchFsBasic() {
const testDir = await Deno.makeTempDir();
const iter = Deno.watchFs(testDir);
@ -65,7 +65,7 @@ unitTest(
// This should be removed at 2.0
unitTest(
{ perms: { read: true, write: true } },
async function watchFsReturn(): Promise<void> {
async function watchFsReturn() {
const testDir = await Deno.makeTempDir();
const iter = Deno.watchFs(testDir);
@ -83,7 +83,7 @@ unitTest(
unitTest(
{ perms: { read: true, write: true } },
async function watchFsClose(): Promise<void> {
async function watchFsClose() {
const testDir = await Deno.makeTempDir();
const iter = Deno.watchFs(testDir);

View file

@ -1,49 +1,49 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assertNotEquals, assertStrictEquals, unitTest } from "./test_util.ts";
unitTest(function getRandomValuesInt8Array(): void {
unitTest(function getRandomValuesInt8Array() {
const arr = new Int8Array(32);
crypto.getRandomValues(arr);
assertNotEquals(arr, new Int8Array(32));
});
unitTest(function getRandomValuesUint8Array(): void {
unitTest(function getRandomValuesUint8Array() {
const arr = new Uint8Array(32);
crypto.getRandomValues(arr);
assertNotEquals(arr, new Uint8Array(32));
});
unitTest(function getRandomValuesUint8ClampedArray(): void {
unitTest(function getRandomValuesUint8ClampedArray() {
const arr = new Uint8ClampedArray(32);
crypto.getRandomValues(arr);
assertNotEquals(arr, new Uint8ClampedArray(32));
});
unitTest(function getRandomValuesInt16Array(): void {
unitTest(function getRandomValuesInt16Array() {
const arr = new Int16Array(4);
crypto.getRandomValues(arr);
assertNotEquals(arr, new Int16Array(4));
});
unitTest(function getRandomValuesUint16Array(): void {
unitTest(function getRandomValuesUint16Array() {
const arr = new Uint16Array(4);
crypto.getRandomValues(arr);
assertNotEquals(arr, new Uint16Array(4));
});
unitTest(function getRandomValuesInt32Array(): void {
unitTest(function getRandomValuesInt32Array() {
const arr = new Int32Array(8);
crypto.getRandomValues(arr);
assertNotEquals(arr, new Int32Array(8));
});
unitTest(function getRandomValuesUint32Array(): void {
unitTest(function getRandomValuesUint32Array() {
const arr = new Uint32Array(8);
crypto.getRandomValues(arr);
assertNotEquals(arr, new Uint32Array(8));
});
unitTest(function getRandomValuesReturnValue(): void {
unitTest(function getRandomValuesReturnValue() {
const arr = new Uint32Array(8);
const rtn = crypto.getRandomValues(arr);
assertNotEquals(arr, new Uint32Array(8));

View file

@ -1,72 +1,72 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assert, unitTest } from "./test_util.ts";
unitTest(function globalThisExists(): void {
unitTest(function globalThisExists() {
assert(globalThis != null);
});
unitTest(function noInternalGlobals(): void {
unitTest(function noInternalGlobals() {
// globalThis.__bootstrap should not be there.
for (const key of Object.keys(globalThis)) {
assert(!key.startsWith("_"));
}
});
unitTest(function windowExists(): void {
unitTest(function windowExists() {
assert(window != null);
});
unitTest(function selfExists(): void {
unitTest(function selfExists() {
assert(self != null);
});
unitTest(function windowWindowExists(): void {
unitTest(function windowWindowExists() {
assert(window.window === window);
});
unitTest(function windowSelfExists(): void {
unitTest(function windowSelfExists() {
assert(window.self === window);
});
unitTest(function globalThisEqualsWindow(): void {
unitTest(function globalThisEqualsWindow() {
assert(globalThis === window);
});
unitTest(function globalThisEqualsSelf(): void {
unitTest(function globalThisEqualsSelf() {
assert(globalThis === self);
});
unitTest(function globalThisInstanceofWindow(): void {
unitTest(function globalThisInstanceofWindow() {
assert(globalThis instanceof Window);
});
unitTest(function globalThisConstructorLength(): void {
unitTest(function globalThisConstructorLength() {
assert(globalThis.constructor.length === 0);
});
unitTest(function globalThisInstanceofEventTarget(): void {
unitTest(function globalThisInstanceofEventTarget() {
assert(globalThis instanceof EventTarget);
});
unitTest(function navigatorInstanceofNavigator(): void {
unitTest(function navigatorInstanceofNavigator() {
// TODO(nayeemrmn): Add `Navigator` to deno_lint globals.
// deno-lint-ignore no-undef
assert(navigator instanceof Navigator);
});
unitTest(function DenoNamespaceExists(): void {
unitTest(function DenoNamespaceExists() {
assert(Deno != null);
});
unitTest(function DenoNamespaceEqualsWindowDeno(): void {
unitTest(function DenoNamespaceEqualsWindowDeno() {
assert(Deno === window.Deno);
});
unitTest(function DenoNamespaceIsNotFrozen(): void {
unitTest(function DenoNamespaceIsNotFrozen() {
assert(!Object.isFrozen(Deno));
});
unitTest(function webAssemblyExists(): void {
unitTest(function webAssemblyExists() {
assert(typeof WebAssembly.compile === "function");
});
@ -84,7 +84,7 @@ unitTest(function DenoNamespaceConfigurable() {
assert(!desc.writable);
});
unitTest(function DenoCoreNamespaceIsImmutable(): void {
unitTest(function DenoCoreNamespaceIsImmutable() {
const { print } = Deno.core;
try {
Deno.core.print = 1;
@ -100,18 +100,18 @@ unitTest(function DenoCoreNamespaceIsImmutable(): void {
assert(print === Deno.core.print);
});
unitTest(async function windowQueueMicrotask(): Promise<void> {
unitTest(async function windowQueueMicrotask() {
let resolve1: () => void | undefined;
let resolve2: () => void | undefined;
let microtaskDone = false;
const p1 = new Promise<void>((res): void => {
resolve1 = (): void => {
const p1 = new Promise<void>((res) => {
resolve1 = () => {
microtaskDone = true;
res();
};
});
const p2 = new Promise<void>((res): void => {
resolve2 = (): void => {
const p2 = new Promise<void>((res) => {
resolve2 = () => {
assert(microtaskDone);
res();
};

View file

@ -5,14 +5,14 @@ const {
// @ts-expect-error TypeScript (as of 3.7) does not support indexing namespaces by symbol
} = Deno[Deno.internal];
unitTest(function headersHasCorrectNameProp(): void {
unitTest(function headersHasCorrectNameProp() {
assertEquals(Headers.name, "Headers");
});
// Logic heavily copied from web-platform-tests, make
// sure pass mostly header basic test
// ref: https://github.com/web-platform-tests/wpt/blob/7c50c216081d6ea3c9afe553ee7b64534020a1b2/fetch/api/headers/headers-basic.html
unitTest(function newHeaderTest(): void {
unitTest(function newHeaderTest() {
new Headers();
new Headers(undefined);
new Headers({});
@ -38,7 +38,7 @@ for (const name in headerDict) {
headerSeq.push([name, headerDict[name]]);
}
unitTest(function newHeaderWithSequence(): void {
unitTest(function newHeaderWithSequence() {
const headers = new Headers(headerSeq);
for (const name in headerDict) {
assertEquals(headers.get(name), String(headerDict[name]));
@ -46,14 +46,14 @@ unitTest(function newHeaderWithSequence(): void {
assertEquals(headers.get("length"), null);
});
unitTest(function newHeaderWithRecord(): void {
unitTest(function newHeaderWithRecord() {
const headers = new Headers(headerDict);
for (const name in headerDict) {
assertEquals(headers.get(name), String(headerDict[name]));
}
});
unitTest(function newHeaderWithHeadersInstance(): void {
unitTest(function newHeaderWithHeadersInstance() {
const headers = new Headers(headerDict);
const headers2 = new Headers(headers);
for (const name in headerDict) {
@ -61,7 +61,7 @@ unitTest(function newHeaderWithHeadersInstance(): void {
}
});
unitTest(function headerAppendSuccess(): void {
unitTest(function headerAppendSuccess() {
const headers = new Headers();
for (const name in headerDict) {
headers.append(name, headerDict[name]);
@ -69,7 +69,7 @@ unitTest(function headerAppendSuccess(): void {
}
});
unitTest(function headerSetSuccess(): void {
unitTest(function headerSetSuccess() {
const headers = new Headers();
for (const name in headerDict) {
headers.set(name, headerDict[name]);
@ -77,7 +77,7 @@ unitTest(function headerSetSuccess(): void {
}
});
unitTest(function headerHasSuccess(): void {
unitTest(function headerHasSuccess() {
const headers = new Headers(headerDict);
for (const name in headerDict) {
assert(headers.has(name), "headers has name " + name);
@ -88,7 +88,7 @@ unitTest(function headerHasSuccess(): void {
}
});
unitTest(function headerDeleteSuccess(): void {
unitTest(function headerDeleteSuccess() {
const headers = new Headers(headerDict);
for (const name in headerDict) {
assert(headers.has(name), "headers have a header: " + name);
@ -97,7 +97,7 @@ unitTest(function headerDeleteSuccess(): void {
}
});
unitTest(function headerGetSuccess(): void {
unitTest(function headerGetSuccess() {
const headers = new Headers(headerDict);
for (const name in headerDict) {
assertEquals(headers.get(name), String(headerDict[name]));
@ -105,7 +105,7 @@ unitTest(function headerGetSuccess(): void {
}
});
unitTest(function headerEntriesSuccess(): void {
unitTest(function headerEntriesSuccess() {
const headers = new Headers(headerDict);
const iterators = headers.entries();
for (const it of iterators) {
@ -116,7 +116,7 @@ unitTest(function headerEntriesSuccess(): void {
}
});
unitTest(function headerKeysSuccess(): void {
unitTest(function headerKeysSuccess() {
const headers = new Headers(headerDict);
const iterators = headers.keys();
for (const it of iterators) {
@ -124,7 +124,7 @@ unitTest(function headerKeysSuccess(): void {
}
});
unitTest(function headerValuesSuccess(): void {
unitTest(function headerValuesSuccess() {
const headers = new Headers(headerDict);
const iterators = headers.values();
const entries = headers.entries();
@ -146,16 +146,16 @@ const headerEntriesDict: Record<string, string> = {
"Content-Types": "value6",
};
unitTest(function headerForEachSuccess(): void {
unitTest(function headerForEachSuccess() {
const headers = new Headers(headerEntriesDict);
const keys = Object.keys(headerEntriesDict);
keys.forEach((key): void => {
keys.forEach((key) => {
const value = headerEntriesDict[key];
const newkey = key.toLowerCase();
headerEntriesDict[newkey] = value;
});
let callNum = 0;
headers.forEach((value, key, container): void => {
headers.forEach((value, key, container) => {
assertEquals(headers, container);
assertEquals(value, headerEntriesDict[key]);
callNum++;
@ -163,7 +163,7 @@ unitTest(function headerForEachSuccess(): void {
assertEquals(callNum, keys.length);
});
unitTest(function headerSymbolIteratorSuccess(): void {
unitTest(function headerSymbolIteratorSuccess() {
assert(Symbol.iterator in Headers.prototype);
const headers = new Headers(headerEntriesDict);
for (const header of headers) {
@ -174,7 +174,7 @@ unitTest(function headerSymbolIteratorSuccess(): void {
}
});
unitTest(function headerTypesAvailable(): void {
unitTest(function headerTypesAvailable() {
function newHeaders(): Headers {
return new Headers();
}
@ -184,7 +184,7 @@ unitTest(function headerTypesAvailable(): void {
// Modified from https://github.com/bitinn/node-fetch/blob/7d3293200a91ad52b5ca7962f9d6fd1c04983edb/test/test.js#L2001-L2014
// Copyright (c) 2016 David Frank. MIT License.
unitTest(function headerIllegalReject(): void {
unitTest(function headerIllegalReject() {
let errorCount = 0;
try {
new Headers({ "He y": "ok" });
@ -238,7 +238,7 @@ unitTest(function headerIllegalReject(): void {
});
// If pair does not contain exactly two items,then throw a TypeError.
unitTest(function headerParamsShouldThrowTypeError(): void {
unitTest(function headerParamsShouldThrowTypeError() {
let hasThrown = 0;
try {
@ -255,12 +255,12 @@ unitTest(function headerParamsShouldThrowTypeError(): void {
assertEquals(hasThrown, 2);
});
unitTest(function headerParamsArgumentsCheck(): void {
unitTest(function headerParamsArgumentsCheck() {
const methodRequireOneParam = ["delete", "get", "has", "forEach"] as const;
const methodRequireTwoParams = ["append", "set"] as const;
methodRequireOneParam.forEach((method): void => {
methodRequireOneParam.forEach((method) => {
const headers = new Headers();
let hasThrown = 0;
try {
@ -277,7 +277,7 @@ unitTest(function headerParamsArgumentsCheck(): void {
assertEquals(hasThrown, 2);
});
methodRequireTwoParams.forEach((method): void => {
methodRequireTwoParams.forEach((method) => {
const headers = new Headers();
let hasThrown = 0;
@ -310,7 +310,7 @@ unitTest(function headerParamsArgumentsCheck(): void {
});
});
unitTest(function headersInitMultiple(): void {
unitTest(function headersInitMultiple() {
const headers = new Headers([
["Set-Cookie", "foo=bar"],
["Set-Cookie", "bar=baz"],
@ -325,7 +325,7 @@ unitTest(function headersInitMultiple(): void {
]);
});
unitTest(function headersAppendMultiple(): void {
unitTest(function headersAppendMultiple() {
const headers = new Headers([
["Set-Cookie", "foo=bar"],
["X-Deno", "foo"],
@ -340,7 +340,7 @@ unitTest(function headersAppendMultiple(): void {
]);
});
unitTest(function headersAppendDuplicateSetCookieKey(): void {
unitTest(function headersAppendDuplicateSetCookieKey() {
const headers = new Headers([["Set-Cookie", "foo=bar"]]);
headers.append("set-Cookie", "foo=baz");
headers.append("Set-cookie", "baz=bar");
@ -352,7 +352,7 @@ unitTest(function headersAppendDuplicateSetCookieKey(): void {
]);
});
unitTest(function headersGetSetCookie(): void {
unitTest(function headersGetSetCookie() {
const headers = new Headers([
["Set-Cookie", "foo=bar"],
["set-Cookie", "bar=qat"],
@ -360,7 +360,7 @@ unitTest(function headersGetSetCookie(): void {
assertEquals(headers.get("SET-COOKIE"), "foo=bar, bar=qat");
});
unitTest(function toStringShouldBeWebCompatibility(): void {
unitTest(function toStringShouldBeWebCompatibility() {
const headers = new Headers();
assertEquals(headers.toString(), "[object Headers]");
});
@ -369,7 +369,7 @@ function stringify(...args: unknown[]): string {
return inspectArgs(args).replace(/\n$/, "");
}
unitTest(function customInspectReturnsCorrectHeadersFormat(): void {
unitTest(function customInspectReturnsCorrectHeadersFormat() {
const blankHeaders = new Headers();
assertEquals(stringify(blankHeaders), "Headers {}");
const singleHeader = new Headers([["Content-Type", "application/json"]]);

View file

@ -200,7 +200,7 @@ unitTest({ perms: { net: true } }, async function httpServerInvalidMethod() {
unitTest(
{ perms: { read: true, net: true } },
async function httpServerWithTls(): Promise<void> {
async function httpServerWithTls() {
const hostname = "localhost";
const port = 4501;

View file

@ -1,7 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assert, unitTest } from "./test_util.ts";
unitTest(function internalsExists(): void {
unitTest(function internalsExists() {
const {
inspectArgs,
// @ts-expect-error TypeScript (as of 3.7) does not support indexing namespaces by symbol

View file

@ -3,7 +3,7 @@ import { assert, assertEquals, assertThrows, unitTest } from "./test_util.ts";
unitTest(
{ perms: { read: true, write: true } },
function linkSyncSuccess(): void {
function linkSyncSuccess() {
const testDir = Deno.makeTempDirSync();
const oldData = "Hardlink";
const oldName = testDir + "/oldname";
@ -42,7 +42,7 @@ unitTest(
unitTest(
{ perms: { read: true, write: true } },
function linkSyncExists(): void {
function linkSyncExists() {
const testDir = Deno.makeTempDirSync();
const oldName = testDir + "/oldname";
const newName = testDir + "/newname";
@ -58,7 +58,7 @@ unitTest(
unitTest(
{ perms: { read: true, write: true } },
function linkSyncNotFound(): void {
function linkSyncNotFound() {
const testDir = Deno.makeTempDirSync();
const oldName = testDir + "/oldname";
const newName = testDir + "/newname";
@ -71,7 +71,7 @@ unitTest(
unitTest(
{ perms: { read: false, write: true } },
function linkSyncReadPerm(): void {
function linkSyncReadPerm() {
assertThrows(() => {
Deno.linkSync("oldbaddir", "newbaddir");
}, Deno.errors.PermissionDenied);
@ -80,7 +80,7 @@ unitTest(
unitTest(
{ perms: { read: true, write: false } },
function linkSyncWritePerm(): void {
function linkSyncWritePerm() {
assertThrows(() => {
Deno.linkSync("oldbaddir", "newbaddir");
}, Deno.errors.PermissionDenied);
@ -89,7 +89,7 @@ unitTest(
unitTest(
{ perms: { read: true, write: true } },
async function linkSuccess(): Promise<void> {
async function linkSuccess() {
const testDir = Deno.makeTempDirSync();
const oldData = "Hardlink";
const oldName = testDir + "/oldname";

View file

@ -7,7 +7,7 @@ import {
unitTest,
} from "./test_util.ts";
unitTest({ perms: { write: true } }, function makeTempDirSyncSuccess(): void {
unitTest({ perms: { write: true } }, function makeTempDirSyncSuccess() {
const dir1 = Deno.makeTempDirSync({ prefix: "hello", suffix: "world" });
const dir2 = Deno.makeTempDirSync({ prefix: "hello", suffix: "world" });
// Check that both dirs are different.
@ -30,7 +30,7 @@ unitTest({ perms: { write: true } }, function makeTempDirSyncSuccess(): void {
unitTest(
{ perms: { read: true, write: true } },
function makeTempDirSyncMode(): void {
function makeTempDirSyncMode() {
const path = Deno.makeTempDirSync();
const pathInfo = Deno.statSync(path);
if (Deno.build.os !== "windows") {
@ -39,7 +39,7 @@ unitTest(
},
);
unitTest(function makeTempDirSyncPerm(): void {
unitTest(function makeTempDirSyncPerm() {
// makeTempDirSync should require write permissions (for now).
assertThrows(() => {
Deno.makeTempDirSync({ dir: "/baddir" });
@ -48,7 +48,7 @@ unitTest(function makeTempDirSyncPerm(): void {
unitTest(
{ perms: { write: true } },
async function makeTempDirSuccess(): Promise<void> {
async function makeTempDirSuccess() {
const dir1 = await Deno.makeTempDir({ prefix: "hello", suffix: "world" });
const dir2 = await Deno.makeTempDir({ prefix: "hello", suffix: "world" });
// Check that both dirs are different.
@ -72,7 +72,7 @@ unitTest(
unitTest(
{ perms: { read: true, write: true } },
async function makeTempDirMode(): Promise<void> {
async function makeTempDirMode() {
const path = await Deno.makeTempDir();
const pathInfo = Deno.statSync(path);
if (Deno.build.os !== "windows") {
@ -81,7 +81,7 @@ unitTest(
},
);
unitTest({ perms: { write: true } }, function makeTempFileSyncSuccess(): void {
unitTest({ perms: { write: true } }, function makeTempFileSyncSuccess() {
const file1 = Deno.makeTempFileSync({ prefix: "hello", suffix: "world" });
const file2 = Deno.makeTempFileSync({ prefix: "hello", suffix: "world" });
// Check that both dirs are different.
@ -105,7 +105,7 @@ unitTest({ perms: { write: true } }, function makeTempFileSyncSuccess(): void {
unitTest(
{ perms: { read: true, write: true } },
function makeTempFileSyncMode(): void {
function makeTempFileSyncMode() {
const path = Deno.makeTempFileSync();
const pathInfo = Deno.statSync(path);
if (Deno.build.os !== "windows") {
@ -114,7 +114,7 @@ unitTest(
},
);
unitTest(function makeTempFileSyncPerm(): void {
unitTest(function makeTempFileSyncPerm() {
// makeTempFileSync should require write permissions (for now).
assertThrows(() => {
Deno.makeTempFileSync({ dir: "/baddir" });
@ -123,7 +123,7 @@ unitTest(function makeTempFileSyncPerm(): void {
unitTest(
{ perms: { write: true } },
async function makeTempFileSuccess(): Promise<void> {
async function makeTempFileSuccess() {
const file1 = await Deno.makeTempFile({ prefix: "hello", suffix: "world" });
const file2 = await Deno.makeTempFile({ prefix: "hello", suffix: "world" });
// Check that both dirs are different.
@ -148,7 +148,7 @@ unitTest(
unitTest(
{ perms: { read: true, write: true } },
async function makeTempFileMode(): Promise<void> {
async function makeTempFileMode() {
const path = await Deno.makeTempFile();
const pathInfo = Deno.statSync(path);
if (Deno.build.os !== "windows") {

View file

@ -1,7 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assert, unitTest } from "./test_util.ts";
unitTest(async function metrics(): Promise<void> {
unitTest(async function metrics() {
// Write to stdout to ensure a "data" message gets sent instead of just
// control messages.
const dataMsg = new Uint8Array([13, 13, 13]); // "\r\r\r",
@ -41,7 +41,7 @@ unitTest(async function metrics(): Promise<void> {
unitTest(
{ perms: { write: true } },
function metricsUpdatedIfNoResponseSync(): void {
function metricsUpdatedIfNoResponseSync() {
const filename = Deno.makeTempDirSync() + "/test.txt";
const data = new Uint8Array([41, 42, 43]);
@ -55,7 +55,7 @@ unitTest(
unitTest(
{ perms: { write: true } },
async function metricsUpdatedIfNoResponseAsync(): Promise<void> {
async function metricsUpdatedIfNoResponseAsync() {
const filename = Deno.makeTempDirSync() + "/test.txt";
const data = new Uint8Array([41, 42, 43]);
@ -69,7 +69,7 @@ unitTest(
);
// Test that ops from extensions have metrics (via OpMiddleware)
unitTest(function metricsForOpCrates(): void {
unitTest(function metricsForOpCrates() {
const _ = new URL("https://deno.land");
const m1 = Deno.metrics().ops["op_url_parse"];

View file

@ -8,7 +8,7 @@ import {
unitTest,
} from "./test_util.ts";
function assertDirectory(path: string, mode?: number): void {
function assertDirectory(path: string, mode?: number) {
const info = Deno.lstatSync(path);
assert(info.isDirectory);
if (Deno.build.os !== "windows" && mode !== undefined) {
@ -18,7 +18,7 @@ function assertDirectory(path: string, mode?: number): void {
unitTest(
{ perms: { read: true, write: true } },
function mkdirSyncSuccess(): void {
function mkdirSyncSuccess() {
const path = Deno.makeTempDirSync() + "/dir";
Deno.mkdirSync(path);
assertDirectory(path);
@ -27,14 +27,14 @@ unitTest(
unitTest(
{ perms: { read: true, write: true } },
function mkdirSyncMode(): void {
function mkdirSyncMode() {
const path = Deno.makeTempDirSync() + "/dir";
Deno.mkdirSync(path, { mode: 0o737 });
assertDirectory(path, 0o737);
},
);
unitTest({ perms: { write: false } }, function mkdirSyncPerm(): void {
unitTest({ perms: { write: false } }, function mkdirSyncPerm() {
assertThrows(() => {
Deno.mkdirSync("/baddir");
}, Deno.errors.PermissionDenied);
@ -42,7 +42,7 @@ unitTest({ perms: { write: false } }, function mkdirSyncPerm(): void {
unitTest(
{ perms: { read: true, write: true } },
async function mkdirSuccess(): Promise<void> {
async function mkdirSuccess() {
const path = Deno.makeTempDirSync() + "/dir";
await Deno.mkdir(path);
assertDirectory(path);
@ -51,22 +51,20 @@ unitTest(
unitTest(
{ perms: { read: true, write: true } },
async function mkdirMode(): Promise<void> {
async function mkdirMode() {
const path = Deno.makeTempDirSync() + "/dir";
await Deno.mkdir(path, { mode: 0o737 });
assertDirectory(path, 0o737);
},
);
unitTest({ perms: { write: true } }, function mkdirErrSyncIfExists(): void {
unitTest({ perms: { write: true } }, function mkdirErrSyncIfExists() {
assertThrows(() => {
Deno.mkdirSync(".");
}, Deno.errors.AlreadyExists);
});
unitTest({ perms: { write: true } }, async function mkdirErrIfExists(): Promise<
void
> {
unitTest({ perms: { write: true } }, async function mkdirErrIfExists() {
await assertThrowsAsync(async () => {
await Deno.mkdir(".");
}, Deno.errors.AlreadyExists);
@ -74,7 +72,7 @@ unitTest({ perms: { write: true } }, async function mkdirErrIfExists(): Promise<
unitTest(
{ perms: { read: true, write: true } },
function mkdirSyncRecursive(): void {
function mkdirSyncRecursive() {
const path = Deno.makeTempDirSync() + "/nested/directory";
Deno.mkdirSync(path, { recursive: true });
assertDirectory(path);
@ -83,7 +81,7 @@ unitTest(
unitTest(
{ perms: { read: true, write: true } },
async function mkdirRecursive(): Promise<void> {
async function mkdirRecursive() {
const path = Deno.makeTempDirSync() + "/nested/directory";
await Deno.mkdir(path, { recursive: true });
assertDirectory(path);
@ -92,7 +90,7 @@ unitTest(
unitTest(
{ perms: { read: true, write: true } },
function mkdirSyncRecursiveMode(): void {
function mkdirSyncRecursiveMode() {
const nested = Deno.makeTempDirSync() + "/nested";
const path = nested + "/dir";
Deno.mkdirSync(path, { mode: 0o737, recursive: true });
@ -103,7 +101,7 @@ unitTest(
unitTest(
{ perms: { read: true, write: true } },
async function mkdirRecursiveMode(): Promise<void> {
async function mkdirRecursiveMode() {
const nested = Deno.makeTempDirSync() + "/nested";
const path = nested + "/dir";
await Deno.mkdir(path, { mode: 0o737, recursive: true });
@ -114,7 +112,7 @@ unitTest(
unitTest(
{ perms: { read: true, write: true } },
function mkdirSyncRecursiveIfExists(): void {
function mkdirSyncRecursiveIfExists() {
const path = Deno.makeTempDirSync() + "/dir";
Deno.mkdirSync(path, { mode: 0o737 });
Deno.mkdirSync(path, { recursive: true });
@ -132,7 +130,7 @@ unitTest(
unitTest(
{ perms: { read: true, write: true } },
async function mkdirRecursiveIfExists(): Promise<void> {
async function mkdirRecursiveIfExists() {
const path = Deno.makeTempDirSync() + "/dir";
await Deno.mkdir(path, { mode: 0o737 });
await Deno.mkdir(path, { recursive: true });
@ -150,7 +148,7 @@ unitTest(
unitTest(
{ perms: { read: true, write: true } },
function mkdirSyncErrors(): void {
function mkdirSyncErrors() {
const testDir = Deno.makeTempDirSync();
const emptydir = testDir + "/empty";
const fulldir = testDir + "/dir";
@ -159,16 +157,16 @@ unitTest(
Deno.mkdirSync(fulldir);
Deno.createSync(file).close();
assertThrows((): void => {
assertThrows(() => {
Deno.mkdirSync(emptydir, { recursive: false });
}, Deno.errors.AlreadyExists);
assertThrows((): void => {
assertThrows(() => {
Deno.mkdirSync(fulldir, { recursive: false });
}, Deno.errors.AlreadyExists);
assertThrows((): void => {
assertThrows(() => {
Deno.mkdirSync(file, { recursive: false });
}, Deno.errors.AlreadyExists);
assertThrows((): void => {
assertThrows(() => {
Deno.mkdirSync(file, { recursive: true });
}, Deno.errors.AlreadyExists);
@ -180,19 +178,19 @@ unitTest(
Deno.symlinkSync(emptydir, dirLink);
Deno.symlinkSync(testDir + "/nonexistent", danglingLink);
assertThrows((): void => {
assertThrows(() => {
Deno.mkdirSync(dirLink, { recursive: false });
}, Deno.errors.AlreadyExists);
assertThrows((): void => {
assertThrows(() => {
Deno.mkdirSync(fileLink, { recursive: false });
}, Deno.errors.AlreadyExists);
assertThrows((): void => {
assertThrows(() => {
Deno.mkdirSync(fileLink, { recursive: true });
}, Deno.errors.AlreadyExists);
assertThrows((): void => {
assertThrows(() => {
Deno.mkdirSync(danglingLink, { recursive: false });
}, Deno.errors.AlreadyExists);
assertThrows((): void => {
assertThrows(() => {
Deno.mkdirSync(danglingLink, { recursive: true });
}, Deno.errors.AlreadyExists);
}
@ -201,7 +199,7 @@ unitTest(
unitTest(
{ perms: { read: true, write: true } },
function mkdirSyncRelativeUrlPath(): void {
function mkdirSyncRelativeUrlPath() {
const testDir = Deno.makeTempDirSync();
const nestedDir = testDir + "/nested";
// Add trailing slash so base path is treated as a directory. pathToAbsoluteFileUrl removes trailing slashes.
@ -216,7 +214,7 @@ unitTest(
unitTest(
{ perms: { read: true, write: true } },
async function mkdirRelativeUrlPath(): Promise<void> {
async function mkdirRelativeUrlPath() {
const testDir = Deno.makeTempDirSync();
const nestedDir = testDir + "/nested";
// Add trailing slash so base path is treated as a directory. pathToAbsoluteFileUrl removes trailing slashes.

View file

@ -1,6 +1,6 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assert, unitTest } from "./test_util.ts";
unitTest(function navigatorNumCpus(): void {
unitTest(function navigatorNumCpus() {
assert(navigator.hardwareConcurrency > 0);
});

View file

@ -10,7 +10,7 @@ import {
unitTest,
} from "./test_util.ts";
unitTest({ perms: { net: true } }, function netTcpListenClose(): void {
unitTest({ perms: { net: true } }, function netTcpListenClose() {
const listener = Deno.listen({ hostname: "127.0.0.1", port: 3500 });
assert(listener.addr.transport === "tcp");
assertEquals(listener.addr.hostname, "127.0.0.1");
@ -23,7 +23,7 @@ unitTest(
{
perms: { net: true },
},
function netUdpListenClose(): void {
function netUdpListenClose() {
const socket = Deno.listenDatagram({
hostname: "127.0.0.1",
port: 3500,
@ -38,7 +38,7 @@ unitTest(
unitTest(
{ ignore: Deno.build.os === "windows", perms: { read: true, write: true } },
function netUnixListenClose(): void {
function netUnixListenClose() {
const filePath = Deno.makeTempFileSync();
const socket = Deno.listen({
path: filePath,
@ -52,7 +52,7 @@ unitTest(
unitTest(
{ ignore: Deno.build.os === "windows", perms: { read: true, write: true } },
function netUnixPacketListenClose(): void {
function netUnixPacketListenClose() {
const filePath = Deno.makeTempFileSync();
const socket = Deno.listenDatagram({
path: filePath,
@ -66,7 +66,7 @@ unitTest(
unitTest(
{ ignore: Deno.build.os === "windows", perms: { read: true } },
function netUnixListenWritePermission(): void {
function netUnixListenWritePermission() {
assertThrows(() => {
const filePath = Deno.makeTempFileSync();
const socket = Deno.listen({
@ -82,7 +82,7 @@ unitTest(
unitTest(
{ ignore: Deno.build.os === "windows", perms: { read: true } },
function netUnixPacketListenWritePermission(): void {
function netUnixPacketListenWritePermission() {
assertThrows(() => {
const filePath = Deno.makeTempFileSync();
const socket = Deno.listenDatagram({
@ -100,12 +100,12 @@ unitTest(
{
perms: { net: true },
},
async function netTcpCloseWhileAccept(): Promise<void> {
async function netTcpCloseWhileAccept() {
const listener = Deno.listen({ port: 4501 });
const p = listener.accept();
listener.close();
await assertThrowsAsync(
async (): Promise<void> => {
async () => {
await p;
},
Deno.errors.BadResource,
@ -116,7 +116,7 @@ unitTest(
unitTest(
{ ignore: Deno.build.os === "windows", perms: { read: true, write: true } },
async function netUnixCloseWhileAccept(): Promise<void> {
async function netUnixCloseWhileAccept() {
const filePath = await Deno.makeTempFile();
const listener = Deno.listen({
path: filePath,
@ -125,7 +125,7 @@ unitTest(
const p = listener.accept();
listener.close();
await assertThrowsAsync(
async (): Promise<void> => {
async () => {
await p;
},
Deno.errors.BadResource,
@ -136,10 +136,10 @@ unitTest(
unitTest(
{ perms: { net: true } },
async function netTcpConcurrentAccept(): Promise<void> {
async function netTcpConcurrentAccept() {
const listener = Deno.listen({ port: 4502 });
let acceptErrCount = 0;
const checkErr = (e: Error): void => {
const checkErr = (e: Error) => {
if (e.message === "Listener has been closed") {
assertEquals(acceptErrCount, 1);
} else if (e.message === "Another accept task is ongoing") {
@ -160,11 +160,11 @@ unitTest(
// TODO(jsouto): Enable when tokio updates mio to v0.7!
unitTest(
{ ignore: true, perms: { read: true, write: true } },
async function netUnixConcurrentAccept(): Promise<void> {
async function netUnixConcurrentAccept() {
const filePath = await Deno.makeTempFile();
const listener = Deno.listen({ transport: "unix", path: filePath });
let acceptErrCount = 0;
const checkErr = (e: Error): void => {
const checkErr = (e: Error) => {
if (e.message === "Listener has been closed") {
assertEquals(acceptErrCount, 1);
} else if (e.message === "Another accept task is ongoing") {
@ -182,12 +182,10 @@ unitTest(
},
);
unitTest({ perms: { net: true } }, async function netTcpDialListen(): Promise<
void
> {
unitTest({ perms: { net: true } }, async function netTcpDialListen() {
const listener = Deno.listen({ port: 3500 });
listener.accept().then(
async (conn): Promise<void> => {
async (conn) => {
assert(conn.remoteAddr != null);
assert(conn.localAddr.transport === "tcp");
assertEquals(conn.localAddr.hostname, "127.0.0.1");
@ -221,11 +219,11 @@ unitTest({ perms: { net: true } }, async function netTcpDialListen(): Promise<
unitTest(
{ ignore: Deno.build.os === "windows", perms: { read: true, write: true } },
async function netUnixDialListen(): Promise<void> {
async function netUnixDialListen() {
const filePath = await Deno.makeTempFile();
const listener = Deno.listen({ path: filePath, transport: "unix" });
listener.accept().then(
async (conn): Promise<void> => {
async (conn) => {
assert(conn.remoteAddr != null);
assert(conn.localAddr.transport === "unix");
assertEquals(conn.localAddr.path, filePath);
@ -257,7 +255,7 @@ unitTest(
unitTest(
{ perms: { net: true } },
async function netUdpSendReceive(): Promise<void> {
async function netUdpSendReceive() {
const alice = Deno.listenDatagram({ port: 3500, transport: "udp" });
assert(alice.addr.transport === "udp");
assertEquals(alice.addr.port, 3500);
@ -287,7 +285,7 @@ unitTest(
unitTest(
{ perms: { net: true } },
async function netUdpConcurrentSendReceive(): Promise<void> {
async function netUdpConcurrentSendReceive() {
const socket = Deno.listenDatagram({ port: 3500, transport: "udp" });
assert(socket.addr.transport === "udp");
assertEquals(socket.addr.port, 3500);
@ -311,7 +309,7 @@ unitTest(
unitTest(
{ perms: { net: true } },
async function netUdpBorrowMutError(): Promise<void> {
async function netUdpBorrowMutError() {
const socket = Deno.listenDatagram({
port: 4501,
transport: "udp",
@ -326,7 +324,7 @@ unitTest(
unitTest(
{ ignore: Deno.build.os === "windows", perms: { read: true, write: true } },
async function netUnixPacketSendReceive(): Promise<void> {
async function netUnixPacketSendReceive() {
const filePath = await Deno.makeTempFile();
const alice = Deno.listenDatagram({
path: filePath,
@ -361,7 +359,7 @@ unitTest(
// TODO(piscisaureus): Enable after Tokio v0.3/v1.0 upgrade.
unitTest(
{ ignore: true, perms: { read: true, write: true } },
async function netUnixPacketConcurrentSendReceive(): Promise<void> {
async function netUnixPacketConcurrentSendReceive() {
const filePath = await Deno.makeTempFile();
const socket = Deno.listenDatagram({
path: filePath,
@ -388,10 +386,10 @@ unitTest(
unitTest(
{ perms: { net: true } },
async function netTcpListenIteratorBreakClosesResource(): Promise<void> {
async function netTcpListenIteratorBreakClosesResource() {
const promise = deferred();
async function iterate(listener: Deno.Listener): Promise<void> {
async function iterate(listener: Deno.Listener) {
let i = 0;
for await (const conn of listener) {
@ -422,7 +420,7 @@ unitTest(
unitTest(
{ perms: { net: true } },
async function netTcpListenCloseWhileIterating(): Promise<void> {
async function netTcpListenCloseWhileIterating() {
const listener = Deno.listen({ port: 8001 });
const nextWhileClosing = listener[Symbol.asyncIterator]().next();
listener.close();
@ -435,7 +433,7 @@ unitTest(
unitTest(
{ perms: { net: true } },
async function netUdpListenCloseWhileIterating(): Promise<void> {
async function netUdpListenCloseWhileIterating() {
const socket = Deno.listenDatagram({ port: 8000, transport: "udp" });
const nextWhileClosing = socket[Symbol.asyncIterator]().next();
socket.close();
@ -448,7 +446,7 @@ unitTest(
unitTest(
{ ignore: Deno.build.os === "windows", perms: { read: true, write: true } },
async function netUnixListenCloseWhileIterating(): Promise<void> {
async function netUnixListenCloseWhileIterating() {
const filePath = Deno.makeTempFileSync();
const socket = Deno.listen({ path: filePath, transport: "unix" });
const nextWhileClosing = socket[Symbol.asyncIterator]().next();
@ -462,7 +460,7 @@ unitTest(
unitTest(
{ ignore: Deno.build.os === "windows", perms: { read: true, write: true } },
async function netUnixPacketListenCloseWhileIterating(): Promise<void> {
async function netUnixPacketListenCloseWhileIterating() {
const filePath = Deno.makeTempFileSync();
const socket = Deno.listenDatagram({
path: filePath,
@ -483,10 +481,10 @@ unitTest(
ignore: true,
perms: { net: true },
},
async function netListenAsyncIterator(): Promise<void> {
async function netListenAsyncIterator() {
const addr = { hostname: "127.0.0.1", port: 3500 };
const listener = Deno.listen(addr);
const runAsyncIterator = async (): Promise<void> => {
const runAsyncIterator = async () => {
for await (const conn of listener) {
await conn.write(new Uint8Array([1, 2, 3]));
conn.close();
@ -552,7 +550,7 @@ unitTest(
async function netHangsOnClose() {
let acceptedConn: Deno.Conn;
async function iteratorReq(listener: Deno.Listener): Promise<void> {
async function iteratorReq(listener: Deno.Listener) {
const p = new Uint8Array(10);
const conn = await listener.accept();
acceptedConn = conn;

View file

@ -21,7 +21,7 @@ declare global {
}
}
unitTest(async function opsAsyncBadResource(): Promise<void> {
unitTest(async function opsAsyncBadResource() {
try {
const nonExistingRid = 9999;
await Deno.core.opAsync(
@ -36,7 +36,7 @@ unitTest(async function opsAsyncBadResource(): Promise<void> {
}
});
unitTest(function opsSyncBadResource(): void {
unitTest(function opsSyncBadResource() {
try {
const nonExistingRid = 9999;
Deno.core.opSync("op_read_sync", nonExistingRid, new Uint8Array(0));

View file

@ -7,7 +7,7 @@ import {
unitTest,
} from "./test_util.ts";
unitTest({ perms: { env: true } }, function envSuccess(): void {
unitTest({ perms: { env: true } }, function envSuccess() {
Deno.env.set("TEST_VAR", "A");
const env = Deno.env.toObject();
Deno.env.set("TEST_VAR", "B");
@ -15,19 +15,19 @@ unitTest({ perms: { env: true } }, function envSuccess(): void {
assertNotEquals(Deno.env.get("TEST_VAR"), env["TEST_VAR"]);
});
unitTest({ perms: { env: true } }, function envNotFound(): void {
unitTest({ perms: { env: true } }, function envNotFound() {
const r = Deno.env.get("env_var_does_not_exist!");
assertEquals(r, undefined);
});
unitTest({ perms: { env: true } }, function deleteEnv(): void {
unitTest({ perms: { env: true } }, function deleteEnv() {
Deno.env.set("TEST_VAR", "A");
assertEquals(Deno.env.get("TEST_VAR"), "A");
assertEquals(Deno.env.delete("TEST_VAR"), undefined);
assertEquals(Deno.env.get("TEST_VAR"), undefined);
});
unitTest({ perms: { env: true } }, function avoidEmptyNamedEnv(): void {
unitTest({ perms: { env: true } }, function avoidEmptyNamedEnv() {
assertThrows(() => Deno.env.set("", "v"), TypeError);
assertThrows(() => Deno.env.set("a=a", "v"), TypeError);
assertThrows(() => Deno.env.set("a\0a", "v"), TypeError);
@ -42,13 +42,13 @@ unitTest({ perms: { env: true } }, function avoidEmptyNamedEnv(): void {
assertThrows(() => Deno.env.delete("a\0a"), TypeError);
});
unitTest(function envPermissionDenied1(): void {
unitTest(function envPermissionDenied1() {
assertThrows(() => {
Deno.env.toObject();
}, Deno.errors.PermissionDenied);
});
unitTest(function envPermissionDenied2(): void {
unitTest(function envPermissionDenied2() {
assertThrows(() => {
Deno.env.get("PATH");
}, Deno.errors.PermissionDenied);
@ -70,7 +70,7 @@ unitTest(
const checkChildEnv = async (
inputEnv: Record<string, string>,
expectedEnv: Record<string, string>,
): Promise<void> => {
) => {
const src = `
console.log(
${JSON.stringify(Object.keys(expectedEnv))}.map(k => Deno.env.get(k))
@ -122,17 +122,17 @@ unitTest(
},
);
unitTest(function osPid(): void {
unitTest(function osPid() {
assert(Deno.pid > 0);
});
unitTest(function osPpid(): void {
unitTest(function osPpid() {
assert(Deno.ppid > 0);
});
unitTest(
{ perms: { run: true, read: true } },
async function osPpidIsEqualToPidOfParentProcess(): Promise<void> {
async function osPpidIsEqualToPidOfParentProcess() {
const decoder = new TextDecoder();
const process = Deno.run({
cmd: [Deno.execPath(), "eval", "-p", "--unstable", "Deno.ppid"],
@ -148,11 +148,11 @@ unitTest(
},
);
unitTest({ perms: { read: true } }, function execPath(): void {
unitTest({ perms: { read: true } }, function execPath() {
assertNotEquals(Deno.execPath(), "");
});
unitTest({ perms: { read: false } }, function execPathPerm(): void {
unitTest({ perms: { read: false } }, function execPathPerm() {
assertThrows(
() => {
Deno.execPath();
@ -162,38 +162,38 @@ unitTest({ perms: { read: false } }, function execPathPerm(): void {
);
});
unitTest({ perms: { env: true } }, function loadavgSuccess(): void {
unitTest({ perms: { env: true } }, function loadavgSuccess() {
const load = Deno.loadavg();
assertEquals(load.length, 3);
});
unitTest({ perms: { env: false } }, function loadavgPerm(): void {
unitTest({ perms: { env: false } }, function loadavgPerm() {
assertThrows(() => {
Deno.loadavg();
}, Deno.errors.PermissionDenied);
});
unitTest({ perms: { env: true } }, function hostnameDir(): void {
unitTest({ perms: { env: true } }, function hostnameDir() {
assertNotEquals(Deno.hostname(), "");
});
unitTest({ perms: { env: false } }, function hostnamePerm(): void {
unitTest({ perms: { env: false } }, function hostnamePerm() {
assertThrows(() => {
Deno.hostname();
}, Deno.errors.PermissionDenied);
});
unitTest({ perms: { env: true } }, function releaseDir(): void {
unitTest({ perms: { env: true } }, function releaseDir() {
assertNotEquals(Deno.osRelease(), "");
});
unitTest({ perms: { env: false } }, function releasePerm(): void {
unitTest({ perms: { env: false } }, function releasePerm() {
assertThrows(() => {
Deno.osRelease();
}, Deno.errors.PermissionDenied);
});
unitTest({ perms: { env: true } }, function systemMemoryInfo(): void {
unitTest({ perms: { env: true } }, function systemMemoryInfo() {
const info = Deno.systemMemoryInfo();
assert(info.total >= 0);
assert(info.free >= 0);

View file

@ -5,7 +5,7 @@ const { pathFromURL } = Deno[Deno.internal];
unitTest(
{ ignore: Deno.build.os === "windows" },
function pathFromURLPosix(): void {
function pathFromURLPosix() {
assertEquals(
pathFromURL(new URL("file:///test/directory")),
"/test/directory",
@ -17,7 +17,7 @@ unitTest(
unitTest(
{ ignore: Deno.build.os !== "windows" },
function pathFromURLWin32(): void {
function pathFromURLWin32() {
assertEquals(
pathFromURL(new URL("file:///c:/windows/test")),
"c:\\windows\\test",

View file

@ -8,12 +8,10 @@ import {
unitTest,
} from "./test_util.ts";
unitTest({ perms: { hrtime: false } }, async function performanceNow(): Promise<
void
> {
unitTest({ perms: { hrtime: false } }, async function performanceNow() {
const resolvable = deferred();
const start = performance.now();
setTimeout((): void => {
setTimeout(() => {
const end = performance.now();
assert(end - start >= 10);
resolvable.resolve();
@ -82,7 +80,7 @@ unitTest(function performanceMeasure() {
});
});
unitTest(function performanceCustomInspectFunction(): void {
unitTest(function performanceCustomInspectFunction() {
assertStringIncludes(Deno.inspect(performance), "Performance");
assertStringIncludes(
Deno.inspect(Performance.prototype),
@ -90,7 +88,7 @@ unitTest(function performanceCustomInspectFunction(): void {
);
});
unitTest(function performanceMarkCustomInspectFunction(): void {
unitTest(function performanceMarkCustomInspectFunction() {
const mark1 = performance.mark("mark1");
assertStringIncludes(Deno.inspect(mark1), "PerformanceMark");
assertStringIncludes(
@ -99,7 +97,7 @@ unitTest(function performanceMarkCustomInspectFunction(): void {
);
});
unitTest(function performanceMeasureCustomInspectFunction(): void {
unitTest(function performanceMeasureCustomInspectFunction() {
const measure1 = performance.measure("measure1");
assertStringIncludes(Deno.inspect(measure1), "PerformanceMeasure");
assertStringIncludes(

View file

@ -7,14 +7,14 @@ import {
unitTest,
} from "./test_util.ts";
unitTest(async function permissionInvalidName(): Promise<void> {
unitTest(async function permissionInvalidName() {
await assertThrowsAsync(async () => {
// deno-lint-ignore no-explicit-any
await Deno.permissions.query({ name: "foo" as any });
}, TypeError);
});
unitTest(async function permissionNetInvalidHost(): Promise<void> {
unitTest(async function permissionNetInvalidHost() {
await assertThrowsAsync(async () => {
await Deno.permissions.query({ name: "net", host: ":" });
}, URIError);

View file

@ -7,7 +7,7 @@ import {
unitTest,
} from "./test_util.ts";
unitTest({ perms: { read: true } }, function runPermissions(): void {
unitTest({ perms: { read: true } }, function runPermissions() {
assertThrows(() => {
Deno.run({ cmd: [Deno.execPath(), "eval", "console.log('hello world')"] });
}, Deno.errors.PermissionDenied);
@ -15,7 +15,7 @@ unitTest({ perms: { read: true } }, function runPermissions(): void {
unitTest(
{ perms: { run: true, read: true } },
async function runSuccess(): Promise<void> {
async function runSuccess() {
const p = Deno.run({
cmd: [Deno.execPath(), "eval", "console.log('hello world')"],
stdout: "piped",
@ -32,7 +32,7 @@ unitTest(
unitTest(
{ perms: { run: true, read: true } },
async function runUrl(): Promise<void> {
async function runUrl() {
const p = Deno.run({
cmd: [
new URL(`file:///${Deno.execPath()}`),
@ -73,7 +73,7 @@ unitTest(
unitTest(
{ perms: { run: true, read: true } },
function runInvalidStdio(): void {
function runInvalidStdio() {
assertThrows(() =>
Deno.run({
cmd: [Deno.execPath(), "eval", "console.log('hello world')"],
@ -100,7 +100,7 @@ unitTest(
unitTest(
{ perms: { run: true, read: true } },
async function runCommandFailedWithCode(): Promise<void> {
async function runCommandFailedWithCode() {
const p = Deno.run({
cmd: [Deno.execPath(), "eval", "Deno.exit(41 + 1)"],
});
@ -118,7 +118,7 @@ unitTest(
ignore: Deno.build.os === "windows",
perms: { run: true, read: true },
},
async function runCommandFailedWithSignal(): Promise<void> {
async function runCommandFailedWithSignal() {
const p = Deno.run({
cmd: [Deno.execPath(), "eval", "--unstable", "Deno.kill(Deno.pid, 9)"],
});
@ -130,7 +130,7 @@ unitTest(
},
);
unitTest({ perms: { run: true } }, function runNotFound(): void {
unitTest({ perms: { run: true } }, function runNotFound() {
let error;
try {
Deno.run({ cmd: ["this file hopefully doesn't exist"] });
@ -143,7 +143,7 @@ unitTest({ perms: { run: true } }, function runNotFound(): void {
unitTest(
{ perms: { write: true, run: true, read: true } },
async function runWithCwdIsAsync(): Promise<void> {
async function runWithCwdIsAsync() {
const enc = new TextEncoder();
const cwd = await Deno.makeTempDir({ prefix: "deno_command_test" });
@ -287,7 +287,7 @@ unitTest(
unitTest(
{ perms: { run: true, read: true } },
async function runOutput(): Promise<void> {
async function runOutput() {
const p = Deno.run({
cmd: [
Deno.execPath(),
@ -325,7 +325,7 @@ unitTest(
unitTest(
{ perms: { run: true, write: true, read: true } },
async function runRedirectStdoutStderr(): Promise<void> {
async function runRedirectStdoutStderr() {
const tempDir = await Deno.makeTempDir();
const fileName = tempDir + "/redirected_stdio.txt";
const file = await Deno.open(fileName, {
@ -358,7 +358,7 @@ unitTest(
unitTest(
{ perms: { run: true, write: true, read: true } },
async function runRedirectStdin(): Promise<void> {
async function runRedirectStdin() {
const tempDir = await Deno.makeTempDir();
const fileName = tempDir + "/redirected_stdio.txt";
const encoder = new TextEncoder();
@ -383,7 +383,7 @@ unitTest(
unitTest(
{ perms: { run: true, read: true } },
async function runEnv(): Promise<void> {
async function runEnv() {
const p = Deno.run({
cmd: [
Deno.execPath(),
@ -405,7 +405,7 @@ unitTest(
unitTest(
{ perms: { run: true, read: true } },
async function runClose(): Promise<void> {
async function runClose() {
const p = Deno.run({
cmd: [
Deno.execPath(),
@ -428,7 +428,7 @@ unitTest(
unitTest(
{ perms: { run: true, read: true } },
async function runKillAfterStatus(): Promise<void> {
async function runKillAfterStatus() {
const p = Deno.run({
cmd: [Deno.execPath(), "eval", 'console.log("hello")'],
});
@ -454,7 +454,7 @@ unitTest(
},
);
unitTest(function signalNumbers(): void {
unitTest(function signalNumbers() {
if (Deno.build.os === "darwin") {
assertEquals(Deno.Signal.SIGSTOP, 17);
} else if (Deno.build.os === "linux") {
@ -462,7 +462,7 @@ unitTest(function signalNumbers(): void {
}
});
unitTest(function killPermissions(): void {
unitTest(function killPermissions() {
assertThrows(() => {
// Unlike the other test cases, we don't have permission to spawn a
// subprocess we can safely kill. Instead we send SIGCONT to the current
@ -474,7 +474,7 @@ unitTest(function killPermissions(): void {
unitTest(
{ perms: { run: true, read: true } },
async function killSuccess(): Promise<void> {
async function killSuccess() {
const p = Deno.run({
cmd: [Deno.execPath(), "eval", "setTimeout(() => {}, 10000)"],
});
@ -497,7 +497,7 @@ unitTest(
},
);
unitTest({ perms: { run: true, read: true } }, function killFailed(): void {
unitTest({ perms: { run: true, read: true } }, function killFailed() {
const p = Deno.run({
cmd: [Deno.execPath(), "eval", "setTimeout(() => {}, 10000)"],
});

View file

@ -1,7 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assertEquals, unitTest } from "./test_util.ts";
unitTest(function progressEventConstruct(): void {
unitTest(function progressEventConstruct() {
const progressEventDefs = new ProgressEvent("progressEventType", {});
assertEquals(progressEventDefs.lengthComputable, false);
assertEquals(progressEventDefs.loaded, 0);

View file

@ -8,7 +8,7 @@ import {
unitTest,
} from "./test_util.ts";
function assertSameContent(files: Deno.DirEntry[]): void {
function assertSameContent(files: Deno.DirEntry[]) {
let counter = 0;
for (const entry of files) {
@ -21,37 +21,35 @@ function assertSameContent(files: Deno.DirEntry[]): void {
assertEquals(counter, 1);
}
unitTest({ perms: { read: true } }, function readDirSyncSuccess(): void {
unitTest({ perms: { read: true } }, function readDirSyncSuccess() {
const files = [...Deno.readDirSync("cli/tests/")];
assertSameContent(files);
});
unitTest({ perms: { read: true } }, function readDirSyncWithUrl(): void {
unitTest({ perms: { read: true } }, function readDirSyncWithUrl() {
const files = [...Deno.readDirSync(pathToAbsoluteFileUrl("cli/tests"))];
assertSameContent(files);
});
unitTest({ perms: { read: false } }, function readDirSyncPerm(): void {
unitTest({ perms: { read: false } }, function readDirSyncPerm() {
assertThrows(() => {
Deno.readDirSync("tests/");
}, Deno.errors.PermissionDenied);
});
unitTest({ perms: { read: true } }, function readDirSyncNotDir(): void {
unitTest({ perms: { read: true } }, function readDirSyncNotDir() {
assertThrows(() => {
Deno.readDirSync("cli/tests/fixture.json");
}, Error);
});
unitTest({ perms: { read: true } }, function readDirSyncNotFound(): void {
unitTest({ perms: { read: true } }, function readDirSyncNotFound() {
assertThrows(() => {
Deno.readDirSync("bad_dir_name");
}, Deno.errors.NotFound);
});
unitTest({ perms: { read: true } }, async function readDirSuccess(): Promise<
void
> {
unitTest({ perms: { read: true } }, async function readDirSuccess() {
const files = [];
for await (const dirEntry of Deno.readDir("cli/tests/")) {
files.push(dirEntry);
@ -59,9 +57,7 @@ unitTest({ perms: { read: true } }, async function readDirSuccess(): Promise<
assertSameContent(files);
});
unitTest({ perms: { read: true } }, async function readDirWithUrl(): Promise<
void
> {
unitTest({ perms: { read: true } }, async function readDirWithUrl() {
const files = [];
for await (
const dirEntry of Deno.readDir(pathToAbsoluteFileUrl("cli/tests"))
@ -71,9 +67,7 @@ unitTest({ perms: { read: true } }, async function readDirWithUrl(): Promise<
assertSameContent(files);
});
unitTest({ perms: { read: false } }, async function readDirPerm(): Promise<
void
> {
unitTest({ perms: { read: false } }, async function readDirPerm() {
await assertThrowsAsync(async () => {
await Deno.readDir("tests/")[Symbol.asyncIterator]().next();
}, Deno.errors.PermissionDenied);
@ -92,7 +86,7 @@ unitTest(
unitTest(
{ perms: { read: true }, ignore: Deno.build.os == "windows" },
function readDirDevFdSync(): void {
function readDirDevFdSync() {
for (const _ of Deno.readDirSync("/dev/fd")) {
// We don't actually care whats in here; just that we don't panic on non regular file entries
}

View file

@ -8,7 +8,7 @@ import {
unitTest,
} from "./test_util.ts";
unitTest({ perms: { read: true } }, function readFileSyncSuccess(): void {
unitTest({ perms: { read: true } }, function readFileSyncSuccess() {
const data = Deno.readFileSync("cli/tests/fixture.json");
assert(data.byteLength > 0);
const decoder = new TextDecoder("utf-8");
@ -17,7 +17,7 @@ unitTest({ perms: { read: true } }, function readFileSyncSuccess(): void {
assertEquals(pkg.name, "deno");
});
unitTest({ perms: { read: true } }, function readFileSyncUrl(): void {
unitTest({ perms: { read: true } }, function readFileSyncUrl() {
const data = Deno.readFileSync(
pathToAbsoluteFileUrl("cli/tests/fixture.json"),
);
@ -28,21 +28,19 @@ unitTest({ perms: { read: true } }, function readFileSyncUrl(): void {
assertEquals(pkg.name, "deno");
});
unitTest({ perms: { read: false } }, function readFileSyncPerm(): void {
unitTest({ perms: { read: false } }, function readFileSyncPerm() {
assertThrows(() => {
Deno.readFileSync("cli/tests/fixture.json");
}, Deno.errors.PermissionDenied);
});
unitTest({ perms: { read: true } }, function readFileSyncNotFound(): void {
unitTest({ perms: { read: true } }, function readFileSyncNotFound() {
assertThrows(() => {
Deno.readFileSync("bad_filename");
}, Deno.errors.NotFound);
});
unitTest({ perms: { read: true } }, async function readFileUrl(): Promise<
void
> {
unitTest({ perms: { read: true } }, async function readFileUrl() {
const data = await Deno.readFile(
pathToAbsoluteFileUrl("cli/tests/fixture.json"),
);
@ -53,9 +51,7 @@ unitTest({ perms: { read: true } }, async function readFileUrl(): Promise<
assertEquals(pkg.name, "deno");
});
unitTest({ perms: { read: true } }, async function readFileSuccess(): Promise<
void
> {
unitTest({ perms: { read: true } }, async function readFileSuccess() {
const data = await Deno.readFile("cli/tests/fixture.json");
assert(data.byteLength > 0);
const decoder = new TextDecoder("utf-8");
@ -64,15 +60,13 @@ unitTest({ perms: { read: true } }, async function readFileSuccess(): Promise<
assertEquals(pkg.name, "deno");
});
unitTest({ perms: { read: false } }, async function readFilePerm(): Promise<
void
> {
unitTest({ perms: { read: false } }, async function readFilePerm() {
await assertThrowsAsync(async () => {
await Deno.readFile("cli/tests/fixture.json");
}, Deno.errors.PermissionDenied);
});
unitTest({ perms: { read: true } }, function readFileSyncLoop(): void {
unitTest({ perms: { read: true } }, function readFileSyncLoop() {
for (let i = 0; i < 256; i++) {
Deno.readFileSync("cli/tests/fixture.json");
}
@ -80,7 +74,7 @@ unitTest({ perms: { read: true } }, function readFileSyncLoop(): void {
unitTest(
{ perms: { read: true } },
async function readFileDoesNotLeakResources(): Promise<void> {
async function readFileDoesNotLeakResources() {
const resourcesBefore = Deno.resources();
await assertThrowsAsync(async () => await Deno.readFile("cli"));
assertEquals(resourcesBefore, Deno.resources());
@ -89,7 +83,7 @@ unitTest(
unitTest(
{ perms: { read: true } },
function readFileSyncDoesNotLeakResources(): void {
function readFileSyncDoesNotLeakResources() {
const resourcesBefore = Deno.resources();
assertThrows(() => Deno.readFileSync("cli"));
assertEquals(resourcesBefore, Deno.resources());
@ -98,7 +92,7 @@ unitTest(
unitTest(
{ perms: { read: true } },
async function readFileWithAbortSignal(): Promise<void> {
async function readFileWithAbortSignal() {
const ac = new AbortController();
queueMicrotask(() => ac.abort());
await assertThrowsAsync(async () => {
@ -109,7 +103,7 @@ unitTest(
unitTest(
{ perms: { read: true } },
async function readTextileWithAbortSignal(): Promise<void> {
async function readTextileWithAbortSignal() {
const ac = new AbortController();
queueMicrotask(() => ac.abort());
await assertThrowsAsync(async () => {

View file

@ -9,7 +9,7 @@ import {
unitTest(
{ perms: { write: true, read: true } },
function readLinkSyncSuccess(): void {
function readLinkSyncSuccess() {
const testDir = Deno.makeTempDirSync();
const target = testDir +
(Deno.build.os == "windows" ? "\\target" : "/target");
@ -24,7 +24,7 @@ unitTest(
unitTest(
{ perms: { write: true, read: true } },
function readLinkSyncUrlSuccess(): void {
function readLinkSyncUrlSuccess() {
const testDir = Deno.makeTempDirSync();
const target = testDir +
(Deno.build.os == "windows" ? "\\target" : "/target");
@ -37,13 +37,13 @@ unitTest(
},
);
unitTest({ perms: { read: false } }, function readLinkSyncPerm(): void {
unitTest({ perms: { read: false } }, function readLinkSyncPerm() {
assertThrows(() => {
Deno.readLinkSync("/symlink");
}, Deno.errors.PermissionDenied);
});
unitTest({ perms: { read: true } }, function readLinkSyncNotFound(): void {
unitTest({ perms: { read: true } }, function readLinkSyncNotFound() {
assertThrows(() => {
Deno.readLinkSync("bad_filename");
}, Deno.errors.NotFound);
@ -51,7 +51,7 @@ unitTest({ perms: { read: true } }, function readLinkSyncNotFound(): void {
unitTest(
{ perms: { write: true, read: true } },
async function readLinkSuccess(): Promise<void> {
async function readLinkSuccess() {
const testDir = Deno.makeTempDirSync();
const target = testDir +
(Deno.build.os == "windows" ? "\\target" : "/target");
@ -66,7 +66,7 @@ unitTest(
unitTest(
{ perms: { write: true, read: true } },
async function readLinkUrlSuccess(): Promise<void> {
async function readLinkUrlSuccess() {
const testDir = Deno.makeTempDirSync();
const target = testDir +
(Deno.build.os == "windows" ? "\\target" : "/target");
@ -79,9 +79,7 @@ unitTest(
},
);
unitTest({ perms: { read: false } }, async function readLinkPerm(): Promise<
void
> {
unitTest({ perms: { read: false } }, async function readLinkPerm() {
await assertThrowsAsync(async () => {
await Deno.readLink("/symlink");
}, Deno.errors.PermissionDenied);

View file

@ -7,14 +7,14 @@ import {
unitTest,
} from "./test_util.ts";
unitTest({ perms: { read: true } }, function readTextFileSyncSuccess(): void {
unitTest({ perms: { read: true } }, function readTextFileSyncSuccess() {
const data = Deno.readTextFileSync("cli/tests/fixture.json");
assert(data.length > 0);
const pkg = JSON.parse(data);
assertEquals(pkg.name, "deno");
});
unitTest({ perms: { read: true } }, function readTextFileSyncByUrl(): void {
unitTest({ perms: { read: true } }, function readTextFileSyncByUrl() {
const data = Deno.readTextFileSync(
pathToAbsoluteFileUrl("cli/tests/fixture.json"),
);
@ -23,13 +23,13 @@ unitTest({ perms: { read: true } }, function readTextFileSyncByUrl(): void {
assertEquals(pkg.name, "deno");
});
unitTest({ perms: { read: false } }, function readTextFileSyncPerm(): void {
unitTest({ perms: { read: false } }, function readTextFileSyncPerm() {
assertThrows(() => {
Deno.readTextFileSync("cli/tests/fixture.json");
}, Deno.errors.PermissionDenied);
});
unitTest({ perms: { read: true } }, function readTextFileSyncNotFound(): void {
unitTest({ perms: { read: true } }, function readTextFileSyncNotFound() {
assertThrows(() => {
Deno.readTextFileSync("bad_filename");
}, Deno.errors.NotFound);
@ -37,7 +37,7 @@ unitTest({ perms: { read: true } }, function readTextFileSyncNotFound(): void {
unitTest(
{ perms: { read: true } },
async function readTextFileSuccess(): Promise<void> {
async function readTextFileSuccess() {
const data = await Deno.readTextFile("cli/tests/fixture.json");
assert(data.length > 0);
const pkg = JSON.parse(data);
@ -45,9 +45,7 @@ unitTest(
},
);
unitTest({ perms: { read: true } }, async function readTextFileByUrl(): Promise<
void
> {
unitTest({ perms: { read: true } }, async function readTextFileByUrl() {
const data = await Deno.readTextFile(
pathToAbsoluteFileUrl("cli/tests/fixture.json"),
);
@ -56,15 +54,13 @@ unitTest({ perms: { read: true } }, async function readTextFileByUrl(): Promise<
assertEquals(pkg.name, "deno");
});
unitTest({ perms: { read: false } }, async function readTextFilePerm(): Promise<
void
> {
unitTest({ perms: { read: false } }, async function readTextFilePerm() {
await assertThrowsAsync(async () => {
await Deno.readTextFile("cli/tests/fixture.json");
}, Deno.errors.PermissionDenied);
});
unitTest({ perms: { read: true } }, function readTextFileSyncLoop(): void {
unitTest({ perms: { read: true } }, function readTextFileSyncLoop() {
for (let i = 0; i < 256; i++) {
Deno.readTextFileSync("cli/tests/fixture.json");
}
@ -72,7 +68,7 @@ unitTest({ perms: { read: true } }, function readTextFileSyncLoop(): void {
unitTest(
{ perms: { read: true } },
async function readTextFileDoesNotLeakResources(): Promise<void> {
async function readTextFileDoesNotLeakResources() {
const resourcesBefore = Deno.resources();
await assertThrowsAsync(async () => await Deno.readTextFile("cli"));
assertEquals(resourcesBefore, Deno.resources());
@ -81,7 +77,7 @@ unitTest(
unitTest(
{ perms: { read: true } },
function readTextFileSyncDoesNotLeakResources(): void {
function readTextFileSyncDoesNotLeakResources() {
const resourcesBefore = Deno.resources();
assertThrows(() => Deno.readTextFileSync("cli"));
assertEquals(resourcesBefore, Deno.resources());

View file

@ -9,7 +9,7 @@ import {
unitTest,
} from "./test_util.ts";
unitTest({ perms: { read: true } }, function realPathSyncSuccess(): void {
unitTest({ perms: { read: true } }, function realPathSyncSuccess() {
const relative = "cli/tests/fixture.json";
const realPath = Deno.realPathSync(relative);
if (Deno.build.os !== "windows") {
@ -21,7 +21,7 @@ unitTest({ perms: { read: true } }, function realPathSyncSuccess(): void {
}
});
unitTest({ perms: { read: true } }, function realPathSyncUrl(): void {
unitTest({ perms: { read: true } }, function realPathSyncUrl() {
const relative = "cli/tests/fixture.json";
const url = pathToAbsoluteFileUrl(relative);
assertEquals(Deno.realPathSync(relative), Deno.realPathSync(url));
@ -31,7 +31,7 @@ unitTest(
{
perms: { read: true, write: true },
},
function realPathSyncSymlink(): void {
function realPathSyncSymlink() {
const testDir = Deno.makeTempDirSync();
const target = testDir + "/target";
const symlink = testDir + "/symln";
@ -48,21 +48,19 @@ unitTest(
},
);
unitTest({ perms: { read: false } }, function realPathSyncPerm(): void {
unitTest({ perms: { read: false } }, function realPathSyncPerm() {
assertThrows(() => {
Deno.realPathSync("some_file");
}, Deno.errors.PermissionDenied);
});
unitTest({ perms: { read: true } }, function realPathSyncNotFound(): void {
unitTest({ perms: { read: true } }, function realPathSyncNotFound() {
assertThrows(() => {
Deno.realPathSync("bad_filename");
}, Deno.errors.NotFound);
});
unitTest({ perms: { read: true } }, async function realPathSuccess(): Promise<
void
> {
unitTest({ perms: { read: true } }, async function realPathSuccess() {
const relativePath = "cli/tests/fixture.json";
const realPath = await Deno.realPath(relativePath);
if (Deno.build.os !== "windows") {
@ -76,7 +74,7 @@ unitTest({ perms: { read: true } }, async function realPathSuccess(): Promise<
unitTest(
{ perms: { read: true } },
async function realPathUrl(): Promise<void> {
async function realPathUrl() {
const relative = "cli/tests/fixture.json";
const url = pathToAbsoluteFileUrl(relative);
assertEquals(await Deno.realPath(relative), await Deno.realPath(url));
@ -87,7 +85,7 @@ unitTest(
{
perms: { read: true, write: true },
},
async function realPathSymlink(): Promise<void> {
async function realPathSymlink() {
const testDir = Deno.makeTempDirSync();
const target = testDir + "/target";
const symlink = testDir + "/symln";
@ -104,17 +102,13 @@ unitTest(
},
);
unitTest({ perms: { read: false } }, async function realPathPerm(): Promise<
void
> {
unitTest({ perms: { read: false } }, async function realPathPerm() {
await assertThrowsAsync(async () => {
await Deno.realPath("some_file");
}, Deno.errors.PermissionDenied);
});
unitTest({ perms: { read: true } }, async function realPathNotFound(): Promise<
void
> {
unitTest({ perms: { read: true } }, async function realPathNotFound() {
await assertThrowsAsync(async () => {
await Deno.realPath("bad_filename");
}, Deno.errors.NotFound);

View file

@ -10,7 +10,7 @@ const REMOVE_METHODS = ["remove", "removeSync"] as const;
unitTest(
{ perms: { write: true, read: true } },
async function removeDirSuccess(): Promise<void> {
async function removeDirSuccess() {
for (const method of REMOVE_METHODS) {
// REMOVE EMPTY DIRECTORY
const path = Deno.makeTempDirSync() + "/subdir";
@ -28,7 +28,7 @@ unitTest(
unitTest(
{ perms: { write: true, read: true } },
async function removeFileSuccess(): Promise<void> {
async function removeFileSuccess() {
for (const method of REMOVE_METHODS) {
// REMOVE FILE
const enc = new TextEncoder();
@ -48,7 +48,7 @@ unitTest(
unitTest(
{ perms: { write: true, read: true } },
async function removeFileByUrl(): Promise<void> {
async function removeFileByUrl() {
for (const method of REMOVE_METHODS) {
// REMOVE FILE
const enc = new TextEncoder();
@ -73,7 +73,7 @@ unitTest(
unitTest(
{ perms: { write: true, read: true } },
async function removeFail(): Promise<void> {
async function removeFail() {
for (const method of REMOVE_METHODS) {
// NON-EMPTY DIRECTORY
const path = Deno.makeTempDirSync() + "/dir/subdir";
@ -100,7 +100,7 @@ unitTest(
unitTest(
{ perms: { write: true, read: true } },
async function removeDanglingSymlinkSuccess(): Promise<void> {
async function removeDanglingSymlinkSuccess() {
for (const method of REMOVE_METHODS) {
const danglingSymlinkPath = Deno.makeTempDirSync() + "/dangling_symlink";
if (Deno.build.os === "windows") {
@ -122,7 +122,7 @@ unitTest(
unitTest(
{ perms: { write: true, read: true } },
async function removeValidSymlinkSuccess(): Promise<void> {
async function removeValidSymlinkSuccess() {
for (const method of REMOVE_METHODS) {
const encoder = new TextEncoder();
const data = encoder.encode("Test");
@ -146,9 +146,7 @@ unitTest(
},
);
unitTest({ perms: { write: false } }, async function removePerm(): Promise<
void
> {
unitTest({ perms: { write: false } }, async function removePerm() {
for (const method of REMOVE_METHODS) {
await assertThrowsAsync(async () => {
await Deno[method]("/baddir");
@ -158,7 +156,7 @@ unitTest({ perms: { write: false } }, async function removePerm(): Promise<
unitTest(
{ perms: { write: true, read: true } },
async function removeAllDirSuccess(): Promise<void> {
async function removeAllDirSuccess() {
for (const method of REMOVE_METHODS) {
// REMOVE EMPTY DIRECTORY
let path = Deno.makeTempDirSync() + "/dir/subdir";
@ -195,7 +193,7 @@ unitTest(
unitTest(
{ perms: { write: true, read: true } },
async function removeAllFileSuccess(): Promise<void> {
async function removeAllFileSuccess() {
for (const method of REMOVE_METHODS) {
// REMOVE FILE
const enc = new TextEncoder();
@ -214,9 +212,7 @@ unitTest(
},
);
unitTest({ perms: { write: true } }, async function removeAllFail(): Promise<
void
> {
unitTest({ perms: { write: true } }, async function removeAllFail() {
for (const method of REMOVE_METHODS) {
// NON-EXISTENT DIRECTORY/FILE
await assertThrowsAsync(async () => {
@ -226,9 +222,7 @@ unitTest({ perms: { write: true } }, async function removeAllFail(): Promise<
}
});
unitTest({ perms: { write: false } }, async function removeAllPerm(): Promise<
void
> {
unitTest({ perms: { write: false } }, async function removeAllPerm() {
for (const method of REMOVE_METHODS) {
await assertThrowsAsync(async () => {
await Deno[method]("/baddir", { recursive: true });
@ -241,7 +235,7 @@ unitTest(
ignore: Deno.build.os === "windows",
perms: { write: true, read: true },
},
async function removeUnixSocketSuccess(): Promise<void> {
async function removeUnixSocketSuccess() {
for (const method of REMOVE_METHODS) {
// MAKE TEMPORARY UNIX SOCKET
const path = Deno.makeTempDirSync() + "/test.sock";
@ -260,7 +254,7 @@ unitTest(
if (Deno.build.os === "windows") {
unitTest(
{ perms: { run: true, write: true, read: true } },
async function removeFileSymlink(): Promise<void> {
async function removeFileSymlink() {
const symlink = Deno.run({
cmd: ["cmd", "/c", "mklink", "file_link", "bar"],
stdout: "null",
@ -277,7 +271,7 @@ if (Deno.build.os === "windows") {
unitTest(
{ perms: { run: true, write: true, read: true } },
async function removeDirSymlink(): Promise<void> {
async function removeDirSymlink() {
const symlink = Deno.run({
cmd: ["cmd", "/c", "mklink", "/d", "dir_link", "bar"],
stdout: "null",

View file

@ -7,7 +7,7 @@ import {
unitTest,
} from "./test_util.ts";
function assertMissing(path: string): void {
function assertMissing(path: string) {
let caughtErr = false;
let info;
try {
@ -20,12 +20,12 @@ function assertMissing(path: string): void {
assertEquals(info, undefined);
}
function assertFile(path: string): void {
function assertFile(path: string) {
const info = Deno.lstatSync(path);
assert(info.isFile);
}
function assertDirectory(path: string, mode?: number): void {
function assertDirectory(path: string, mode?: number) {
const info = Deno.lstatSync(path);
assert(info.isDirectory);
if (Deno.build.os !== "windows" && mode !== undefined) {
@ -35,7 +35,7 @@ function assertDirectory(path: string, mode?: number): void {
unitTest(
{ perms: { read: true, write: true } },
function renameSyncSuccess(): void {
function renameSyncSuccess() {
const testDir = Deno.makeTempDirSync();
const oldpath = testDir + "/oldpath";
const newpath = testDir + "/newpath";
@ -48,7 +48,7 @@ unitTest(
unitTest(
{ perms: { read: true, write: true } },
function renameSyncWithURL(): void {
function renameSyncWithURL() {
const testDir = Deno.makeTempDirSync();
const oldpath = testDir + "/oldpath";
const newpath = testDir + "/newpath";
@ -64,7 +64,7 @@ unitTest(
unitTest(
{ perms: { read: false, write: true } },
function renameSyncReadPerm(): void {
function renameSyncReadPerm() {
assertThrows(() => {
const oldpath = "/oldbaddir";
const newpath = "/newbaddir";
@ -75,7 +75,7 @@ unitTest(
unitTest(
{ perms: { read: true, write: false } },
function renameSyncWritePerm(): void {
function renameSyncWritePerm() {
assertThrows(() => {
const oldpath = "/oldbaddir";
const newpath = "/newbaddir";
@ -86,7 +86,7 @@ unitTest(
unitTest(
{ perms: { read: true, write: true } },
async function renameSuccess(): Promise<void> {
async function renameSuccess() {
const testDir = Deno.makeTempDirSync();
const oldpath = testDir + "/oldpath";
const newpath = testDir + "/newpath";
@ -99,7 +99,7 @@ unitTest(
unitTest(
{ perms: { read: true, write: true } },
async function renameWithURL(): Promise<void> {
async function renameWithURL() {
const testDir = Deno.makeTempDirSync();
const oldpath = testDir + "/oldpath";
const newpath = testDir + "/newpath";
@ -119,7 +119,7 @@ function readFileString(filename: string): string {
return dec.decode(dataRead);
}
function writeFileString(filename: string, s: string): void {
function writeFileString(filename: string, s: string) {
const enc = new TextEncoder();
const data = enc.encode(s);
Deno.writeFileSync(filename, data, { mode: 0o666 });
@ -127,7 +127,7 @@ function writeFileString(filename: string, s: string): void {
unitTest(
{ ignore: Deno.build.os === "windows", perms: { read: true, write: true } },
function renameSyncErrorsUnix(): void {
function renameSyncErrorsUnix() {
const testDir = Deno.makeTempDirSync();
const oldfile = testDir + "/oldfile";
const olddir = testDir + "/olddir";
@ -141,21 +141,21 @@ unitTest(
writeFileString(file, "world");
assertThrows(
(): void => {
() => {
Deno.renameSync(oldfile, emptydir);
},
Error,
"Is a directory",
);
assertThrows(
(): void => {
() => {
Deno.renameSync(olddir, fulldir);
},
Error,
"Directory not empty",
);
assertThrows(
(): void => {
() => {
Deno.renameSync(olddir, file);
},
Error,
@ -170,21 +170,21 @@ unitTest(
Deno.symlinkSync(testDir + "/nonexistent", danglingLink);
assertThrows(
(): void => {
() => {
Deno.renameSync(olddir, fileLink);
},
Error,
"Not a directory",
);
assertThrows(
(): void => {
() => {
Deno.renameSync(olddir, dirLink);
},
Error,
"Not a directory",
);
assertThrows(
(): void => {
() => {
Deno.renameSync(olddir, danglingLink);
},
Error,
@ -202,7 +202,7 @@ unitTest(
unitTest(
{ ignore: Deno.build.os !== "windows", perms: { read: true, write: true } },
function renameSyncErrorsWin(): void {
function renameSyncErrorsWin() {
const testDir = Deno.makeTempDirSync();
const oldfile = testDir + "/oldfile";
const olddir = testDir + "/olddir";
@ -216,21 +216,21 @@ unitTest(
writeFileString(file, "world");
assertThrows(
(): void => {
() => {
Deno.renameSync(oldfile, emptydir);
},
Deno.errors.PermissionDenied,
"Access is denied",
);
assertThrows(
(): void => {
() => {
Deno.renameSync(olddir, fulldir);
},
Deno.errors.PermissionDenied,
"Access is denied",
);
assertThrows(
(): void => {
() => {
Deno.renameSync(olddir, emptydir);
},
Deno.errors.PermissionDenied,

View file

@ -1,7 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assertEquals, assertStringIncludes, unitTest } from "./test_util.ts";
unitTest(async function fromInit(): Promise<void> {
unitTest(async function fromInit() {
const req = new Request("http://foo/", {
body: "ahoyhoy",
method: "POST",
@ -15,7 +15,7 @@ unitTest(async function fromInit(): Promise<void> {
assertEquals(req.headers.get("test-header"), "value");
});
unitTest(function requestNonString(): void {
unitTest(function requestNonString() {
const nonString = {
toString() {
return "http://foo/";
@ -26,18 +26,18 @@ unitTest(function requestNonString(): void {
assertEquals(new Request(nonString).url, "http://foo/");
});
unitTest(function methodNonString(): void {
unitTest(function methodNonString() {
assertEquals(new Request("http://foo/", { method: undefined }).method, "GET");
});
unitTest(function requestRelativeUrl(): void {
unitTest(function requestRelativeUrl() {
assertEquals(
new Request("relative-url").url,
"http://js-unit-tests/foo/relative-url",
);
});
unitTest(async function cloneRequestBodyStream(): Promise<void> {
unitTest(async function cloneRequestBodyStream() {
// hack to get a stream
const stream =
new Request("http://foo/", { body: "a test body", method: "POST" }).body;
@ -54,7 +54,7 @@ unitTest(async function cloneRequestBodyStream(): Promise<void> {
assertEquals(b1, b2);
});
unitTest(function customInspectFunction(): void {
unitTest(function customInspectFunction() {
const request = new Request("https://example.com");
assertEquals(
Deno.inspect(request),

View file

@ -1,13 +1,13 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assert, assertEquals, assertThrows, unitTest } from "./test_util.ts";
unitTest(function resourcesCloseBadArgs(): void {
unitTest(function resourcesCloseBadArgs() {
assertThrows(() => {
Deno.close((null as unknown) as number);
}, TypeError);
});
unitTest(function resourcesStdio(): void {
unitTest(function resourcesStdio() {
const res = Deno.resources();
assertEquals(res[0], "stdin");
@ -15,9 +15,7 @@ unitTest(function resourcesStdio(): void {
assertEquals(res[2], "stderr");
});
unitTest({ perms: { net: true } }, async function resourcesNet(): Promise<
void
> {
unitTest({ perms: { net: true } }, async function resourcesNet() {
const listener = Deno.listen({ port: 4501 });
const dialerConn = await Deno.connect({ port: 4501 });
const listenerConn = await listener.accept();
@ -37,9 +35,7 @@ unitTest({ perms: { net: true } }, async function resourcesNet(): Promise<
listener.close();
});
unitTest({ perms: { read: true } }, async function resourcesFile(): Promise<
void
> {
unitTest({ perms: { read: true } }, async function resourcesFile() {
const resourcesBefore = Deno.resources();
const f = await Deno.open("cli/tests/hello.txt");
const resourcesAfter = Deno.resources();

View file

@ -56,7 +56,7 @@ unitTest(async function responseFormData() {
assertEquals([...formData], [...input]);
});
unitTest(function customInspectFunction(): void {
unitTest(function customInspectFunction() {
const response = new Response();
assertEquals(
Deno.inspect(response),

View file

@ -10,7 +10,7 @@ import {
unitTest(
{ ignore: Deno.build.os !== "windows" },
function signalsNotImplemented(): void {
function signalsNotImplemented() {
assertThrows(
() => {
Deno.signal(1);
@ -100,7 +100,7 @@ unitTest(
unitTest(
{ ignore: Deno.build.os === "windows", perms: { run: true, net: true } },
async function signalStreamTest(): Promise<void> {
async function signalStreamTest() {
const resolvable = deferred();
// This prevents the program from exiting.
const t = setInterval(() => {}, 1000);
@ -132,7 +132,7 @@ unitTest(
// This tests that pending op_signal_poll doesn't block the runtime from exiting the process.
unitTest(
{ ignore: Deno.build.os === "windows", perms: { run: true, read: true } },
async function signalStreamExitTest(): Promise<void> {
async function signalStreamExitTest() {
const p = Deno.run({
cmd: [
Deno.execPath(),
@ -149,7 +149,7 @@ unitTest(
unitTest(
{ ignore: Deno.build.os === "windows", perms: { run: true } },
async function signalPromiseTest(): Promise<void> {
async function signalPromiseTest() {
const resolvable = deferred();
// This prevents the program from exiting.
const t = setInterval(() => {}, 1000);
@ -170,7 +170,7 @@ unitTest(
// https://github.com/denoland/deno/issues/9806
unitTest(
{ ignore: Deno.build.os === "windows", perms: { run: true } },
async function signalPromiseTest2(): Promise<void> {
async function signalPromiseTest2() {
const resolvable = deferred();
// This prevents the program from exiting.
const t = setInterval(() => {}, 1000);
@ -198,7 +198,7 @@ unitTest(
unitTest(
{ ignore: Deno.build.os === "windows", perms: { run: true } },
function signalShorthandsTest(): void {
function signalShorthandsTest() {
let s: Deno.SignalStream;
s = Deno.signals.alarm(); // for SIGALRM
assert(s instanceof Deno.SignalStream);

View file

@ -8,7 +8,7 @@ import {
unitTest,
} from "./test_util.ts";
unitTest({ perms: { read: true } }, function fstatSyncSuccess(): void {
unitTest({ perms: { read: true } }, function fstatSyncSuccess() {
const file = Deno.openSync("README.md");
const fileInfo = Deno.fstatSync(file.rid);
assert(fileInfo.isFile);
@ -23,9 +23,7 @@ unitTest({ perms: { read: true } }, function fstatSyncSuccess(): void {
Deno.close(file.rid);
});
unitTest({ perms: { read: true } }, async function fstatSuccess(): Promise<
void
> {
unitTest({ perms: { read: true } }, async function fstatSuccess() {
const file = await Deno.open("README.md");
const fileInfo = await Deno.fstat(file.rid);
assert(fileInfo.isFile);
@ -42,7 +40,7 @@ unitTest({ perms: { read: true } }, async function fstatSuccess(): Promise<
unitTest(
{ perms: { read: true, write: true } },
function statSyncSuccess(): void {
function statSyncSuccess() {
const packageInfo = Deno.statSync("README.md");
assert(packageInfo.isFile);
assert(!packageInfo.isSymlink);
@ -103,19 +101,19 @@ unitTest(
},
);
unitTest({ perms: { read: false } }, function statSyncPerm(): void {
unitTest({ perms: { read: false } }, function statSyncPerm() {
assertThrows(() => {
Deno.statSync("README.md");
}, Deno.errors.PermissionDenied);
});
unitTest({ perms: { read: true } }, function statSyncNotFound(): void {
unitTest({ perms: { read: true } }, function statSyncNotFound() {
assertThrows(() => {
Deno.statSync("bad_file_name");
}, Deno.errors.NotFound);
});
unitTest({ perms: { read: true } }, function lstatSyncSuccess(): void {
unitTest({ perms: { read: true } }, function lstatSyncSuccess() {
const packageInfo = Deno.lstatSync("README.md");
assert(packageInfo.isFile);
assert(!packageInfo.isSymlink);
@ -143,13 +141,13 @@ unitTest({ perms: { read: true } }, function lstatSyncSuccess(): void {
assert(!coreInfoByUrl.isSymlink);
});
unitTest({ perms: { read: false } }, function lstatSyncPerm(): void {
unitTest({ perms: { read: false } }, function lstatSyncPerm() {
assertThrows(() => {
Deno.lstatSync("README.md");
}, Deno.errors.PermissionDenied);
});
unitTest({ perms: { read: true } }, function lstatSyncNotFound(): void {
unitTest({ perms: { read: true } }, function lstatSyncNotFound() {
assertThrows(() => {
Deno.lstatSync("bad_file_name");
}, Deno.errors.NotFound);
@ -157,7 +155,7 @@ unitTest({ perms: { read: true } }, function lstatSyncNotFound(): void {
unitTest(
{ perms: { read: true, write: true } },
async function statSuccess(): Promise<void> {
async function statSuccess() {
const packageInfo = await Deno.stat("README.md");
assert(packageInfo.isFile);
assert(!packageInfo.isSymlink);
@ -221,25 +219,21 @@ unitTest(
},
);
unitTest({ perms: { read: false } }, async function statPerm(): Promise<void> {
unitTest({ perms: { read: false } }, async function statPerm() {
await assertThrowsAsync(async () => {
await Deno.stat("README.md");
}, Deno.errors.PermissionDenied);
});
unitTest({ perms: { read: true } }, async function statNotFound(): Promise<
void
> {
unitTest({ perms: { read: true } }, async function statNotFound() {
await assertThrowsAsync(
async (): Promise<void> => {
async () => {
await Deno.stat("bad_file_name"), Deno.errors.NotFound;
},
);
});
unitTest({ perms: { read: true } }, async function lstatSuccess(): Promise<
void
> {
unitTest({ perms: { read: true } }, async function lstatSuccess() {
const packageInfo = await Deno.lstat("README.md");
assert(packageInfo.isFile);
assert(!packageInfo.isSymlink);
@ -267,15 +261,13 @@ unitTest({ perms: { read: true } }, async function lstatSuccess(): Promise<
assert(!coreInfoByUrl.isSymlink);
});
unitTest({ perms: { read: false } }, async function lstatPerm(): Promise<void> {
unitTest({ perms: { read: false } }, async function lstatPerm() {
await assertThrowsAsync(async () => {
await Deno.lstat("README.md");
}, Deno.errors.PermissionDenied);
});
unitTest({ perms: { read: true } }, async function lstatNotFound(): Promise<
void
> {
unitTest({ perms: { read: true } }, async function lstatNotFound() {
await assertThrowsAsync(async () => {
await Deno.lstat("bad_file_name");
}, Deno.errors.NotFound);
@ -283,7 +275,7 @@ unitTest({ perms: { read: true } }, async function lstatNotFound(): Promise<
unitTest(
{ ignore: Deno.build.os !== "windows", perms: { read: true, write: true } },
function statNoUnixFields(): void {
function statNoUnixFields() {
const enc = new TextEncoder();
const data = enc.encode("Hello");
const tempDir = Deno.makeTempDirSync();
@ -304,7 +296,7 @@ unitTest(
unitTest(
{ ignore: Deno.build.os === "windows", perms: { read: true, write: true } },
function statUnixFields(): void {
function statUnixFields() {
const enc = new TextEncoder();
const data = enc.encode("Hello");
const tempDir = Deno.makeTempDirSync();

View file

@ -8,7 +8,7 @@ import {
unitTest(
{ perms: { read: true, write: true } },
function symlinkSyncSuccess(): void {
function symlinkSyncSuccess() {
const testDir = Deno.makeTempDirSync();
const oldname = testDir + "/oldname";
const newname = testDir + "/newname";
@ -23,7 +23,7 @@ unitTest(
unitTest(
{ perms: { read: true, write: true } },
function symlinkSyncURL(): void {
function symlinkSyncURL() {
const testDir = Deno.makeTempDirSync();
const oldname = testDir + "/oldname";
const newname = testDir + "/newname";
@ -39,7 +39,7 @@ unitTest(
},
);
unitTest(function symlinkSyncPerm(): void {
unitTest(function symlinkSyncPerm() {
assertThrows(() => {
Deno.symlinkSync("oldbaddir", "newbaddir");
}, Deno.errors.PermissionDenied);
@ -47,7 +47,7 @@ unitTest(function symlinkSyncPerm(): void {
unitTest(
{ perms: { read: true, write: true } },
async function symlinkSuccess(): Promise<void> {
async function symlinkSuccess() {
const testDir = Deno.makeTempDirSync();
const oldname = testDir + "/oldname";
const newname = testDir + "/newname";
@ -62,7 +62,7 @@ unitTest(
unitTest(
{ perms: { read: true, write: true } },
async function symlinkURL(): Promise<void> {
async function symlinkURL() {
const testDir = Deno.makeTempDirSync();
const oldname = testDir + "/oldname";
const newname = testDir + "/newname";

View file

@ -3,7 +3,7 @@ import { assertEquals, unitTest } from "./test_util.ts";
unitTest(
{ perms: { read: true, write: true } },
function fdatasyncSyncSuccess(): void {
function fdatasyncSyncSuccess() {
const filename = Deno.makeTempDirSync() + "/test_fdatasyncSync.txt";
const file = Deno.openSync(filename, {
read: true,
@ -21,7 +21,7 @@ unitTest(
unitTest(
{ perms: { read: true, write: true } },
async function fdatasyncSuccess(): Promise<void> {
async function fdatasyncSuccess() {
const filename = (await Deno.makeTempDir()) + "/test_fdatasync.txt";
const file = await Deno.open(filename, {
read: true,
@ -39,7 +39,7 @@ unitTest(
unitTest(
{ perms: { read: true, write: true } },
function fsyncSyncSuccess(): void {
function fsyncSyncSuccess() {
const filename = Deno.makeTempDirSync() + "/test_fsyncSync.txt";
const file = Deno.openSync(filename, {
read: true,
@ -57,7 +57,7 @@ unitTest(
unitTest(
{ perms: { read: true, write: true } },
async function fsyncSuccess(): Promise<void> {
async function fsyncSuccess() {
const filename = (await Deno.makeTempDir()) + "/test_fsync.txt";
const file = await Deno.open(filename, {
read: true,

View file

@ -1,12 +1,12 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assertThrows, unitTest } from "./test_util.ts";
unitTest(function testFnOverloading(): void {
unitTest(function testFnOverloading() {
// just verifying that you can use this test definition syntax
Deno.test("test fn overloading", (): void => {});
Deno.test("test fn overloading", () => {});
});
unitTest(function nameOfTestCaseCantBeEmpty(): void {
unitTest(function nameOfTestCaseCantBeEmpty() {
assertThrows(
() => {
Deno.test("", () => {});

View file

@ -1,19 +1,19 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assert, assertEquals, assertThrows, unitTest } from "./test_util.ts";
unitTest(function btoaSuccess(): void {
unitTest(function btoaSuccess() {
const text = "hello world";
const encoded = btoa(text);
assertEquals(encoded, "aGVsbG8gd29ybGQ=");
});
unitTest(function atobSuccess(): void {
unitTest(function atobSuccess() {
const encoded = "aGVsbG8gd29ybGQ=";
const decoded = atob(encoded);
assertEquals(decoded, "hello world");
});
unitTest(function atobWithAsciiWhitespace(): void {
unitTest(function atobWithAsciiWhitespace() {
const encodedList = [
" aGVsbG8gd29ybGQ=",
" aGVsbG8gd29ybGQ=",
@ -30,7 +30,7 @@ unitTest(function atobWithAsciiWhitespace(): void {
}
});
unitTest(function atobThrows(): void {
unitTest(function atobThrows() {
let threw = false;
try {
atob("aGVsbG8gd29ybGQ==");
@ -40,7 +40,7 @@ unitTest(function atobThrows(): void {
assert(threw);
});
unitTest(function atobThrows2(): void {
unitTest(function atobThrows2() {
let threw = false;
try {
atob("aGVsbG8gd29ybGQ===");
@ -50,7 +50,7 @@ unitTest(function atobThrows2(): void {
assert(threw);
});
unitTest(function atobThrows3(): void {
unitTest(function atobThrows3() {
let threw = false;
try {
atob("foobar!!");
@ -65,14 +65,14 @@ unitTest(function atobThrows3(): void {
assert(threw);
});
unitTest(function btoaFailed(): void {
unitTest(function btoaFailed() {
const text = "你好";
assertThrows(() => {
btoa(text);
}, DOMException);
});
unitTest(function textDecoder2(): void {
unitTest(function textDecoder2() {
// deno-fmt-ignore
const fixture = new Uint8Array([
0xf0, 0x9d, 0x93, 0xbd,
@ -86,13 +86,13 @@ unitTest(function textDecoder2(): void {
// ignoreBOM is tested through WPT
unitTest(function textDecoderASCII(): void {
unitTest(function textDecoderASCII() {
const fixture = new Uint8Array([0x89, 0x95, 0x9f, 0xbf]);
const decoder = new TextDecoder("ascii");
assertEquals(decoder.decode(fixture), "‰•Ÿ¿");
});
unitTest(function textDecoderErrorEncoding(): void {
unitTest(function textDecoderErrorEncoding() {
let didThrow = false;
try {
new TextDecoder("Foo");
@ -103,7 +103,7 @@ unitTest(function textDecoderErrorEncoding(): void {
assert(didThrow);
});
unitTest(function textEncoder(): void {
unitTest(function textEncoder() {
const fixture = "𝓽𝓮𝔁𝓽";
const encoder = new TextEncoder();
// deno-fmt-ignore
@ -115,7 +115,7 @@ unitTest(function textEncoder(): void {
]);
});
unitTest(function textEncodeInto(): void {
unitTest(function textEncodeInto() {
const fixture = "text";
const encoder = new TextEncoder();
const bytes = new Uint8Array(5);
@ -128,7 +128,7 @@ unitTest(function textEncodeInto(): void {
]);
});
unitTest(function textEncodeInto2(): void {
unitTest(function textEncodeInto2() {
const fixture = "𝓽𝓮𝔁𝓽";
const encoder = new TextEncoder();
const bytes = new Uint8Array(17);
@ -144,7 +144,7 @@ unitTest(function textEncodeInto2(): void {
]);
});
unitTest(function textEncodeInto3(): void {
unitTest(function textEncodeInto3() {
const fixture = "𝓽𝓮𝔁𝓽";
const encoder = new TextEncoder();
const bytes = new Uint8Array(5);
@ -157,7 +157,7 @@ unitTest(function textEncodeInto3(): void {
]);
});
unitTest(function loneSurrogateEncodeInto(): void {
unitTest(function loneSurrogateEncodeInto() {
const fixture = "lone𝄞\ud888surrogate";
const encoder = new TextEncoder();
const bytes = new Uint8Array(20);
@ -174,7 +174,7 @@ unitTest(function loneSurrogateEncodeInto(): void {
]);
});
unitTest(function loneSurrogateEncodeInto2(): void {
unitTest(function loneSurrogateEncodeInto2() {
const fixture = "\ud800";
const encoder = new TextEncoder();
const bytes = new Uint8Array(3);
@ -187,7 +187,7 @@ unitTest(function loneSurrogateEncodeInto2(): void {
]);
});
unitTest(function loneSurrogateEncodeInto3(): void {
unitTest(function loneSurrogateEncodeInto3() {
const fixture = "\udc00";
const encoder = new TextEncoder();
const bytes = new Uint8Array(3);
@ -200,7 +200,7 @@ unitTest(function loneSurrogateEncodeInto3(): void {
]);
});
unitTest(function swappedSurrogatePairEncodeInto4(): void {
unitTest(function swappedSurrogatePairEncodeInto4() {
const fixture = "\udc00\ud800";
const encoder = new TextEncoder();
const bytes = new Uint8Array(8);
@ -213,7 +213,7 @@ unitTest(function swappedSurrogatePairEncodeInto4(): void {
]);
});
unitTest(function textDecoderSharedUint8Array(): void {
unitTest(function textDecoderSharedUint8Array() {
const ab = new SharedArrayBuffer(6);
const dataView = new DataView(ab);
const charCodeA = "A".charCodeAt(0);
@ -226,7 +226,7 @@ unitTest(function textDecoderSharedUint8Array(): void {
assertEquals(actual, "ABCDEF");
});
unitTest(function textDecoderSharedInt32Array(): void {
unitTest(function textDecoderSharedInt32Array() {
const ab = new SharedArrayBuffer(8);
const dataView = new DataView(ab);
const charCodeA = "A".charCodeAt(0);
@ -239,14 +239,14 @@ unitTest(function textDecoderSharedInt32Array(): void {
assertEquals(actual, "ABCDEFGH");
});
unitTest(function toStringShouldBeWebCompatibility(): void {
unitTest(function toStringShouldBeWebCompatibility() {
const encoder = new TextEncoder();
assertEquals(encoder.toString(), "[object TextEncoder]");
const decoder = new TextDecoder();
assertEquals(decoder.toString(), "[object TextDecoder]");
});
unitTest(function textEncoderShouldCoerceToString(): void {
unitTest(function textEncoderShouldCoerceToString() {
const encoder = new TextEncoder();
const fixutreText = "text";
const fixture = {

View file

@ -9,11 +9,11 @@ import {
unitTest,
} from "./test_util.ts";
unitTest(async function functionParameterBindingSuccess(): Promise<void> {
unitTest(async function functionParameterBindingSuccess() {
const promise = deferred();
let count = 0;
const nullProto = (newCount: number): void => {
const nullProto = (newCount: number) => {
count = newCount;
promise.resolve();
};
@ -26,7 +26,7 @@ unitTest(async function functionParameterBindingSuccess(): Promise<void> {
assertEquals(count, 1);
});
unitTest(async function stringifyAndEvalNonFunctions(): Promise<void> {
unitTest(async function stringifyAndEvalNonFunctions() {
// eval can only access global scope
const global = globalThis as unknown as {
globalPromise: ReturnType<typeof deferred>;
@ -50,10 +50,10 @@ unitTest(async function stringifyAndEvalNonFunctions(): Promise<void> {
Reflect.deleteProperty(global, "globalCount");
});
unitTest(async function timeoutSuccess(): Promise<void> {
unitTest(async function timeoutSuccess() {
const promise = deferred();
let count = 0;
setTimeout((): void => {
setTimeout(() => {
count++;
promise.resolve();
}, 500);
@ -62,7 +62,7 @@ unitTest(async function timeoutSuccess(): Promise<void> {
assertEquals(count, 1);
});
unitTest(async function timeoutEvalNoScopeLeak(): Promise<void> {
unitTest(async function timeoutEvalNoScopeLeak() {
// eval can only access global scope
const global = globalThis as unknown as {
globalPromise: Deferred<Error>;
@ -83,11 +83,11 @@ unitTest(async function timeoutEvalNoScopeLeak(): Promise<void> {
Reflect.deleteProperty(global, "globalPromise");
});
unitTest(async function timeoutArgs(): Promise<void> {
unitTest(async function timeoutArgs() {
const promise = deferred();
const arg = 1;
setTimeout(
(a, b, c): void => {
(a, b, c) => {
assertEquals(a, arg);
assertEquals(b, arg.toString());
assertEquals(c, [arg]);
@ -101,9 +101,9 @@ unitTest(async function timeoutArgs(): Promise<void> {
await promise;
});
unitTest(async function timeoutCancelSuccess(): Promise<void> {
unitTest(async function timeoutCancelSuccess() {
let count = 0;
const id = setTimeout((): void => {
const id = setTimeout(() => {
count++;
}, 1);
// Cancelled, count should not increment
@ -112,7 +112,7 @@ unitTest(async function timeoutCancelSuccess(): Promise<void> {
assertEquals(count, 0);
});
unitTest(async function timeoutCancelMultiple(): Promise<void> {
unitTest(async function timeoutCancelMultiple() {
function uncalled(): never {
throw new Error("This function should not be called.");
}
@ -137,11 +137,11 @@ unitTest(async function timeoutCancelMultiple(): Promise<void> {
await delay(50);
});
unitTest(async function timeoutCancelInvalidSilentFail(): Promise<void> {
unitTest(async function timeoutCancelInvalidSilentFail() {
// Expect no panic
const promise = deferred();
let count = 0;
const id = setTimeout((): void => {
const id = setTimeout(() => {
count++;
// Should have no effect
clearTimeout(id);
@ -154,10 +154,10 @@ unitTest(async function timeoutCancelInvalidSilentFail(): Promise<void> {
clearTimeout(2147483647);
});
unitTest(async function intervalSuccess(): Promise<void> {
unitTest(async function intervalSuccess() {
const promise = deferred();
let count = 0;
const id = setInterval((): void => {
const id = setInterval(() => {
count++;
clearInterval(id);
promise.resolve();
@ -172,9 +172,9 @@ unitTest(async function intervalSuccess(): Promise<void> {
await delay(0);
});
unitTest(async function intervalCancelSuccess(): Promise<void> {
unitTest(async function intervalCancelSuccess() {
let count = 0;
const id = setInterval((): void => {
const id = setInterval(() => {
count++;
}, 1);
clearInterval(id);
@ -182,10 +182,10 @@ unitTest(async function intervalCancelSuccess(): Promise<void> {
assertEquals(count, 0);
});
unitTest(async function intervalOrdering(): Promise<void> {
unitTest(async function intervalOrdering() {
const timers: number[] = [];
let timeouts = 0;
function onTimeout(): void {
function onTimeout() {
++timeouts;
for (let i = 1; i < timers.length; i++) {
clearTimeout(timers[i]);
@ -198,26 +198,24 @@ unitTest(async function intervalOrdering(): Promise<void> {
assertEquals(timeouts, 1);
});
unitTest(function intervalCancelInvalidSilentFail(): void {
unitTest(function intervalCancelInvalidSilentFail() {
// Should silently fail (no panic)
clearInterval(2147483647);
});
unitTest(async function fireCallbackImmediatelyWhenDelayOverMaxValue(): Promise<
void
> {
unitTest(async function fireCallbackImmediatelyWhenDelayOverMaxValue() {
let count = 0;
setTimeout((): void => {
setTimeout(() => {
count++;
}, 2 ** 31);
await delay(1);
assertEquals(count, 1);
});
unitTest(async function timeoutCallbackThis(): Promise<void> {
unitTest(async function timeoutCallbackThis() {
const promise = deferred();
const obj = {
foo(): void {
foo() {
assertEquals(this, window);
promise.resolve();
},
@ -226,7 +224,7 @@ unitTest(async function timeoutCallbackThis(): Promise<void> {
await promise;
});
unitTest(async function timeoutBindThis(): Promise<void> {
unitTest(async function timeoutBindThis() {
const thisCheckPassed = [null, undefined, window, globalThis];
const thisCheckFailed = [
@ -237,7 +235,7 @@ unitTest(async function timeoutBindThis(): Promise<void> {
{},
[],
"foo",
(): void => {},
() => {},
Object.prototype,
];
@ -274,7 +272,7 @@ unitTest(async function timeoutBindThis(): Promise<void> {
}
});
unitTest(function clearTimeoutShouldConvertToNumber(): void {
unitTest(function clearTimeoutShouldConvertToNumber() {
let called = false;
const obj = {
valueOf(): number {
@ -286,10 +284,10 @@ unitTest(function clearTimeoutShouldConvertToNumber(): void {
assert(called);
});
unitTest(function setTimeoutShouldThrowWithBigint(): void {
unitTest(function setTimeoutShouldThrowWithBigint() {
let hasThrown = 0;
try {
setTimeout((): void => {}, (1n as unknown) as number);
setTimeout(() => {}, (1n as unknown) as number);
hasThrown = 1;
} catch (err) {
if (err instanceof TypeError) {
@ -301,7 +299,7 @@ unitTest(function setTimeoutShouldThrowWithBigint(): void {
assertEquals(hasThrown, 2);
});
unitTest(function clearTimeoutShouldThrowWithBigint(): void {
unitTest(function clearTimeoutShouldThrowWithBigint() {
let hasThrown = 0;
try {
clearTimeout((1n as unknown) as number);
@ -316,23 +314,23 @@ unitTest(function clearTimeoutShouldThrowWithBigint(): void {
assertEquals(hasThrown, 2);
});
unitTest(function testFunctionName(): void {
unitTest(function testFunctionName() {
assertEquals(clearTimeout.name, "clearTimeout");
assertEquals(clearInterval.name, "clearInterval");
});
unitTest(function testFunctionParamsLength(): void {
unitTest(function testFunctionParamsLength() {
assertEquals(setTimeout.length, 1);
assertEquals(setInterval.length, 1);
assertEquals(clearTimeout.length, 0);
assertEquals(clearInterval.length, 0);
});
unitTest(function clearTimeoutAndClearIntervalNotBeEquals(): void {
unitTest(function clearTimeoutAndClearIntervalNotBeEquals() {
assertNotEquals(clearTimeout, clearInterval);
});
unitTest(async function timerMaxCpuBug(): Promise<void> {
unitTest(async function timerMaxCpuBug() {
// There was a bug where clearing a timeout would cause Deno to use 100% CPU.
clearTimeout(setTimeout(() => {}, 1000));
// We can check this by counting how many ops have triggered in the interim.
@ -343,7 +341,7 @@ unitTest(async function timerMaxCpuBug(): Promise<void> {
assert(opsDispatched_ - opsDispatched < 10);
});
unitTest(async function timerBasicMicrotaskOrdering(): Promise<void> {
unitTest(async function timerBasicMicrotaskOrdering() {
let s = "";
let count = 0;
const promise = deferred();
@ -367,7 +365,7 @@ unitTest(async function timerBasicMicrotaskOrdering(): Promise<void> {
assertEquals(s, "deno");
});
unitTest(async function timerNestedMicrotaskOrdering(): Promise<void> {
unitTest(async function timerNestedMicrotaskOrdering() {
let s = "";
const promise = deferred();
s += "0";
@ -407,7 +405,7 @@ unitTest(function testQueueMicrotask() {
assertEquals(typeof queueMicrotask, "function");
});
unitTest(async function timerIgnoresDateOverride(): Promise<void> {
unitTest(async function timerIgnoresDateOverride() {
const OriginalDate = Date;
const promise = deferred();
let hasThrown = 0;
@ -416,7 +414,7 @@ unitTest(async function timerIgnoresDateOverride(): Promise<void> {
promise.reject("global Date override used over original Date object");
return 0;
};
const DateOverride = (): void => {
const DateOverride = () => {
overrideCalled();
};
globalThis.Date = DateOverride as DateConstructor;
@ -441,7 +439,7 @@ unitTest(async function timerIgnoresDateOverride(): Promise<void> {
assertEquals(hasThrown, 1);
});
unitTest({ perms: { hrtime: true } }, function sleepSync(): void {
unitTest({ perms: { hrtime: true } }, function sleepSync() {
const start = performance.now();
Deno.sleepSync(10);
const after = performance.now();
@ -450,7 +448,7 @@ unitTest({ perms: { hrtime: true } }, function sleepSync(): void {
unitTest(
{ perms: { hrtime: true } },
async function sleepSyncShorterPromise(): Promise<void> {
async function sleepSyncShorterPromise() {
const perf = performance;
const short = 5;
const long = 10;
@ -469,7 +467,7 @@ unitTest(
unitTest(
{ perms: { hrtime: true } },
async function sleepSyncLongerPromise(): Promise<void> {
async function sleepSyncLongerPromise() {
const perf = performance;
const short = 5;
const long = 10;

View file

@ -16,7 +16,7 @@ import { TextProtoReader } from "../../../test_util/std/textproto/mod.ts";
const encoder = new TextEncoder();
const decoder = new TextDecoder();
async function sleep(msec: number): Promise<void> {
async function sleep(msec: number) {
await new Promise((res, _rej) => setTimeout(res, msec));
}
@ -24,7 +24,7 @@ function unreachable(): never {
throw new Error("Unreachable code reached");
}
unitTest(async function connectTLSNoPerm(): Promise<void> {
unitTest(async function connectTLSNoPerm() {
await assertThrowsAsync(async () => {
await Deno.connectTls({ hostname: "github.com", port: 443 });
}, Deno.errors.PermissionDenied);
@ -32,7 +32,7 @@ unitTest(async function connectTLSNoPerm(): Promise<void> {
unitTest(
{ perms: { read: true, net: true } },
async function connectTLSInvalidHost(): Promise<void> {
async function connectTLSInvalidHost() {
const listener = await Deno.listenTls({
hostname: "localhost",
port: 3567,
@ -48,7 +48,7 @@ unitTest(
},
);
unitTest(async function connectTLSCertFileNoReadPerm(): Promise<void> {
unitTest(async function connectTLSCertFileNoReadPerm() {
await assertThrowsAsync(async () => {
await Deno.connectTls({
hostname: "github.com",
@ -60,7 +60,7 @@ unitTest(async function connectTLSCertFileNoReadPerm(): Promise<void> {
unitTest(
{ perms: { read: true, net: true } },
function listenTLSNonExistentCertKeyFiles(): void {
function listenTLSNonExistentCertKeyFiles() {
const options = {
hostname: "localhost",
port: 3500,
@ -84,7 +84,7 @@ unitTest(
},
);
unitTest({ perms: { net: true } }, function listenTLSNoReadPerm(): void {
unitTest({ perms: { net: true } }, function listenTLSNoReadPerm() {
assertThrows(() => {
Deno.listenTls({
hostname: "localhost",
@ -99,7 +99,7 @@ unitTest(
{
perms: { read: true, write: true, net: true },
},
function listenTLSEmptyKeyFile(): void {
function listenTLSEmptyKeyFile() {
const options = {
hostname: "localhost",
port: 3500,
@ -124,7 +124,7 @@ unitTest(
unitTest(
{ perms: { read: true, write: true, net: true } },
function listenTLSEmptyCertFile(): void {
function listenTLSEmptyCertFile() {
const options = {
hostname: "localhost",
port: 3500,
@ -149,7 +149,7 @@ unitTest(
unitTest(
{ perms: { read: true, net: true } },
async function dialAndListenTLS(): Promise<void> {
async function dialAndListenTLS() {
const resolvable = deferred();
const hostname = "localhost";
const port = 3500;
@ -166,7 +166,7 @@ unitTest(
);
listener.accept().then(
async (conn): Promise<void> => {
async (conn) => {
assert(conn.remoteAddr != null);
assert(conn.localAddr != null);
await conn.write(response);
@ -242,7 +242,7 @@ async function sendThenCloseWriteThenReceive(
conn: Deno.Conn,
chunkCount: number,
chunkSize: number,
): Promise<void> {
) {
const byteCount = chunkCount * chunkSize;
const buf = new Uint8Array(chunkSize); // Note: buf is size of _chunk_.
let n: number;
@ -274,7 +274,7 @@ async function receiveThenSend(
conn: Deno.Conn,
chunkCount: number,
chunkSize: number,
): Promise<void> {
) {
const byteCount = chunkCount * chunkSize;
const buf = new Uint8Array(byteCount); // Note: buf size equals `byteCount`.
let n: number;
@ -301,7 +301,7 @@ async function receiveThenSend(
unitTest(
{ perms: { read: true, net: true } },
async function tlsServerStreamHalfCloseSendOneByte(): Promise<void> {
async function tlsServerStreamHalfCloseSendOneByte() {
const [serverConn, clientConn] = await tlsPair();
await Promise.all([
sendThenCloseWriteThenReceive(serverConn, 1, 1),
@ -312,7 +312,7 @@ unitTest(
unitTest(
{ perms: { read: true, net: true } },
async function tlsClientStreamHalfCloseSendOneByte(): Promise<void> {
async function tlsClientStreamHalfCloseSendOneByte() {
const [serverConn, clientConn] = await tlsPair();
await Promise.all([
sendThenCloseWriteThenReceive(clientConn, 1, 1),
@ -323,7 +323,7 @@ unitTest(
unitTest(
{ perms: { read: true, net: true } },
async function tlsServerStreamHalfCloseSendOneChunk(): Promise<void> {
async function tlsServerStreamHalfCloseSendOneChunk() {
const [serverConn, clientConn] = await tlsPair();
await Promise.all([
sendThenCloseWriteThenReceive(serverConn, 1, 1 << 20 /* 1 MB */),
@ -334,7 +334,7 @@ unitTest(
unitTest(
{ perms: { read: true, net: true } },
async function tlsClientStreamHalfCloseSendOneChunk(): Promise<void> {
async function tlsClientStreamHalfCloseSendOneChunk() {
const [serverConn, clientConn] = await tlsPair();
await Promise.all([
sendThenCloseWriteThenReceive(clientConn, 1, 1 << 20 /* 1 MB */),
@ -345,7 +345,7 @@ unitTest(
unitTest(
{ perms: { read: true, net: true } },
async function tlsServerStreamHalfCloseSendManyBytes(): Promise<void> {
async function tlsServerStreamHalfCloseSendManyBytes() {
const [serverConn, clientConn] = await tlsPair();
await Promise.all([
sendThenCloseWriteThenReceive(serverConn, 100, 1),
@ -356,7 +356,7 @@ unitTest(
unitTest(
{ perms: { read: true, net: true } },
async function tlsClientStreamHalfCloseSendManyBytes(): Promise<void> {
async function tlsClientStreamHalfCloseSendManyBytes() {
const [serverConn, clientConn] = await tlsPair();
await Promise.all([
sendThenCloseWriteThenReceive(clientConn, 100, 1),
@ -367,7 +367,7 @@ unitTest(
unitTest(
{ perms: { read: true, net: true } },
async function tlsServerStreamHalfCloseSendManyChunks(): Promise<void> {
async function tlsServerStreamHalfCloseSendManyChunks() {
const [serverConn, clientConn] = await tlsPair();
await Promise.all([
sendThenCloseWriteThenReceive(serverConn, 100, 1 << 16 /* 64 kB */),
@ -378,7 +378,7 @@ unitTest(
unitTest(
{ perms: { read: true, net: true } },
async function tlsClientStreamHalfCloseSendManyChunks(): Promise<void> {
async function tlsClientStreamHalfCloseSendManyChunks() {
const [serverConn, clientConn] = await tlsPair();
await Promise.all([
sendThenCloseWriteThenReceive(clientConn, 100, 1 << 16 /* 64 kB */),
@ -387,7 +387,7 @@ unitTest(
},
);
async function sendAlotReceiveNothing(conn: Deno.Conn): Promise<void> {
async function sendAlotReceiveNothing(conn: Deno.Conn) {
// Start receive op.
const readBuf = new Uint8Array(1024);
const readPromise = conn.read(readBuf);
@ -410,7 +410,7 @@ async function sendAlotReceiveNothing(conn: Deno.Conn): Promise<void> {
);
}
async function receiveAlotSendNothing(conn: Deno.Conn): Promise<void> {
async function receiveAlotSendNothing(conn: Deno.Conn) {
const readBuf = new Uint8Array(1024);
let n: number | null;
@ -428,7 +428,7 @@ async function receiveAlotSendNothing(conn: Deno.Conn): Promise<void> {
unitTest(
{ perms: { read: true, net: true } },
async function tlsServerStreamCancelRead(): Promise<void> {
async function tlsServerStreamCancelRead() {
const [serverConn, clientConn] = await tlsPair();
await Promise.all([
sendAlotReceiveNothing(serverConn),
@ -439,7 +439,7 @@ unitTest(
unitTest(
{ perms: { read: true, net: true } },
async function tlsClientStreamCancelRead(): Promise<void> {
async function tlsClientStreamCancelRead() {
const [serverConn, clientConn] = await tlsPair();
await Promise.all([
sendAlotReceiveNothing(clientConn),
@ -448,7 +448,7 @@ unitTest(
},
);
async function sendReceiveEmptyBuf(conn: Deno.Conn): Promise<void> {
async function sendReceiveEmptyBuf(conn: Deno.Conn) {
const byteBuf = new Uint8Array([1]);
const emptyBuf = new Uint8Array(0);
let n: number | null;
@ -485,7 +485,7 @@ async function sendReceiveEmptyBuf(conn: Deno.Conn): Promise<void> {
unitTest(
{ perms: { read: true, net: true } },
async function tlsStreamSendReceiveEmptyBuf(): Promise<void> {
async function tlsStreamSendReceiveEmptyBuf() {
const [serverConn, clientConn] = await tlsPair();
await Promise.all([
sendReceiveEmptyBuf(serverConn),
@ -494,12 +494,12 @@ unitTest(
},
);
function immediateClose(conn: Deno.Conn): Promise<void> {
function immediateClose(conn: Deno.Conn) {
conn.close();
return Promise.resolve();
}
async function closeWriteAndClose(conn: Deno.Conn): Promise<void> {
async function closeWriteAndClose(conn: Deno.Conn) {
await conn.closeWrite();
if (await conn.read(new Uint8Array(1)) !== null) {
@ -511,7 +511,7 @@ async function closeWriteAndClose(conn: Deno.Conn): Promise<void> {
unitTest(
{ perms: { read: true, net: true } },
async function tlsServerStreamImmediateClose(): Promise<void> {
async function tlsServerStreamImmediateClose() {
const [serverConn, clientConn] = await tlsPair();
await Promise.all([
immediateClose(serverConn),
@ -522,7 +522,7 @@ unitTest(
unitTest(
{ perms: { read: true, net: true } },
async function tlsClientStreamImmediateClose(): Promise<void> {
async function tlsClientStreamImmediateClose() {
const [serverConn, clientConn] = await tlsPair();
await Promise.all([
closeWriteAndClose(serverConn),
@ -533,7 +533,7 @@ unitTest(
unitTest(
{ perms: { read: true, net: true } },
async function tlsClientAndServerStreamImmediateClose(): Promise<void> {
async function tlsClientAndServerStreamImmediateClose() {
const [serverConn, clientConn] = await tlsPair();
await Promise.all([
immediateClose(serverConn),
@ -547,7 +547,7 @@ async function tlsWithTcpFailureTestImpl(
cipherByteCount: number,
failureMode: "corruption" | "shutdown",
reverse: boolean,
): Promise<void> {
) {
const tlsPort = getPort();
const tlsListener = Deno.listenTls({
hostname: "localhost",
@ -723,7 +723,7 @@ async function tlsWithTcpFailureTestImpl(
conn: Deno.Conn,
byte: number,
count: number,
): Promise<void> {
) {
let buf = new Uint8Array(1 << 12 /* 4 kB */);
buf.fill(byte);
@ -739,7 +739,7 @@ async function tlsWithTcpFailureTestImpl(
conn: Deno.Conn,
byte: number,
count: number,
): Promise<void> {
) {
let buf = new Uint8Array(1 << 12 /* 4 kB */);
while (count > 0) {
buf = buf.subarray(0, Math.min(buf.length, count));
@ -761,7 +761,7 @@ async function tlsWithTcpFailureTestImpl(
sink: Deno.Conn,
count: number,
interruptPromise: Deferred<void>,
): Promise<void> {
) {
let buf = new Uint8Array(1 << 12 /* 4 kB */);
while (count > 0) {
buf = buf.subarray(0, Math.min(buf.length, count));
@ -913,7 +913,7 @@ async function curl(url: string): Promise<string> {
unitTest(
{ perms: { read: true, net: true, run: true } },
async function curlFakeHttpsServer(): Promise<void> {
async function curlFakeHttpsServer() {
const port = getPort();
const listener = createHttpsListener(port);
@ -937,7 +937,7 @@ unitTest(
unitTest(
{ perms: { read: true, net: true } },
async function startTls(): Promise<void> {
async function startTls() {
const hostname = "smtp.gmail.com";
const port = 587;
const encoder = new TextEncoder();

Some files were not shown because too many files have changed in this diff Show more