summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/tests/unit/fetch_test.ts8
-rw-r--r--cli/tests/unit/request_test.ts7
-rw-r--r--cli/tests/unit/url_test.ts12
-rw-r--r--cli/tests/unit/websocket_test.ts14
-rw-r--r--ext/fetch/lib.deno_fetch.d.ts4
-rw-r--r--ext/url/lib.deno_url.d.ts2
-rw-r--r--ext/websocket/lib.deno_websocket.d.ts2
7 files changed, 44 insertions, 5 deletions
diff --git a/cli/tests/unit/fetch_test.ts b/cli/tests/unit/fetch_test.ts
index 7adbb7721..72660c547 100644
--- a/cli/tests/unit/fetch_test.ts
+++ b/cli/tests/unit/fetch_test.ts
@@ -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));
diff --git a/cli/tests/unit/request_test.ts b/cli/tests/unit/request_test.ts
index 41a1d7e2f..68f7a86c1 100644
--- a/cli/tests/unit/request_test.ts
+++ b/cli/tests/unit/request_test.ts
@@ -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/",
+ );
+});
diff --git a/cli/tests/unit/url_test.ts b/cli/tests/unit/url_test.ts
index 3d4e1aa2c..0ba848add 100644
--- a/cli/tests/unit/url_test.ts
+++ b/cli/tests/unit/url_test.ts
@@ -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: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",
+ );
+});
diff --git a/cli/tests/unit/websocket_test.ts b/cli/tests/unit/websocket_test.ts
index f033c5ac4..6bd35efca 100644
--- a/cli/tests/unit/websocket_test.ts
+++ b/cli/tests/unit/websocket_test.ts
@@ -1,5 +1,5 @@
// 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(
@@ -7,3 +7,15 @@ Deno.test({ permissions: "none" }, function websocketPermissionless() {
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;
+});
diff --git a/ext/fetch/lib.deno_fetch.d.ts b/ext/fetch/lib.deno_fetch.d.ts
index 18c39c866..79d435468 100644
--- a/ext/fetch/lib.deno_fetch.d.ts
+++ b/ext/fetch/lib.deno_fetch.d.ts
@@ -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
@@ -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;
diff --git a/ext/url/lib.deno_url.d.ts b/ext/url/lib.deno_url.d.ts
index 4dc56b3f6..d3a51a00e 100644
--- a/ext/url/lib.deno_url.d.ts
+++ b/ext/url/lib.deno_url.d.ts
@@ -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;
diff --git a/ext/websocket/lib.deno_websocket.d.ts b/ext/websocket/lib.deno_websocket.d.ts
index 8b79fa5cc..70d0bd61d 100644
--- a/ext/websocket/lib.deno_websocket.d.ts
+++ b/ext/websocket/lib.deno_websocket.d.ts
@@ -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;