diff options
author | 2023-05-24 22:52:13 -0300 | |
---|---|---|
committer | 2023-05-24 18:52:13 -0700 | |
commit | ed1f62ffffdd02db761513e8ac2561afa4b5a8dc (patch) | |
tree | 261982cfd30796c9b35ed3ef8fb701687bf2cdec /test/js | |
parent | 49729341895752f8817f444e9c87eaf4affa68bf (diff) | |
download | bun-ed1f62ffffdd02db761513e8ac2561afa4b5a8dc.tar.gz bun-ed1f62ffffdd02db761513e8ac2561afa4b5a8dc.tar.zst bun-ed1f62ffffdd02db761513e8ac2561afa4b5a8dc.zip |
[server.fetch] call when using Request object (#3051)
* patch server.fetch
* add tests and fix types
Diffstat (limited to 'test/js')
-rw-r--r-- | test/js/bun/http/bun-server.test.ts | 33 |
1 files changed, 33 insertions, 0 deletions
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; |