Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cli/tests/unit/fetch_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,14 @@ Deno.test(function responseRedirect() {
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() {
const response = new Response();
assertEquals(await response.arrayBuffer(), new ArrayBuffer(0));
Expand Down
7 changes: 7 additions & 0 deletions cli/tests/unit/request_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,10 @@ Deno.test(function customInspectFunction() {
);
assertStringIncludes(Deno.inspect(Request.prototype), "Request");
});

Deno.test(function requestConstructorTakeURLObjectAsParameter() {
assertEquals(
new Request(new URL("http://foo/")).url,
"http://foo/",
);
});
12 changes: 12 additions & 0 deletions cli/tests/unit/url_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,3 +494,15 @@ Deno.test(function urlSearchParamsIdentityPreserved() {
const sp2 = u.searchParams;
assertStrictEquals(sp1, sp2);
});

Deno.test(function urlTakeURLObjectAsParameter() {
const url = new URL(
new URL(
"https://foo:[email protected]:8000/qux/quux?foo=bar&baz=12#qat",
),
);
assertEquals(
url.href,
"https://foo:[email protected]:8000/qux/quux?foo=bar&baz=12#qat",
);
});
14 changes: 13 additions & 1 deletion cli/tests/unit/websocket_test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
// 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() {
assertThrows(
() => new WebSocket("ws://localhost"),
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;
});
4 changes: 2 additions & 2 deletions ext/fetch/lib.deno_fetch.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ interface RequestInit {

/** This Fetch API interface represents a resource request. */
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
Expand Down Expand Up @@ -385,7 +385,7 @@ declare class Response implements Body {
constructor(body?: BodyInit | null, init?: ResponseInit);
static json(data: unknown, init?: ResponseInit): Response;
static error(): Response;
static redirect(url: string, status?: number): Response;
static redirect(url: string | URL, status?: number): Response;

readonly headers: Headers;
readonly ok: boolean;
Expand Down
2 changes: 1 addition & 1 deletion ext/url/lib.deno_url.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ declare class URLSearchParams {

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

Expand Down
2 changes: 1 addition & 1 deletion ext/websocket/lib.deno_websocket.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ interface WebSocketEventMap {
* If you are looking to create a WebSocket server, please take a look at `Deno.upgradeWebSocket()`.
*/
declare class WebSocket extends EventTarget {
constructor(url: string, protocols?: string | string[]);
constructor(url: string | URL, protocols?: string | string[]);

static readonly CLOSED: number;
static readonly CLOSING: number;
Expand Down