aboutsummaryrefslogtreecommitdiff
path: root/integration/bunjs-only-snippets/url.test.ts
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-03-27 02:43:52 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-03-27 02:45:30 -0700
commit4df62a67e7a7f4b484469c92d1c60e2b645e676b (patch)
tree26ebd2bfac0ad5ac2c734c389e866598af811a1b /integration/bunjs-only-snippets/url.test.ts
parent3cfafb6dc4feb45df98c6df25f00939ee3312848 (diff)
downloadbun-4df62a67e7a7f4b484469c92d1c60e2b645e676b.tar.gz
bun-4df62a67e7a7f4b484469c92d1c60e2b645e676b.tar.zst
bun-4df62a67e7a7f4b484469c92d1c60e2b645e676b.zip
Create url.test.ts
Diffstat (limited to 'integration/bunjs-only-snippets/url.test.ts')
-rw-r--r--integration/bunjs-only-snippets/url.test.ts102
1 files changed, 102 insertions, 0 deletions
diff --git a/integration/bunjs-only-snippets/url.test.ts b/integration/bunjs-only-snippets/url.test.ts
new file mode 100644
index 000000000..9bead1f4e
--- /dev/null
+++ b/integration/bunjs-only-snippets/url.test.ts
@@ -0,0 +1,102 @@
+import { describe, it, expect } from "bun:test";
+
+describe("url", () => {
+ it("works", () => {
+ const inputs: [
+ [
+ string,
+ {
+ hash: string;
+ host: string;
+ hostname: string;
+ href: string;
+ origin: string;
+ password: string;
+ pathname: string;
+ port: string;
+ protocol: string;
+ search: string;
+ username: string;
+ }
+ ]
+ ] = [
+ [
+ "https://username:password@api.foo.bar.com:9999/baz/okay/i/123?ran=out&of=things#to-use-as-a-placeholder",
+ {
+ hash: "#to-use-as-a-placeholder",
+ host: "api.foo.bar.com:9999",
+ hostname: "api.foo.bar.com",
+ href: "https://username:password@api.foo.bar.com:9999/baz/okay/i/123?ran=out&of=things#to-use-as-a-placeholder",
+ origin: "https://api.foo.bar.com:9999",
+ password: "password",
+ pathname: "/baz/okay/i/123",
+ port: "9999",
+ protocol: "https:",
+ search: "?ran=out&of=things",
+ username: "username",
+ },
+ ],
+ [
+ "https://url.spec.whatwg.org/#url-serializing",
+ {
+ hash: "#url-serializing",
+ host: "url.spec.whatwg.org",
+ hostname: "url.spec.whatwg.org",
+ href: "https://url.spec.whatwg.org/#url-serializing",
+ origin: "https://url.spec.whatwg.org",
+ password: "",
+ pathname: "/",
+ port: "",
+ protocol: "https:",
+ search: "",
+ username: "",
+ },
+ ],
+ [
+ "https://url.spec.whatwg.org#url-serializing",
+ {
+ hash: "#url-serializing",
+ host: "url.spec.whatwg.org",
+ hostname: "url.spec.whatwg.org",
+ href: "https://url.spec.whatwg.org/#url-serializing",
+ origin: "https://url.spec.whatwg.org",
+ password: "",
+ pathname: "/",
+ port: "",
+ protocol: "https:",
+ search: "",
+ username: "",
+ },
+ ],
+ ];
+
+ for (let [url, values] of inputs) {
+ const result = new URL(url);
+ expect(result.hash).toBe(values.hash);
+ expect(result.host).toBe(values.host);
+ expect(result.hostname).toBe(values.hostname);
+ expect(result.href).toBe(values.href);
+ expect(result.origin).toBe(values.origin);
+ expect(result.password).toBe(values.password);
+ expect(result.pathname).toBe(values.pathname);
+ expect(result.port).toBe(values.port);
+ expect(result.protocol).toBe(values.protocol);
+ expect(result.search).toBe(values.search);
+ expect(result.username).toBe(values.username);
+ }
+
+ expect(new URL("example.com").pathname).toBe("/");
+ expect(new URL("https://example.com").protocol).toBe("https:");
+ expect(new URL("http://example.com").protocol).toBe("http:");
+ expect(new URL("example.com/foo").pathname).toBe("/foo");
+ expect(new URL("example.com/foo/bar/").pathname).toBe("/foo/bar/");
+ expect(new URL("example.com/foo/bar/?search=true").search).toBe(
+ "?search=true"
+ );
+ expect(new URL("example.com/foo/bar/?search=true#fragment").search).toBe(
+ "?search=true"
+ );
+ expect(new URL("https://example.com").href).toBe("https://example.com/");
+ expect(new URL("example.com").hostname).toBe("example.com");
+ });
+});