1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-26 00:59:24 -05:00

chore: align some Web API type definitions to lib.dom.d.ts (#15219)

This commit is contained in:
ayame113 2022-07-20 19:30:41 +09:00 committed by GitHub
parent b8e1250500
commit 27a72a12b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 44 additions and 5 deletions

View file

@ -818,6 +818,14 @@ Deno.test(function responseRedirect() {
assertEquals(redir.type, "default"); assertEquals(redir.type, "default");
}); });
Deno.test(function responseRedirectTakeURLObjectAsParameter() {
const redir = Response.redirect(new URL("https://example.com/"));
assertEquals(
redir.headers.get("Location"),
"https://example.com/",
);
});
Deno.test(async function responseWithoutBody() { Deno.test(async function responseWithoutBody() {
const response = new Response(); const response = new Response();
assertEquals(await response.arrayBuffer(), new ArrayBuffer(0)); assertEquals(await response.arrayBuffer(), new ArrayBuffer(0));

View file

@ -68,3 +68,10 @@ Deno.test(function customInspectFunction() {
); );
assertStringIncludes(Deno.inspect(Request.prototype), "Request"); assertStringIncludes(Deno.inspect(Request.prototype), "Request");
}); });
Deno.test(function requestConstructorTakeURLObjectAsParameter() {
assertEquals(
new Request(new URL("http://foo/")).url,
"http://foo/",
);
});

View file

@ -494,3 +494,15 @@ Deno.test(function urlSearchParamsIdentityPreserved() {
const sp2 = u.searchParams; const sp2 = u.searchParams;
assertStrictEquals(sp1, sp2); assertStrictEquals(sp1, sp2);
}); });
Deno.test(function urlTakeURLObjectAsParameter() {
const url = new URL(
new URL(
"https://foo:bar@baz.qat:8000/qux/quux?foo=bar&baz=12#qat",
),
);
assertEquals(
url.href,
"https://foo:bar@baz.qat:8000/qux/quux?foo=bar&baz=12#qat",
);
});

View file

@ -1,5 +1,5 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
import { assertThrows } from "./test_util.ts"; import { assertEquals, assertThrows, deferred, fail } from "./test_util.ts";
Deno.test({ permissions: "none" }, function websocketPermissionless() { Deno.test({ permissions: "none" }, function websocketPermissionless() {
assertThrows( assertThrows(
@ -7,3 +7,15 @@ Deno.test({ permissions: "none" }, function websocketPermissionless() {
Deno.errors.PermissionDenied, Deno.errors.PermissionDenied,
); );
}); });
Deno.test(async function websocketConstructorTakeURLObjectAsParameter() {
const promise = deferred();
const ws = new WebSocket(new URL("ws://localhost:4242/"));
assertEquals(ws.url, "ws://localhost:4242/");
ws.onerror = () => fail();
ws.onopen = () => ws.close();
ws.onclose = () => {
promise.resolve();
};
await promise;
});

View file

@ -252,7 +252,7 @@ interface RequestInit {
/** This Fetch API interface represents a resource request. */ /** This Fetch API interface represents a resource request. */
declare class Request implements Body { declare class Request implements Body {
constructor(input: RequestInfo, init?: RequestInit); constructor(input: RequestInfo | URL, init?: RequestInit);
/** /**
* Returns the cache mode associated with request, which is a string * Returns the cache mode associated with request, which is a string
@ -385,7 +385,7 @@ declare class Response implements Body {
constructor(body?: BodyInit | null, init?: ResponseInit); constructor(body?: BodyInit | null, init?: ResponseInit);
static json(data: unknown, init?: ResponseInit): Response; static json(data: unknown, init?: ResponseInit): Response;
static error(): Response; static error(): Response;
static redirect(url: string, status?: number): Response; static redirect(url: string | URL, status?: number): Response;
readonly headers: Headers; readonly headers: Headers;
readonly ok: boolean; readonly ok: boolean;

View file

@ -153,7 +153,7 @@ declare class URLSearchParams {
/** The URL interface represents an object providing static methods used for creating object URLs. */ /** The URL interface represents an object providing static methods used for creating object URLs. */
declare class URL { declare class URL {
constructor(url: string, base?: string | URL); constructor(url: string | URL, base?: string | URL);
static createObjectURL(blob: Blob): string; static createObjectURL(blob: Blob): string;
static revokeObjectURL(url: string): void; static revokeObjectURL(url: string): void;

View file

@ -40,7 +40,7 @@ interface WebSocketEventMap {
* If you are looking to create a WebSocket server, please take a look at `Deno.upgradeWebSocket()`. * If you are looking to create a WebSocket server, please take a look at `Deno.upgradeWebSocket()`.
*/ */
declare class WebSocket extends EventTarget { declare class WebSocket extends EventTarget {
constructor(url: string, protocols?: string | string[]); constructor(url: string | URL, protocols?: string | string[]);
static readonly CLOSED: number; static readonly CLOSED: number;
static readonly CLOSING: number; static readonly CLOSING: number;