mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 09:31:22 -05:00
Add require-await lint rule (#4401)
This commit is contained in:
parent
35f6e2e45d
commit
798904b0f2
67 changed files with 197 additions and 197 deletions
|
@ -22,7 +22,8 @@
|
|||
],
|
||||
"@typescript-eslint/ban-ts-ignore": ["off"],
|
||||
"@typescript-eslint/no-empty-function": ["off"],
|
||||
"no-return-await": "error"
|
||||
"no-return-await": "error",
|
||||
"require-await": "error"
|
||||
},
|
||||
"overrides": [
|
||||
{
|
||||
|
|
|
@ -106,7 +106,7 @@ export class Buffer implements Reader, SyncReader, Writer, SyncWriter {
|
|||
return nread;
|
||||
}
|
||||
|
||||
async read(p: Uint8Array): Promise<number | EOF> {
|
||||
read(p: Uint8Array): Promise<number | EOF> {
|
||||
const rr = this.readSync(p);
|
||||
return Promise.resolve(rr);
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ export class Buffer implements Reader, SyncReader, Writer, SyncWriter {
|
|||
return copyBytes(this.buf, p, m);
|
||||
}
|
||||
|
||||
async write(p: Uint8Array): Promise<number> {
|
||||
write(p: Uint8Array): Promise<number> {
|
||||
const n = this.writeSync(p);
|
||||
return Promise.resolve(n);
|
||||
}
|
||||
|
|
|
@ -302,7 +302,7 @@ async function runtimeCompile(
|
|||
}
|
||||
}
|
||||
|
||||
async function runtimeTranspile(
|
||||
function runtimeTranspile(
|
||||
request: CompilerRequestRuntimeTranspile
|
||||
): Promise<Record<string, TranspileOnlyResult>> {
|
||||
const result: Record<string, TranspileOnlyResult> = {};
|
||||
|
@ -325,7 +325,7 @@ async function runtimeTranspile(
|
|||
);
|
||||
result[fileName] = { source, map };
|
||||
}
|
||||
return result;
|
||||
return Promise.resolve(result);
|
||||
}
|
||||
|
||||
async function tsCompilerOnMessage({
|
||||
|
|
|
@ -15,7 +15,7 @@ export interface FetchResponse {
|
|||
headers: Array<[string, string]>;
|
||||
}
|
||||
|
||||
export async function fetch(
|
||||
export function fetch(
|
||||
args: FetchRequest,
|
||||
body: ArrayBufferView | undefined
|
||||
): Promise<FetchResponse> {
|
||||
|
|
|
@ -11,9 +11,7 @@ export function makeTempDirSync(options: MakeTempOptions = {}): string {
|
|||
return sendSync("op_make_temp_dir", options);
|
||||
}
|
||||
|
||||
export async function makeTempDir(
|
||||
options: MakeTempOptions = {}
|
||||
): Promise<string> {
|
||||
export function makeTempDir(options: MakeTempOptions = {}): Promise<string> {
|
||||
return sendAsync("op_make_temp_dir", options);
|
||||
}
|
||||
|
||||
|
@ -21,8 +19,6 @@ export function makeTempFileSync(options: MakeTempOptions = {}): string {
|
|||
return sendSync("op_make_temp_file", options);
|
||||
}
|
||||
|
||||
export async function makeTempFile(
|
||||
options: MakeTempOptions = {}
|
||||
): Promise<string> {
|
||||
export function makeTempFile(options: MakeTempOptions = {}): Promise<string> {
|
||||
return sendAsync("op_make_temp_file", options);
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ export function openSync(
|
|||
return sendSync("op_open", { path, options, openMode, mode });
|
||||
}
|
||||
|
||||
export async function open(
|
||||
export function open(
|
||||
path: string,
|
||||
openMode: OpenMode | undefined,
|
||||
options: OpenOptions | undefined
|
||||
|
|
|
@ -5,6 +5,6 @@ export function readlinkSync(path: string): string {
|
|||
return sendSync("op_read_link", { path });
|
||||
}
|
||||
|
||||
export async function readlink(path: string): Promise<string> {
|
||||
export function readlink(path: string): Promise<string> {
|
||||
return sendAsync("op_read_link", { path });
|
||||
}
|
||||
|
|
|
@ -5,6 +5,6 @@ export function realpathSync(path: string): string {
|
|||
return sendSync("op_realpath", { path });
|
||||
}
|
||||
|
||||
export async function realpath(path: string): Promise<string> {
|
||||
export function realpath(path: string): Promise<string> {
|
||||
return sendAsync("op_realpath", { path });
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ export function seekSync(
|
|||
return sendSync("op_seek", { rid, offset, whence });
|
||||
}
|
||||
|
||||
export async function seek(
|
||||
export function seek(
|
||||
rid: number,
|
||||
offset: number,
|
||||
whence: SeekMode
|
||||
|
|
|
@ -15,15 +15,15 @@ class FsEvents implements AsyncIterableIterator<FsEvent> {
|
|||
this.rid = sendSync("op_fs_events_open", { recursive, paths });
|
||||
}
|
||||
|
||||
async next(): Promise<IteratorResult<FsEvent>> {
|
||||
next(): Promise<IteratorResult<FsEvent>> {
|
||||
return sendAsync("op_fs_events_poll", {
|
||||
rid: this.rid
|
||||
});
|
||||
}
|
||||
|
||||
async return(value?: FsEvent): Promise<IteratorResult<FsEvent>> {
|
||||
return(value?: FsEvent): Promise<IteratorResult<FsEvent>> {
|
||||
close(this.rid);
|
||||
return { value, done: true };
|
||||
return Promise.resolve({ value, done: true });
|
||||
}
|
||||
|
||||
[Symbol.asyncIterator](): AsyncIterableIterator<FsEvent> {
|
||||
|
|
|
@ -31,7 +31,7 @@ interface AcceptResponse {
|
|||
};
|
||||
}
|
||||
|
||||
export async function accept(rid: number): Promise<AcceptResponse> {
|
||||
export function accept(rid: number): Promise<AcceptResponse> {
|
||||
return sendAsync("op_accept", { rid });
|
||||
}
|
||||
|
||||
|
@ -74,7 +74,7 @@ export interface ConnectRequest {
|
|||
port: number;
|
||||
}
|
||||
|
||||
export async function connect(args: ConnectRequest): Promise<ConnectResponse> {
|
||||
export function connect(args: ConnectRequest): Promise<ConnectResponse> {
|
||||
return sendAsync("op_connect", args);
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,7 @@ interface ReceiveResponse {
|
|||
};
|
||||
}
|
||||
|
||||
export async function receive(
|
||||
export function receive(
|
||||
rid: number,
|
||||
zeroCopy: Uint8Array
|
||||
): Promise<ReceiveResponse> {
|
||||
|
|
|
@ -12,7 +12,7 @@ interface RunStatusResponse {
|
|||
exitSignal: number;
|
||||
}
|
||||
|
||||
export async function runStatus(rid: number): Promise<RunStatusResponse> {
|
||||
export function runStatus(rid: number): Promise<RunStatusResponse> {
|
||||
return sendAsync("op_run_status", { rid });
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,6 @@ export function startRepl(historyFile: string): number {
|
|||
return sendSync("op_repl_start", { historyFile });
|
||||
}
|
||||
|
||||
export async function readline(rid: number, prompt: string): Promise<string> {
|
||||
export function readline(rid: number, prompt: string): Promise<string> {
|
||||
return sendAsync("op_repl_readline", { rid, prompt });
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ interface CompileRequest {
|
|||
bundle: boolean;
|
||||
}
|
||||
|
||||
export async function compile(request: CompileRequest): Promise<string> {
|
||||
export function compile(request: CompileRequest): Promise<string> {
|
||||
return sendAsync("op_compile", request);
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,6 @@ interface TranspileRequest {
|
|||
options?: string;
|
||||
}
|
||||
|
||||
export async function transpile(request: TranspileRequest): Promise<string> {
|
||||
export function transpile(request: TranspileRequest): Promise<string> {
|
||||
return sendAsync("op_transpile", request);
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ export function bindSignal(signo: number): { rid: number } {
|
|||
return sendSync("op_signal_bind", { signo });
|
||||
}
|
||||
|
||||
export async function pollSignal(rid: number): Promise<{ done: boolean }> {
|
||||
export function pollSignal(rid: number): Promise<{ done: boolean }> {
|
||||
return sendAsync("op_signal_poll", { rid });
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ interface ConnectTLSResponse {
|
|||
};
|
||||
}
|
||||
|
||||
export async function connectTLS(
|
||||
export function connectTLS(
|
||||
args: ConnectTLSRequest
|
||||
): Promise<ConnectTLSResponse> {
|
||||
return sendAsync("op_connect_tls", args);
|
||||
|
@ -43,7 +43,7 @@ interface AcceptTLSResponse {
|
|||
};
|
||||
}
|
||||
|
||||
export async function acceptTLS(rid: number): Promise<AcceptTLSResponse> {
|
||||
export function acceptTLS(rid: number): Promise<AcceptTLSResponse> {
|
||||
return sendAsync("op_accept_tls", { rid });
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,6 @@ export function hostPostMessage(id: number, data: Uint8Array): void {
|
|||
sendSync("op_host_post_message", { id }, data);
|
||||
}
|
||||
|
||||
export async function hostGetMessage(id: number): Promise<any> {
|
||||
export function hostGetMessage(id: number): Promise<any> {
|
||||
return sendAsync("op_host_get_message", { id });
|
||||
}
|
||||
|
|
|
@ -47,19 +47,19 @@ export class PermissionStatus {
|
|||
}
|
||||
|
||||
export class Permissions {
|
||||
async query(desc: PermissionDescriptor): Promise<PermissionStatus> {
|
||||
query(desc: PermissionDescriptor): Promise<PermissionStatus> {
|
||||
const state = permissionsOps.query(desc);
|
||||
return new PermissionStatus(state);
|
||||
return Promise.resolve(new PermissionStatus(state));
|
||||
}
|
||||
|
||||
async revoke(desc: PermissionDescriptor): Promise<PermissionStatus> {
|
||||
revoke(desc: PermissionDescriptor): Promise<PermissionStatus> {
|
||||
const state = permissionsOps.revoke(desc);
|
||||
return new PermissionStatus(state);
|
||||
return Promise.resolve(new PermissionStatus(state));
|
||||
}
|
||||
|
||||
async request(desc: PermissionDescriptor): Promise<PermissionStatus> {
|
||||
request(desc: PermissionDescriptor): Promise<PermissionStatus> {
|
||||
const state = permissionsOps.request(desc);
|
||||
return new PermissionStatus(state);
|
||||
return Promise.resolve(new PermissionStatus(state));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ export class Process {
|
|||
}
|
||||
}
|
||||
|
||||
async status(): Promise<ProcessStatus> {
|
||||
status(): Promise<ProcessStatus> {
|
||||
return runStatus(this.rid);
|
||||
}
|
||||
|
||||
|
|
|
@ -289,7 +289,7 @@ export class ConsoleTestReporter implements TestReporter {
|
|||
this.encoder = new TextEncoder();
|
||||
}
|
||||
|
||||
private log(msg: string, noNewLine = false): void {
|
||||
private log(msg: string, noNewLine = false): Promise<void> {
|
||||
if (!noNewLine) {
|
||||
msg += "\n";
|
||||
}
|
||||
|
@ -298,19 +298,22 @@ export class ConsoleTestReporter implements TestReporter {
|
|||
// compared to `console.log`; `core.print` on the other hand
|
||||
// is line-buffered and doesn't output message without newline
|
||||
stdout.writeSync(this.encoder.encode(msg));
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
async start(event: TestEventStart): Promise<void> {
|
||||
start(event: TestEventStart): Promise<void> {
|
||||
this.log(`running ${event.tests} tests`);
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
async testStart(event: TestEventTestStart): Promise<void> {
|
||||
testStart(event: TestEventTestStart): Promise<void> {
|
||||
const { name } = event;
|
||||
|
||||
this.log(`test ${name} ... `, true);
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
async testEnd(event: TestEventTestEnd): Promise<void> {
|
||||
testEnd(event: TestEventTestEnd): Promise<void> {
|
||||
const { result } = event;
|
||||
|
||||
switch (result.status) {
|
||||
|
@ -324,9 +327,11 @@ export class ConsoleTestReporter implements TestReporter {
|
|||
this.log(`${YELLOW_IGNORED} ${formatDuration(result.duration)}`);
|
||||
break;
|
||||
}
|
||||
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
async end(event: TestEventEnd): Promise<void> {
|
||||
end(event: TestEventEnd): Promise<void> {
|
||||
const { stats, duration, results } = event;
|
||||
// Attempting to match the output of Rust's test runner.
|
||||
const failedTests = results.filter(r => r.error);
|
||||
|
@ -354,6 +359,8 @@ export class ConsoleTestReporter implements TestReporter {
|
|||
`${stats.filtered} filtered out ` +
|
||||
`${formatDuration(duration)}\n`
|
||||
);
|
||||
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ unitTest(
|
|||
}
|
||||
);
|
||||
|
||||
unitTest(async function malformedJsonControlBuffer(): Promise<void> {
|
||||
unitTest(function malformedJsonControlBuffer(): void {
|
||||
// @ts-ignore
|
||||
const opId = Deno.core.ops()["op_open"];
|
||||
// @ts-ignore
|
||||
|
|
|
@ -25,7 +25,7 @@ unitTest(async function sendAsyncStackTrace(): Promise<void> {
|
|||
}
|
||||
});
|
||||
|
||||
unitTest(async function malformedMinimalControlBuffer(): Promise<void> {
|
||||
unitTest(function malformedMinimalControlBuffer(): void {
|
||||
// @ts-ignore
|
||||
const readOpId = Deno.core.ops()["op_read"];
|
||||
// @ts-ignore
|
||||
|
|
|
@ -185,7 +185,7 @@ unitTest(function eventTargetShouldAcceptAsyncFunction(): void {
|
|||
const event = new Event("foo", { bubbles: true, cancelable: false });
|
||||
let callCount = 0;
|
||||
|
||||
const listener = async (e: Event): Promise<void> => {
|
||||
const listener = (e: Event): void => {
|
||||
assertEquals(e, event);
|
||||
++callCount;
|
||||
};
|
||||
|
@ -210,7 +210,7 @@ unitTest(
|
|||
let callCount = 0;
|
||||
|
||||
const listener = {
|
||||
async handleEvent(e: Event): Promise<void> {
|
||||
handleEvent(e: Event): void {
|
||||
assertEquals(e, event);
|
||||
++callCount;
|
||||
}
|
||||
|
|
|
@ -51,16 +51,16 @@ unitTest(async function readerToAsyncIterator(): Promise<void> {
|
|||
|
||||
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.offset);
|
||||
p.set(this.buf.slice(this.offset, this.offset + n));
|
||||
this.offset += n;
|
||||
|
||||
if (n === 0) {
|
||||
return Deno.EOF;
|
||||
return Promise.resolve(Deno.EOF);
|
||||
}
|
||||
|
||||
return n;
|
||||
return Promise.resolve(n);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -359,9 +359,7 @@ if (Deno.build.os !== "win") {
|
|||
p.close();
|
||||
});
|
||||
|
||||
unitTest({ perms: { run: true } }, async function killFailed(): Promise<
|
||||
void
|
||||
> {
|
||||
unitTest({ perms: { run: true } }, function killFailed(): void {
|
||||
const p = run({
|
||||
args: ["python", "-c", "from time import sleep; sleep(10000)"]
|
||||
});
|
||||
|
|
|
@ -18,9 +18,7 @@ unitTest(
|
|||
}
|
||||
);
|
||||
|
||||
unitTest({ perms: { read: false } }, async function readlinkSyncPerm(): Promise<
|
||||
void
|
||||
> {
|
||||
unitTest({ perms: { read: false } }, function readlinkSyncPerm(): void {
|
||||
let caughtError = false;
|
||||
try {
|
||||
Deno.readlinkSync("/symlink");
|
||||
|
|
|
@ -15,7 +15,7 @@ function defer(n: number): Promise<void> {
|
|||
|
||||
unitTest(
|
||||
{ ignore: Deno.build.os !== "win" },
|
||||
async function signalsNotImplemented(): Promise<void> {
|
||||
function signalsNotImplemented(): void {
|
||||
assertThrows(
|
||||
() => {
|
||||
Deno.signal(1);
|
||||
|
@ -162,7 +162,7 @@ unitTest(
|
|||
|
||||
unitTest(
|
||||
{ ignore: Deno.build.os === "win", perms: { run: true } },
|
||||
async function signalShorthandsTest(): Promise<void> {
|
||||
function signalShorthandsTest(): void {
|
||||
let s: Deno.SignalStream;
|
||||
s = Deno.signals.alarm(); // for SIGALRM
|
||||
assert(s instanceof Deno.SignalStream);
|
||||
|
|
|
@ -3,9 +3,7 @@ import { unitTest, assert, assertEquals } from "./test_util.ts";
|
|||
|
||||
// TODO Add tests for modified, accessed, and created fields once there is a way
|
||||
// to create temp files.
|
||||
unitTest({ perms: { read: true } }, async function statSyncSuccess(): Promise<
|
||||
void
|
||||
> {
|
||||
unitTest({ perms: { read: true } }, function statSyncSuccess(): void {
|
||||
const packageInfo = Deno.statSync("README.md");
|
||||
assert(packageInfo.isFile());
|
||||
assert(!packageInfo.isSymlink());
|
||||
|
@ -19,9 +17,7 @@ unitTest({ perms: { read: true } }, async function statSyncSuccess(): Promise<
|
|||
assert(!testsInfo.isSymlink());
|
||||
});
|
||||
|
||||
unitTest({ perms: { read: false } }, async function statSyncPerm(): Promise<
|
||||
void
|
||||
> {
|
||||
unitTest({ perms: { read: false } }, function statSyncPerm(): void {
|
||||
let caughtError = false;
|
||||
try {
|
||||
Deno.statSync("README.md");
|
||||
|
@ -32,9 +28,7 @@ unitTest({ perms: { read: false } }, async function statSyncPerm(): Promise<
|
|||
assert(caughtError);
|
||||
});
|
||||
|
||||
unitTest({ perms: { read: true } }, async function statSyncNotFound(): Promise<
|
||||
void
|
||||
> {
|
||||
unitTest({ perms: { read: true } }, function statSyncNotFound(): void {
|
||||
let caughtError = false;
|
||||
let badInfo;
|
||||
|
||||
|
@ -49,9 +43,7 @@ unitTest({ perms: { read: true } }, async function statSyncNotFound(): Promise<
|
|||
assertEquals(badInfo, undefined);
|
||||
});
|
||||
|
||||
unitTest({ perms: { read: true } }, async function lstatSyncSuccess(): Promise<
|
||||
void
|
||||
> {
|
||||
unitTest({ perms: { read: true } }, function lstatSyncSuccess(): void {
|
||||
const packageInfo = Deno.lstatSync("README.md");
|
||||
assert(packageInfo.isFile());
|
||||
assert(!packageInfo.isSymlink());
|
||||
|
@ -65,9 +57,7 @@ unitTest({ perms: { read: true } }, async function lstatSyncSuccess(): Promise<
|
|||
assert(!coreInfo.isSymlink());
|
||||
});
|
||||
|
||||
unitTest({ perms: { read: false } }, async function lstatSyncPerm(): Promise<
|
||||
void
|
||||
> {
|
||||
unitTest({ perms: { read: false } }, function lstatSyncPerm(): void {
|
||||
let caughtError = false;
|
||||
try {
|
||||
Deno.lstatSync("README.md");
|
||||
|
@ -78,9 +68,7 @@ unitTest({ perms: { read: false } }, async function lstatSyncPerm(): Promise<
|
|||
assert(caughtError);
|
||||
});
|
||||
|
||||
unitTest({ perms: { read: true } }, async function lstatSyncNotFound(): Promise<
|
||||
void
|
||||
> {
|
||||
unitTest({ perms: { read: true } }, function lstatSyncNotFound(): void {
|
||||
let caughtError = false;
|
||||
let badInfo;
|
||||
|
||||
|
@ -185,7 +173,7 @@ unitTest({ perms: { read: true } }, async function lstatNotFound(): Promise<
|
|||
|
||||
unitTest(
|
||||
{ ignore: Deno.build.os !== "win", perms: { read: true, write: true } },
|
||||
async function statNoUnixFields(): Promise<void> {
|
||||
function statNoUnixFields(): void {
|
||||
const enc = new TextEncoder();
|
||||
const data = enc.encode("Hello");
|
||||
const tempDir = Deno.makeTempDirSync();
|
||||
|
@ -206,7 +194,7 @@ unitTest(
|
|||
|
||||
unitTest(
|
||||
{ ignore: Deno.build.os === "win", perms: { read: true, write: true } },
|
||||
async function statUnixFields(): Promise<void> {
|
||||
function statUnixFields(): void {
|
||||
const enc = new TextEncoder();
|
||||
const data = enc.encode("Hello");
|
||||
const tempDir = Deno.makeTempDirSync();
|
||||
|
|
|
@ -328,7 +328,7 @@ unitTest(function permissionsMatches(): void {
|
|||
*/
|
||||
unitTest(
|
||||
{ perms: { read: true } },
|
||||
async function assertAllUnitTestFilesImported(): Promise<void> {
|
||||
function assertAllUnitTestFilesImported(): void {
|
||||
const directoryTestFiles = Deno.readdirSync("./cli/js/tests/")
|
||||
.map(k => k.name)
|
||||
.filter(
|
||||
|
|
|
@ -27,7 +27,7 @@ function deferred(): {
|
|||
};
|
||||
}
|
||||
|
||||
async function waitForMs(ms: number): Promise<number> {
|
||||
function waitForMs(ms: number): Promise<number> {
|
||||
return new Promise((resolve: () => void): number => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
|
@ -158,7 +158,7 @@ unitTest(async function intervalOrdering(): Promise<void> {
|
|||
assertEquals(timeouts, 1);
|
||||
});
|
||||
|
||||
unitTest(async function intervalCancelInvalidSilentFail(): Promise<void> {
|
||||
unitTest(function intervalCancelInvalidSilentFail(): void {
|
||||
// Should silently fail (no panic)
|
||||
clearInterval(2147483647);
|
||||
});
|
||||
|
@ -234,7 +234,7 @@ unitTest(async function timeoutBindThis(): Promise<void> {
|
|||
}
|
||||
});
|
||||
|
||||
unitTest(async function clearTimeoutShouldConvertToNumber(): Promise<void> {
|
||||
unitTest(function clearTimeoutShouldConvertToNumber(): void {
|
||||
let called = false;
|
||||
const obj = {
|
||||
valueOf(): number {
|
||||
|
|
|
@ -39,7 +39,7 @@ unitTest(async function connectTLSCertFileNoReadPerm(): Promise<void> {
|
|||
|
||||
unitTest(
|
||||
{ perms: { read: true, net: true } },
|
||||
async function listenTLSNonExistentCertKeyFiles(): Promise<void> {
|
||||
function listenTLSNonExistentCertKeyFiles(): void {
|
||||
let err;
|
||||
const options = {
|
||||
hostname: "localhost",
|
||||
|
@ -70,30 +70,27 @@ unitTest(
|
|||
}
|
||||
);
|
||||
|
||||
unitTest(
|
||||
{ perms: { net: true } },
|
||||
async function listenTLSNoReadPerm(): Promise<void> {
|
||||
let err;
|
||||
try {
|
||||
Deno.listenTLS({
|
||||
hostname: "localhost",
|
||||
port: 4500,
|
||||
certFile: "cli/tests/tls/localhost.crt",
|
||||
keyFile: "cli/tests/tls/localhost.key"
|
||||
});
|
||||
} catch (e) {
|
||||
err = e;
|
||||
}
|
||||
assert(err instanceof Deno.errors.PermissionDenied);
|
||||
assertEquals(err.name, "PermissionDenied");
|
||||
unitTest({ perms: { net: true } }, function listenTLSNoReadPerm(): void {
|
||||
let err;
|
||||
try {
|
||||
Deno.listenTLS({
|
||||
hostname: "localhost",
|
||||
port: 4500,
|
||||
certFile: "cli/tests/tls/localhost.crt",
|
||||
keyFile: "cli/tests/tls/localhost.key"
|
||||
});
|
||||
} catch (e) {
|
||||
err = e;
|
||||
}
|
||||
);
|
||||
assert(err instanceof Deno.errors.PermissionDenied);
|
||||
assertEquals(err.name, "PermissionDenied");
|
||||
});
|
||||
|
||||
unitTest(
|
||||
{
|
||||
perms: { read: true, write: true, net: true }
|
||||
},
|
||||
async function listenTLSEmptyKeyFile(): Promise<void> {
|
||||
function listenTLSEmptyKeyFile(): void {
|
||||
let err;
|
||||
const options = {
|
||||
hostname: "localhost",
|
||||
|
@ -122,7 +119,7 @@ unitTest(
|
|||
|
||||
unitTest(
|
||||
{ perms: { read: true, write: true, net: true } },
|
||||
async function listenTLSEmptyCertFile(): Promise<void> {
|
||||
function listenTLSEmptyCertFile(): void {
|
||||
let err;
|
||||
const options = {
|
||||
hostname: "localhost",
|
||||
|
|
|
@ -306,7 +306,7 @@ export class Body implements domTypes.Body {
|
|||
return JSON.parse(raw);
|
||||
}
|
||||
|
||||
public async arrayBuffer(): Promise<ArrayBuffer> {
|
||||
public arrayBuffer(): Promise<ArrayBuffer> {
|
||||
if (
|
||||
this._bodySource instanceof Int8Array ||
|
||||
this._bodySource instanceof Int16Array ||
|
||||
|
@ -318,20 +318,24 @@ export class Body implements domTypes.Body {
|
|||
this._bodySource instanceof Float32Array ||
|
||||
this._bodySource instanceof Float64Array
|
||||
) {
|
||||
return this._bodySource.buffer as ArrayBuffer;
|
||||
return Promise.resolve(this._bodySource.buffer as ArrayBuffer);
|
||||
} else if (this._bodySource instanceof ArrayBuffer) {
|
||||
return this._bodySource;
|
||||
return Promise.resolve(this._bodySource);
|
||||
} else if (typeof this._bodySource === "string") {
|
||||
const enc = new TextEncoder();
|
||||
return enc.encode(this._bodySource).buffer as ArrayBuffer;
|
||||
return Promise.resolve(
|
||||
enc.encode(this._bodySource).buffer as ArrayBuffer
|
||||
);
|
||||
} else if (this._bodySource instanceof ReadableStream) {
|
||||
// @ts-ignore
|
||||
return bufferFromStream(this._bodySource.getReader());
|
||||
} else if (this._bodySource instanceof FormData) {
|
||||
const enc = new TextEncoder();
|
||||
return enc.encode(this._bodySource.toString()).buffer as ArrayBuffer;
|
||||
return Promise.resolve(
|
||||
enc.encode(this._bodySource.toString()).buffer as ArrayBuffer
|
||||
);
|
||||
} else if (!this._bodySource) {
|
||||
return new ArrayBuffer(0);
|
||||
return Promise.resolve(new ArrayBuffer(0));
|
||||
}
|
||||
throw new Error(
|
||||
`Body type not yet implemented: ${this._bodySource.constructor.name}`
|
||||
|
|
|
@ -60,6 +60,7 @@ class Body implements domTypes.Body, domTypes.ReadableStream, io.ReadCloser {
|
|||
return this._data;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line require-await
|
||||
async arrayBuffer(): Promise<ArrayBuffer> {
|
||||
// If we've already bufferred the response, just return it.
|
||||
if (this._data != null) {
|
||||
|
@ -223,11 +224,12 @@ class Body implements domTypes.Body, domTypes.ReadableStream, io.ReadCloser {
|
|||
return read(this.rid, p);
|
||||
}
|
||||
|
||||
close(): void {
|
||||
close(): Promise<void> {
|
||||
close(this.rid);
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
async cancel(): Promise<void> {
|
||||
cancel(): Promise<void> {
|
||||
return notImplemented();
|
||||
}
|
||||
|
||||
|
@ -346,7 +348,7 @@ export class Response implements domTypes.Response {
|
|||
return false;
|
||||
}
|
||||
|
||||
async arrayBuffer(): Promise<ArrayBuffer> {
|
||||
arrayBuffer(): Promise<ArrayBuffer> {
|
||||
/* You have to do the null check here and not in the function because
|
||||
* otherwise TS complains about this.body potentially being null */
|
||||
if (this.bodyViewable() || this.body == null) {
|
||||
|
@ -355,14 +357,14 @@ export class Response implements domTypes.Response {
|
|||
return this.body.arrayBuffer();
|
||||
}
|
||||
|
||||
async blob(): Promise<domTypes.Blob> {
|
||||
blob(): Promise<domTypes.Blob> {
|
||||
if (this.bodyViewable() || this.body == null) {
|
||||
return Promise.reject(new Error("Response body is null"));
|
||||
}
|
||||
return this.body.blob();
|
||||
}
|
||||
|
||||
async formData(): Promise<domTypes.FormData> {
|
||||
formData(): Promise<domTypes.FormData> {
|
||||
if (this.bodyViewable() || this.body == null) {
|
||||
return Promise.reject(new Error("Response body is null"));
|
||||
}
|
||||
|
@ -370,14 +372,14 @@ export class Response implements domTypes.Response {
|
|||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
async json(): Promise<any> {
|
||||
json(): Promise<any> {
|
||||
if (this.bodyViewable() || this.body == null) {
|
||||
return Promise.reject(new Error("Response body is null"));
|
||||
}
|
||||
return this.body.json();
|
||||
}
|
||||
|
||||
async text(): Promise<string> {
|
||||
text(): Promise<string> {
|
||||
if (this.bodyViewable() || this.body == null) {
|
||||
return Promise.reject(new Error("Response body is null"));
|
||||
}
|
||||
|
@ -437,7 +439,7 @@ export class Response implements domTypes.Response {
|
|||
}
|
||||
}
|
||||
|
||||
async function sendFetchReq(
|
||||
function sendFetchReq(
|
||||
url: string,
|
||||
method: string | null,
|
||||
headers: domTypes.Headers | null,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
async function fn(): Promise<never> {
|
||||
function fn(): Promise<never> {
|
||||
throw new Error("message");
|
||||
}
|
||||
async function call(): Promise<void> {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
console.log("hello");
|
||||
// eslint-disable-next-line require-await
|
||||
const foo = async (): Promise<never> => {
|
||||
console.log("before error");
|
||||
throw Error("error");
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
before error
|
||||
world
|
||||
error: Uncaught Error: error
|
||||
[WILDCARD]tests/async_error.ts:4:9
|
||||
[WILDCARD]tests/async_error.ts:5:9
|
||||
|
||||
4 throw Error("error");
|
||||
5 throw Error("error");
|
||||
^
|
||||
|
||||
at foo ([WILDCARD]tests/async_error.ts:4:9)
|
||||
at [WILDCARD]tests/async_error.ts:7:1
|
||||
at foo ([WILDCARD]tests/async_error.ts:5:9)
|
||||
at [WILDCARD]tests/async_error.ts:8:1
|
||||
|
|
|
@ -3,8 +3,9 @@ const { args, listen, env, exit, makeTempDirSync, readFileSync, run } = Deno;
|
|||
|
||||
const name = args[0];
|
||||
const test: { [key: string]: Function } = {
|
||||
async readRequired(): Promise<void> {
|
||||
readRequired(): Promise<void> {
|
||||
readFileSync("README.md");
|
||||
return Promise.resolve();
|
||||
},
|
||||
writeRequired(): void {
|
||||
makeTempDirSync();
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
async function* asyncGenerator() {
|
||||
function* asyncGenerator() {
|
||||
let i = 0;
|
||||
while (i < 3) {
|
||||
yield i++;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// eslint-disable-next-line require-await
|
||||
async function* asyncGenerator(): AsyncIterableIterator<number> {
|
||||
let i = 0;
|
||||
while (i < 3) {
|
||||
|
|
|
@ -84,7 +84,7 @@ function listen() {
|
|||
}
|
||||
|
||||
/** Accepts a connection, returns rid. */
|
||||
async function accept(rid) {
|
||||
function accept(rid) {
|
||||
return sendAsync(ops["accept"], rid);
|
||||
}
|
||||
|
||||
|
@ -92,12 +92,12 @@ async function accept(rid) {
|
|||
* Reads a packet from the rid, presumably an http request. data is ignored.
|
||||
* Returns bytes read.
|
||||
*/
|
||||
async function read(rid, data) {
|
||||
function read(rid, data) {
|
||||
return sendAsync(ops["read"], rid, data);
|
||||
}
|
||||
|
||||
/** Writes a fixed HTTP response to the socket rid. Returns bytes written. */
|
||||
async function write(rid, data) {
|
||||
function write(rid, data) {
|
||||
return sendAsync(ops["write"], rid, data);
|
||||
}
|
||||
|
||||
|
|
|
@ -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]));
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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> {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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")
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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> {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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]);
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -16,7 +16,7 @@ test({
|
|||
else resolve();
|
||||
});
|
||||
})
|
||||
.then(async () => {
|
||||
.then(() => {
|
||||
assert(!Deno.resources()[file.rid]);
|
||||
})
|
||||
.catch(() => {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -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 ");
|
||||
|
|
|
@ -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([]);
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
|
@ -8,11 +8,11 @@ const response = Buffer.from(
|
|||
"HTTP/1.1 200 OK\r\nContent-Length: 12\r\n\r\nHello World\n"
|
||||
);
|
||||
|
||||
async function write(socket, buffer) {
|
||||
function write(socket, buffer) {
|
||||
const p = new Promise((resolve, _) => {
|
||||
socket.write(buffer, resolve);
|
||||
});
|
||||
return p;
|
||||
return Promise.resolve(p);
|
||||
}
|
||||
|
||||
Server(async socket => {
|
||||
|
@ -20,6 +20,6 @@ Server(async socket => {
|
|||
socket.destroy();
|
||||
});
|
||||
for await (const _ of socket) {
|
||||
write(socket, response);
|
||||
await write(socket, response);
|
||||
}
|
||||
}).listen(port);
|
||||
|
|
Loading…
Add table
Reference in a new issue