summaryrefslogtreecommitdiff
path: root/std
diff options
context:
space:
mode:
Diffstat (limited to 'std')
-rw-r--r--std/encoding/binary_test.ts10
-rw-r--r--std/encoding/yaml/example/sample_document.ts2
-rw-r--r--std/examples/chat/server.ts2
-rw-r--r--std/examples/chat/server_test.ts2
-rw-r--r--std/fs/copy_test.ts5
-rw-r--r--std/fs/exists.ts17
-rw-r--r--std/fs/walk_test.ts4
-rwxr-xr-xstd/http/file_server.ts10
-rw-r--r--std/http/io.ts4
-rw-r--r--std/http/mock.ts8
-rw-r--r--std/http/server_test.ts2
-rw-r--r--std/io/bufio.ts1
-rw-r--r--std/io/bufio_test.ts6
-rw-r--r--std/io/iotest.ts14
-rw-r--r--std/io/ioutil_test.ts8
-rw-r--r--std/io/readers.ts6
-rw-r--r--std/io/writers.ts4
-rw-r--r--std/node/_fs/_fs_close.ts2
-rw-r--r--std/node/_fs/_fs_close_test.ts2
-rw-r--r--std/node/_fs/_fs_dir_test.ts4
-rw-r--r--std/testing/bench.ts3
-rw-r--r--std/textproto/reader_test.ts3
-rw-r--r--std/textproto/test.ts2
-rw-r--r--std/util/async_test.ts7
-rw-r--r--std/ws/mod.ts4
-rw-r--r--std/ws/test.ts12
26 files changed, 75 insertions, 69 deletions
diff --git a/std/encoding/binary_test.ts b/std/encoding/binary_test.ts
index 936fcbb63..54f8cbded 100644
--- a/std/encoding/binary_test.ts
+++ b/std/encoding/binary_test.ts
@@ -24,12 +24,12 @@ Deno.test(async function testGetNBytes(): Promise<void> {
Deno.test(async function testGetNBytesThrows(): Promise<void> {
const data = new Uint8Array([1, 2, 3, 4]);
const buff = new Deno.Buffer(data.buffer);
- assertThrowsAsync(async () => {
+ await assertThrowsAsync(async () => {
await getNBytes(buff, 8);
}, Deno.errors.UnexpectedEof);
});
-Deno.test(async function testPutVarbig(): Promise<void> {
+Deno.test(function testPutVarbig(): void {
const buff = new Uint8Array(8);
putVarbig(buff, 0xffeeddccbbaa9988n);
assertEquals(
@@ -38,7 +38,7 @@ Deno.test(async function testPutVarbig(): Promise<void> {
);
});
-Deno.test(async function testPutVarbigLittleEndian(): Promise<void> {
+Deno.test(function testPutVarbigLittleEndian(): void {
const buff = new Uint8Array(8);
putVarbig(buff, 0x8899aabbccddeeffn, { endian: "little" });
assertEquals(
@@ -47,13 +47,13 @@ Deno.test(async function testPutVarbigLittleEndian(): Promise<void> {
);
});
-Deno.test(async function testPutVarnum(): Promise<void> {
+Deno.test(function testPutVarnum(): void {
const buff = new Uint8Array(4);
putVarnum(buff, 0xffeeddcc);
assertEquals(buff, new Uint8Array([0xff, 0xee, 0xdd, 0xcc]));
});
-Deno.test(async function testPutVarnumLittleEndian(): Promise<void> {
+Deno.test(function testPutVarnumLittleEndian(): void {
const buff = new Uint8Array(4);
putVarnum(buff, 0xccddeeff, { endian: "little" });
assertEquals(buff, new Uint8Array([0xff, 0xee, 0xdd, 0xcc]));
diff --git a/std/encoding/yaml/example/sample_document.ts b/std/encoding/yaml/example/sample_document.ts
index c9372e8ec..da969d679 100644
--- a/std/encoding/yaml/example/sample_document.ts
+++ b/std/encoding/yaml/example/sample_document.ts
@@ -5,7 +5,7 @@ import { parse } from "../../yaml.ts";
const { readFileSync, cwd } = Deno;
-(async () => {
+(() => {
const yml = readFileSync(`${cwd()}/example/sample_document.yml`);
const document = new TextDecoder().decode(yml);
diff --git a/std/examples/chat/server.ts b/std/examples/chat/server.ts
index 3c968e44e..08aede05b 100644
--- a/std/examples/chat/server.ts
+++ b/std/examples/chat/server.ts
@@ -8,7 +8,7 @@ import {
const clients = new Map<number, WebSocket>();
let clientId = 0;
-async function dispatch(msg: string): Promise<void> {
+function dispatch(msg: string): void {
for (const client of clients.values()) {
client.send(msg);
}
diff --git a/std/examples/chat/server_test.ts b/std/examples/chat/server_test.ts
index 899eb1b32..0d21b3787 100644
--- a/std/examples/chat/server_test.ts
+++ b/std/examples/chat/server_test.ts
@@ -18,7 +18,7 @@ async function startServer(): Promise<Deno.Process> {
const r = new TextProtoReader(new BufReader(server.stdout));
const s = await r.readLine();
assert(s !== Deno.EOF && s.includes("chat server starting"));
- } catch {
+ } catch (err) {
server.stdout!.close();
server.close();
}
diff --git a/std/fs/copy_test.ts b/std/fs/copy_test.ts
index fb8827f0c..9ba5f2b21 100644
--- a/std/fs/copy_test.ts
+++ b/std/fs/copy_test.ts
@@ -17,10 +17,7 @@ const testdataDir = path.resolve("fs", "testdata");
// TODO(axetroy): Add test for Windows once symlink is implemented for Windows.
const isWindows = Deno.build.os === "win";
-async function testCopy(
- name: string,
- cb: (tempDir: string) => Promise<void>
-): Promise<void> {
+function testCopy(name: string, cb: (tempDir: string) => Promise<void>): void {
Deno.test({
name,
async fn(): Promise<void> {
diff --git a/std/fs/exists.ts b/std/fs/exists.ts
index ae64cb1f3..f9e5a0925 100644
--- a/std/fs/exists.ts
+++ b/std/fs/exists.ts
@@ -4,15 +4,16 @@ const { lstat, lstatSync } = Deno;
* Test whether or not the given path exists by checking with the file system
*/
export async function exists(filePath: string): Promise<boolean> {
- return lstat(filePath)
- .then((): boolean => true)
- .catch((err: Error): boolean => {
- if (err instanceof Deno.errors.NotFound) {
- return false;
- }
+ try {
+ await lstat(filePath);
+ return true;
+ } catch (err) {
+ if (err instanceof Deno.errors.NotFound) {
+ return false;
+ }
- throw err;
- });
+ throw err;
+ }
}
/**
diff --git a/std/fs/walk_test.ts b/std/fs/walk_test.ts
index c2518cee3..96bfcae67 100644
--- a/std/fs/walk_test.ts
+++ b/std/fs/walk_test.ts
@@ -5,11 +5,11 @@ import { assert, assertEquals, assertThrowsAsync } from "../testing/asserts.ts";
const isWindows = Deno.build.os == "win";
-export async function testWalk(
+export function testWalk(
setup: (arg0: string) => void | Promise<void>,
t: Deno.TestFunction,
ignore = false
-): Promise<void> {
+): void {
const name = t.name;
async function fn(): Promise<void> {
const origCwd = cwd();
diff --git a/std/http/file_server.ts b/std/http/file_server.ts
index 18a68aa49..20d5d61e6 100755
--- a/std/http/file_server.ts
+++ b/std/http/file_server.ts
@@ -158,17 +158,17 @@ async function serveDir(
return res;
}
-async function serveFallback(req: ServerRequest, e: Error): Promise<Response> {
+function serveFallback(req: ServerRequest, e: Error): Promise<Response> {
if (e instanceof Deno.errors.NotFound) {
- return {
+ return Promise.resolve({
status: 404,
body: encoder.encode("Not found")
- };
+ });
} else {
- return {
+ return Promise.resolve({
status: 500,
body: encoder.encode("Internal server error")
- };
+ });
}
}
diff --git a/std/http/io.ts b/std/http/io.ts
index 5518146a8..6d5d1f665 100644
--- a/std/http/io.ts
+++ b/std/http/io.ts
@@ -7,8 +7,8 @@ import { STATUS_TEXT } from "./http_status.ts";
export function emptyReader(): Deno.Reader {
return {
- async read(_: Uint8Array): Promise<number | Deno.EOF> {
- return Deno.EOF;
+ read(_: Uint8Array): Promise<number | Deno.EOF> {
+ return Promise.resolve(Deno.EOF);
}
};
}
diff --git a/std/http/mock.ts b/std/http/mock.ts
index 3a4eeed82..cee697bed 100644
--- a/std/http/mock.ts
+++ b/std/http/mock.ts
@@ -14,11 +14,11 @@ export function mockConn(base: Partial<Deno.Conn> = {}): Deno.Conn {
rid: -1,
closeRead: (): void => {},
closeWrite: (): void => {},
- read: async (): Promise<number | Deno.EOF> => {
- return 0;
+ read: (): Promise<number | Deno.EOF> => {
+ return Promise.resolve(0);
},
- write: async (): Promise<number> => {
- return -1;
+ write: (): Promise<number> => {
+ return Promise.resolve(-1);
},
close: (): void => {},
...base
diff --git a/std/http/server_test.ts b/std/http/server_test.ts
index 0a4986dcf..2a7c46134 100644
--- a/std/http/server_test.ts
+++ b/std/http/server_test.ts
@@ -68,7 +68,7 @@ test(async function responseWrite(): Promise<void> {
}
});
-test(async function requestContentLength(): Promise<void> {
+test(function requestContentLength(): void {
// Has content length
{
const req = new ServerRequest();
diff --git a/std/io/bufio.ts b/std/io/bufio.ts
index 12b5c2d2b..a944adfed 100644
--- a/std/io/bufio.ts
+++ b/std/io/bufio.ts
@@ -602,6 +602,7 @@ export async function* readStringDelim(
}
/** Read strings line-by-line from a Reader. */
+// eslint-disable-next-line require-await
export async function* readLines(
reader: Reader
): AsyncIterableIterator<string> {
diff --git a/std/io/bufio_test.ts b/std/io/bufio_test.ts
index d925175f1..ae38f6667 100644
--- a/std/io/bufio_test.ts
+++ b/std/io/bufio_test.ts
@@ -191,7 +191,7 @@ const testOutput = encoder.encode("0123456789abcdefghijklmnopqrstuvwxy");
class TestReader implements Reader {
constructor(private data: Uint8Array, private stride: number) {}
- async read(buf: Uint8Array): Promise<number | Deno.EOF> {
+ read(buf: Uint8Array): Promise<number | Deno.EOF> {
let nread = this.stride;
if (nread > this.data.byteLength) {
nread = this.data.byteLength;
@@ -200,11 +200,11 @@ class TestReader implements Reader {
nread = buf.byteLength;
}
if (nread === 0) {
- return Deno.EOF;
+ return Promise.resolve(Deno.EOF);
}
copyBytes(buf as Uint8Array, this.data);
this.data = this.data.subarray(nread);
- return nread;
+ return Promise.resolve(nread);
}
}
diff --git a/std/io/iotest.ts b/std/io/iotest.ts
index 1e922e33f..e2cf315aa 100644
--- a/std/io/iotest.ts
+++ b/std/io/iotest.ts
@@ -10,14 +10,14 @@ type Reader = Deno.Reader;
export class OneByteReader implements Reader {
constructor(readonly r: Reader) {}
- async read(p: Uint8Array): Promise<number | Deno.EOF> {
+ read(p: Uint8Array): Promise<number | Deno.EOF> {
if (p.byteLength === 0) {
- return 0;
+ return Promise.resolve(0);
}
if (!(p instanceof Uint8Array)) {
throw Error("expected Uint8Array");
}
- return this.r.read(p.subarray(0, 1));
+ return Promise.resolve(this.r.read(p.subarray(0, 1)));
}
}
@@ -27,12 +27,12 @@ export class OneByteReader implements Reader {
export class HalfReader implements Reader {
constructor(readonly r: Reader) {}
- async read(p: Uint8Array): Promise<number | Deno.EOF> {
+ read(p: Uint8Array): Promise<number | Deno.EOF> {
if (!(p instanceof Uint8Array)) {
throw Error("expected Uint8Array");
}
const half = Math.floor((p.byteLength + 1) / 2);
- return this.r.read(p.subarray(0, half));
+ return Promise.resolve(this.r.read(p.subarray(0, half)));
}
}
@@ -43,11 +43,11 @@ export class TimeoutReader implements Reader {
count = 0;
constructor(readonly r: Reader) {}
- async read(p: Uint8Array): Promise<number | Deno.EOF> {
+ read(p: Uint8Array): Promise<number | Deno.EOF> {
this.count++;
if (this.count === 2) {
throw new Deno.errors.TimedOut();
}
- return this.r.read(p);
+ return Promise.resolve(this.r.read(p));
}
}
diff --git a/std/io/ioutil_test.ts b/std/io/ioutil_test.ts
index 261f4def0..3d85a0fa1 100644
--- a/std/io/ioutil_test.ts
+++ b/std/io/ioutil_test.ts
@@ -17,10 +17,10 @@ class BinaryReader implements Reader {
constructor(private bytes: Uint8Array = new Uint8Array(0)) {}
- async read(p: Uint8Array): Promise<number | Deno.EOF> {
+ read(p: Uint8Array): Promise<number | Deno.EOF> {
p.set(this.bytes.subarray(this.index, p.byteLength));
this.index += p.byteLength;
- return p.byteLength;
+ return Promise.resolve(p.byteLength);
}
}
@@ -52,7 +52,7 @@ Deno.test(async function testReadLong2(): Promise<void> {
assertEquals(long, 0x12345678);
});
-Deno.test(async function testSliceLongToBytes(): Promise<void> {
+Deno.test(function testSliceLongToBytes(): void {
const arr = sliceLongToBytes(0x1234567890abcdef);
const actual = readLong(new BufReader(new BinaryReader(new Uint8Array(arr))));
const expected = readLong(
@@ -65,7 +65,7 @@ Deno.test(async function testSliceLongToBytes(): Promise<void> {
assertEquals(actual, expected);
});
-Deno.test(async function testSliceLongToBytes2(): Promise<void> {
+Deno.test(function testSliceLongToBytes2(): void {
const arr = sliceLongToBytes(0x12345678);
assertEquals(arr, [0, 0, 0, 0, 0x12, 0x34, 0x56, 0x78]);
});
diff --git a/std/io/readers.ts b/std/io/readers.ts
index 5b1bf1948..2d81e246f 100644
--- a/std/io/readers.ts
+++ b/std/io/readers.ts
@@ -9,14 +9,14 @@ export class StringReader implements Reader {
constructor(private readonly s: string) {}
- async read(p: Uint8Array): Promise<number | Deno.EOF> {
+ read(p: Uint8Array): Promise<number | Deno.EOF> {
const n = Math.min(p.byteLength, this.buf.byteLength - this.offs);
p.set(this.buf.slice(this.offs, this.offs + n));
this.offs += n;
if (n === 0) {
- return Deno.EOF;
+ return Promise.resolve(Deno.EOF);
}
- return n;
+ return Promise.resolve(n);
}
}
diff --git a/std/io/writers.ts b/std/io/writers.ts
index 722e0297f..b9a6a5e70 100644
--- a/std/io/writers.ts
+++ b/std/io/writers.ts
@@ -14,11 +14,11 @@ export class StringWriter implements Writer {
this.byteLength += c.byteLength;
}
- async write(p: Uint8Array): Promise<number> {
+ write(p: Uint8Array): Promise<number> {
this.chunks.push(p);
this.byteLength += p.byteLength;
this.cache = undefined;
- return p.byteLength;
+ return Promise.resolve(p.byteLength);
}
toString(): string {
diff --git a/std/node/_fs/_fs_close.ts b/std/node/_fs/_fs_close.ts
index e19eb932e..4ec10eefb 100644
--- a/std/node/_fs/_fs_close.ts
+++ b/std/node/_fs/_fs_close.ts
@@ -3,7 +3,7 @@
import { CallbackWithError } from "./_fs_common.ts";
export function close(fd: number, callback: CallbackWithError): void {
- new Promise(async (resolve, reject) => {
+ new Promise((resolve, reject) => {
try {
Deno.close(fd);
resolve();
diff --git a/std/node/_fs/_fs_close_test.ts b/std/node/_fs/_fs_close_test.ts
index 2c7117248..7c6dd684c 100644
--- a/std/node/_fs/_fs_close_test.ts
+++ b/std/node/_fs/_fs_close_test.ts
@@ -16,7 +16,7 @@ test({
else resolve();
});
})
- .then(async () => {
+ .then(() => {
assert(!Deno.resources()[file.rid]);
})
.catch(() => {
diff --git a/std/node/_fs/_fs_dir_test.ts b/std/node/_fs/_fs_dir_test.ts
index 3b8c5b341..be276887b 100644
--- a/std/node/_fs/_fs_dir_test.ts
+++ b/std/node/_fs/_fs_dir_test.ts
@@ -5,7 +5,7 @@ import Dirent from "./_fs_dirent.ts";
test({
name: "Closing current directory with callback is successful",
- async fn() {
+ fn() {
let calledBack = false;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
new Dir(".").close((valOrErr: any) => {
@@ -25,7 +25,7 @@ test({
test({
name: "Closing current directory synchronously works",
- async fn() {
+ fn() {
new Dir(".").closeSync();
}
});
diff --git a/std/testing/bench.ts b/std/testing/bench.ts
index 5cec3ea39..1c4b01c0b 100644
--- a/std/testing/bench.ts
+++ b/std/testing/bench.ts
@@ -169,11 +169,12 @@ export async function runBenchmarks({
}
/** Runs specified benchmarks if the enclosing script is main. */
-export async function runIfMain(
+export function runIfMain(
meta: ImportMeta,
opts: BenchmarkRunOptions = {}
): Promise<void> {
if (meta.main) {
return runBenchmarks(opts);
}
+ return Promise.resolve(undefined);
}
diff --git a/std/textproto/reader_test.ts b/std/textproto/reader_test.ts
index 7aead064b..f0ae63894 100644
--- a/std/textproto/reader_test.ts
+++ b/std/textproto/reader_test.ts
@@ -21,9 +21,10 @@ function reader(s: string): TextProtoReader {
test({
ignore: true,
name: "[textproto] Reader : DotBytes",
- async fn(): Promise<void> {
+ fn(): Promise<void> {
const _input =
"dotlines\r\n.foo\r\n..bar\n...baz\nquux\r\n\r\n.\r\nanot.her\r\n";
+ return Promise.resolve();
}
});
diff --git a/std/textproto/test.ts b/std/textproto/test.ts
index 5b67bbf95..9a992a2cf 100644
--- a/std/textproto/test.ts
+++ b/std/textproto/test.ts
@@ -7,7 +7,7 @@ import { append } from "./mod.ts";
import { assertEquals } from "../testing/asserts.ts";
const { test } = Deno;
-test(async function textprotoAppend(): Promise<void> {
+test(function textprotoAppend(): void {
const enc = new TextEncoder();
const dec = new TextDecoder();
const u1 = enc.encode("Hello ");
diff --git a/std/util/async_test.ts b/std/util/async_test.ts
index 4607cf6cd..d81b52b43 100644
--- a/std/util/async_test.ts
+++ b/std/util/async_test.ts
@@ -3,17 +3,20 @@ const { test } = Deno;
import { assert, assertEquals, assertStrictEq } from "../testing/asserts.ts";
import { collectUint8Arrays, deferred, MuxAsyncIterator } from "./async.ts";
-test(async function asyncDeferred(): Promise<void> {
+test(function asyncDeferred(): Promise<void> {
const d = deferred<number>();
d.resolve(12);
+ return Promise.resolve();
});
+// eslint-disable-next-line require-await
async function* gen123(): AsyncIterableIterator<number> {
yield 1;
yield 2;
yield 3;
}
+// eslint-disable-next-line require-await
async function* gen456(): AsyncIterableIterator<number> {
yield 4;
yield 5;
@@ -47,6 +50,7 @@ test(async function collectUint8Arrays0(): Promise<void> {
test(async function collectUint8Arrays1(): Promise<void> {
const buf = new Uint8Array([1, 2, 3]);
+ // eslint-disable-next-line require-await
async function* gen(): AsyncIterableIterator<Uint8Array> {
yield buf;
}
@@ -56,6 +60,7 @@ test(async function collectUint8Arrays1(): Promise<void> {
});
test(async function collectUint8Arrays4(): Promise<void> {
+ // eslint-disable-next-line require-await
async function* gen(): AsyncIterableIterator<Uint8Array> {
yield new Uint8Array([1, 2, 3]);
yield new Uint8Array([]);
diff --git a/std/ws/mod.ts b/std/ws/mod.ts
index 809654a06..3332ed8dd 100644
--- a/std/ws/mod.ts
+++ b/std/ws/mod.ts
@@ -322,7 +322,7 @@ class WebSocketImpl implements WebSocket {
return d;
}
- async send(data: WebSocketMessage): Promise<void> {
+ send(data: WebSocketMessage): Promise<void> {
const opcode =
typeof data === "string" ? OpCode.TextFrame : OpCode.BinaryFrame;
const payload = typeof data === "string" ? encode(data) : data;
@@ -336,7 +336,7 @@ class WebSocketImpl implements WebSocket {
return this.enqueue(frame);
}
- async ping(data: WebSocketMessage = ""): Promise<void> {
+ ping(data: WebSocketMessage = ""): Promise<void> {
const payload = typeof data === "string" ? encode(data) : data;
const frame = {
isLastFrame: true,
diff --git a/std/ws/test.ts b/std/ws/test.ts
index 820fe1423..f1efa8e40 100644
--- a/std/ws/test.ts
+++ b/std/ws/test.ts
@@ -126,7 +126,7 @@ test("[ws] read unmasked bigger binary frame", async () => {
assertEquals(bin.payload.length, payloadLength);
});
-test("[ws] createSecAccept", async () => {
+test("[ws] createSecAccept", () => {
const nonce = "dGhlIHNhbXBsZSBub25jZQ==";
const d = createSecAccept(nonce);
assertEquals(d, "s3pPLMBiTxaQ9kYGzzhZRbK+xOo=");
@@ -335,8 +335,8 @@ test("[ws] createSecKeyHasCorrectLength", () => {
test("[ws] WebSocket should throw `Deno.errors.ConnectionReset` when peer closed connection without close frame", async () => {
const buf = new Buffer();
const eofReader: Deno.Reader = {
- async read(_: Uint8Array): Promise<number | Deno.EOF> {
- return Deno.EOF;
+ read(_: Uint8Array): Promise<number | Deno.EOF> {
+ return Promise.resolve(Deno.EOF);
}
};
const conn = dummyConn(eofReader, buf);
@@ -353,8 +353,8 @@ test("[ws] WebSocket should throw `Deno.errors.ConnectionReset` when peer closed
test("[ws] WebSocket shouldn't throw `Deno.errors.UnexpectedEof` on recive()", async () => {
const buf = new Buffer();
const eofReader: Deno.Reader = {
- async read(_: Uint8Array): Promise<number | Deno.EOF> {
- return Deno.EOF;
+ read(_: Uint8Array): Promise<number | Deno.EOF> {
+ return Promise.resolve(Deno.EOF);
}
};
const conn = dummyConn(eofReader, buf);
@@ -372,7 +372,7 @@ test({
const buf = new Buffer();
let timer: number | undefined;
const lazyWriter: Deno.Writer = {
- async write(_: Uint8Array): Promise<number> {
+ write(_: Uint8Array): Promise<number> {
return new Promise(resolve => {
timer = setTimeout(() => resolve(0), 1000);
});