mirror of
https://github.com/denoland/deno.git
synced 2025-08-03 18:38:33 +00: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
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue