From ed1f62ffffdd02db761513e8ac2561afa4b5a8dc Mon Sep 17 00:00:00 2001 From: Ciro Spaciari Date: Wed, 24 May 2023 22:52:13 -0300 Subject: [server.fetch] call when using Request object (#3051) * patch server.fetch * add tests and fix types --- test/js/bun/http/bun-server.test.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'test/js') diff --git a/test/js/bun/http/bun-server.test.ts b/test/js/bun/http/bun-server.test.ts index 3472dc498..7d0915b89 100644 --- a/test/js/bun/http/bun-server.test.ts +++ b/test/js/bun/http/bun-server.test.ts @@ -150,6 +150,39 @@ describe("Server", () => { } }); + test("server.fetch should work with a string", async () => { + const server = Bun.serve({ + fetch(req) { + return new Response("Hello World!"); + }, + }); + try { + const url = `http://${server.hostname}:${server.port}`; + const response = await server.fetch(url); + expect(await response.text()).toBe("Hello World!"); + expect(response.status).toBe(200); + expect(response.url).toBe(url); + } finally { + server.stop(true); + } + }); + + test("server.fetch should work with a Request object", async () => { + const server = Bun.serve({ + fetch(req) { + return new Response("Hello World!"); + }, + }); + try { + const url = `http://${server.hostname}:${server.port}`; + const response = await server.fetch(new Request(url)); + expect(await response.text()).toBe("Hello World!"); + expect(response.status).toBe(200); + expect(response.url).toBe(url); + } finally { + server.stop(true); + } + }); test("abort signal on server with stream", async () => { { let signalOnServer = false; -- cgit v1.2.3