diff options
Diffstat (limited to 'test/js/web/fetch')
-rw-r--r-- | test/js/web/fetch/body.test.ts | 2 | ||||
-rw-r--r-- | test/js/web/fetch/fetch-gzip.test.ts | 17 | ||||
-rw-r--r-- | test/js/web/fetch/fetch.test.ts | 35 |
3 files changed, 29 insertions, 25 deletions
diff --git a/test/js/web/fetch/body.test.ts b/test/js/web/fetch/body.test.ts index fa3d4e53b..2b9b3e11d 100644 --- a/test/js/web/fetch/body.test.ts +++ b/test/js/web/fetch/body.test.ts @@ -245,11 +245,9 @@ for (const { body, fn } of bodyTypes) { }); test(body.name, async () => { for (const { string, buffer } of utf8) { - // @ts-expect-error expect(() => { fn(buffer); }).not.toThrow(); - // @ts-expect-error expect(await fn(buffer).text()).toBe(string); } }); diff --git a/test/js/web/fetch/fetch-gzip.test.ts b/test/js/web/fetch/fetch-gzip.test.ts index 91ea8de9f..076b5845b 100644 --- a/test/js/web/fetch/fetch-gzip.test.ts +++ b/test/js/web/fetch/fetch-gzip.test.ts @@ -1,7 +1,6 @@ -import { concatArrayBuffers } from "bun"; -import { it, describe, expect } from "bun:test"; -import fs from "fs"; -import { gc, gcTick } from "harness"; +import { concatArrayBuffers, Socket, TCPSocketListener } from "bun"; +import { it, expect } from "bun:test"; +import { gcTick } from "harness"; it("fetch() with a buffered gzip response works (one chunk)", async () => { var server = Bun.serve({ @@ -122,9 +121,15 @@ it("fetch() with a gzip response works (one chunk, streamed, with a delay", asyn server.stop(); }); +const arg = Bun.listen({ + hostname: "asdf", + port: 1234, + socket: {}, +}); + it("fetch() with a gzip response works (multiple chunks, TCP server", async done => { const compressed = await Bun.file(import.meta.dir + "/fixture.html.gz").arrayBuffer(); - var socketToClose; + var socketToClose!: Socket; const server = Bun.listen({ port: 0, hostname: "0.0.0.0", @@ -134,7 +139,7 @@ it("fetch() with a gzip response works (multiple chunks, TCP server", async done var corked: any[] = []; var cork = true; - async function write(chunk) { + async function write(chunk: any) { await new Promise<void>((resolve, reject) => { if (cork) { corked.push(chunk); diff --git a/test/js/web/fetch/fetch.test.ts b/test/js/web/fetch/fetch.test.ts index 1f2345f85..f723761a7 100644 --- a/test/js/web/fetch/fetch.test.ts +++ b/test/js/web/fetch/fetch.test.ts @@ -1,4 +1,4 @@ -import { serve, sleep } from "bun"; +import { AnyFunction, serve, ServeOptions, Server, sleep } from "bun"; import { afterAll, afterEach, beforeAll, describe, expect, it, beforeEach } from "bun:test"; import { chmodSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from "fs"; import { mkfifo } from "mkfifo"; @@ -10,8 +10,8 @@ const tmp_dir = mkdtempSync(join(realpathSync(tmpdir()), "fetch.test")); const fixture = readFileSync(join(import.meta.dir, "fetch.js.txt"), "utf8"); -let server; -function startServer({ fetch, ...options }) { +let server: Server; +function startServer({ fetch, ...options }: ServeOptions) { server = serve({ ...options, fetch, @@ -38,7 +38,7 @@ describe("AbortSignal", () => { return new Response("Hello"); } if (request.url.endsWith("/stream")) { - const reader = request.body.getReader(); + const reader = request.body!.getReader(); const body = new ReadableStream({ async pull(controller) { if (!reader) controller.close(); @@ -113,11 +113,11 @@ describe("AbortSignal", () => { const controller = new AbortController(); const signal = controller.signal; signal.addEventListener("abort", ev => { - const target = ev.currentTarget; + const target = ev.currentTarget!; expect(target).toBeDefined(); expect(target.aborted).toBe(true); expect(target.reason).toBeDefined(); - expect(target.reason.name).toBe("AbortError"); + expect(target.reason!.name).toBe("AbortError"); }); expect(async () => { @@ -280,11 +280,11 @@ describe("fetch", () => { "http://example.com", new URL("https://example.com"), new Request({ url: "https://example.com" }), - { toString: () => "https://example.com" }, + { toString: () => "https://example.com" } as string, ]; for (let url of urls) { gc(); - let name; + let name: string; if (url instanceof URL) { name = "URL: " + url; } else if (url instanceof Request) { @@ -292,7 +292,7 @@ describe("fetch", () => { } else if (url.hasOwnProperty("toString")) { name = "Object: " + url.toString(); } else { - name = url; + name = url as string; } it(name, async () => { gc(); @@ -347,7 +347,7 @@ describe("fetch", () => { fetch(req) { return new Response(req.body); }, - host: "localhost", + hostname: "localhost", }); // POST with body @@ -388,7 +388,7 @@ it("website with tlsextname", async () => { await fetch("https://bun.sh", { method: "HEAD" }); }); -function testBlobInterface(blobbyConstructor, hasBlobFn?) { +function testBlobInterface(blobbyConstructor: { (..._: any[]): any }, hasBlobFn?: boolean) { for (let withGC of [false, true]) { for (let jsonObject of [ { hello: true }, @@ -534,7 +534,7 @@ describe("Bun.file", () => { let count = 0; testBlobInterface(data => { const blob = new Blob([data]); - const buffer = Bun.peek(blob.arrayBuffer()); + const buffer = Bun.peek(blob.arrayBuffer()) as ArrayBuffer; const path = join(tmp_dir, `tmp-${count++}.bytes`); writeFileSync(path, buffer); const file = Bun.file(path); @@ -549,8 +549,8 @@ describe("Bun.file", () => { expect(size).toBe(Infinity); }); - function forEachMethod(fn, skip?) { - const method = ["arrayBuffer", "text", "json"]; + const method = ["arrayBuffer", "text", "json"] as const; + function forEachMethod(fn: (m: (typeof method)[number]) => any, skip?: AnyFunction) { for (const m of method) { (skip ? it.skip : it)(m, fn(m)); } @@ -643,7 +643,7 @@ describe("Blob", () => { "π π π π π π
π π€£ π₯² βΊοΈ π π π π π π π π₯° π π π π π π π π π€ͺ π€¨ π§ π€ π π₯Έ π€© π₯³", ), ], - ]; + ] as any[]; var expected = [ "123456", @@ -721,7 +721,7 @@ describe("Blob", () => { const input = Constructor === Blob ? [data] : Constructor === Request ? { body: data, url: "http://example.com" } : data; if (withGC) gc(); - const blob = new Constructor(input); + const blob = new Constructor(input as any); if (withGC) gc(); const out = await blob.arrayBuffer(); if (withGC) gc(); @@ -1101,12 +1101,14 @@ it("body nullable", async () => { }); it("Request({}) throws", async () => { + // @ts-expect-error expect(() => new Request({})).toThrow(); }); it("Request({toString() { throw 'wat'; } }) throws", async () => { expect( () => + // @ts-expect-error new Request({ toString() { throw "wat"; @@ -1123,6 +1125,5 @@ it("should not be able to parse json from empty body", () => { it("#874", () => { expect(new Request(new Request("https://example.com"), {}).url).toBe("https://example.com"); expect(new Request(new Request("https://example.com")).url).toBe("https://example.com"); - // @ts-expect-error expect(new Request({ url: "https://example.com" }).url).toBe("https://example.com"); }); |