diff options
Diffstat (limited to 'test/regression/issue/06443.test.ts')
-rw-r--r-- | test/regression/issue/06443.test.ts | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/test/regression/issue/06443.test.ts b/test/regression/issue/06443.test.ts new file mode 100644 index 000000000..88b34f0da --- /dev/null +++ b/test/regression/issue/06443.test.ts @@ -0,0 +1,40 @@ +import { describe, test, expect } from "bun:test"; +import { serve, file } from "bun"; + +describe("Bun.serve()", () => { + const tls = { + cert: file(new URL("../fixtures/cert.pem", import.meta.url)), + key: file(new URL("../fixtures/cert.key", import.meta.url)), + }; + + const servers = [ + { + port: 0, + url: /^http:\/\/localhost:\d+\/$/, + }, + { + tls, + port: 0, + url: /^https:\/\/localhost:\d+\/$/, + }, + ]; + + test.each(servers)("%j", async ({ url, ...options }) => { + const server = serve({ + hostname: "localhost", + ...options, + fetch(request) { + return new Response(request.url); + }, + }); + try { + const proto = options.tls ? "https" : "http"; + const target = `${proto}://localhost:${server.port}/`; + const response = await fetch(target); + expect(response.text()).resolves.toMatch(url); + } finally { + server.stop(true); + } + }); +}); + |