diff options
author | 2022-06-22 23:21:48 -0700 | |
---|---|---|
committer | 2022-06-22 23:21:48 -0700 | |
commit | 729d445b6885f69dd2c6355f38707bd42851c791 (patch) | |
tree | f87a7c408929ea3f57bbb7ace380cf869da83c0e /integration/bunjs-only-snippets/serve.test.ts | |
parent | 25f820c6bf1d8ec6d444ef579cc036b8c0607b75 (diff) | |
download | bun-729d445b6885f69dd2c6355f38707bd42851c791.tar.gz bun-729d445b6885f69dd2c6355f38707bd42851c791.tar.zst bun-729d445b6885f69dd2c6355f38707bd42851c791.zip |
change the directory structurejarred/rename
Diffstat (limited to 'integration/bunjs-only-snippets/serve.test.ts')
-rw-r--r-- | integration/bunjs-only-snippets/serve.test.ts | 82 |
1 files changed, 0 insertions, 82 deletions
diff --git a/integration/bunjs-only-snippets/serve.test.ts b/integration/bunjs-only-snippets/serve.test.ts deleted file mode 100644 index 8b785dd25..000000000 --- a/integration/bunjs-only-snippets/serve.test.ts +++ /dev/null @@ -1,82 +0,0 @@ -import { file, serve } from "bun"; -import { expect, it } from "bun:test"; -import { readFileSync } from "fs"; -import { resolve } from "path"; - -var port = 40000; - -it("should work for a hello world", async () => { - const server = serve({ - port: port++, - fetch(req) { - return new Response(`Hello, world!`); - }, - }); - const response = await fetch(`http://localhost:${server.port}`); - expect(await response.text()).toBe("Hello, world!"); - server.stop(); -}); - -it("should work for a file", async () => { - const fixture = resolve(import.meta.dir, "./fetch.js.txt"); - const textToExpect = readFileSync(fixture, "utf-8"); - - const server = serve({ - port: port++, - fetch(req) { - return new Response(file(fixture)); - }, - }); - const response = await fetch(`http://localhost:${server.port}`); - expect(await response.text()).toBe(textToExpect); - server.stop(); -}); - -it("fetch should work with headers", async () => { - const fixture = resolve(import.meta.dir, "./fetch.js.txt"); - - const server = serve({ - port: port++, - fetch(req) { - if (req.headers.get("X-Foo") !== "bar") { - return new Response("X-Foo header not set", { status: 500 }); - } - return new Response(file(fixture), { - headers: { "X-Both-Ways": "1" }, - }); - }, - }); - const response = await fetch(`http://localhost:${server.port}`, { - headers: { - "X-Foo": "bar", - }, - }); - - expect(response.status).toBe(200); - expect(response.headers.get("X-Both-Ways")).toBe("1"); - server.stop(); -}); - -var count = 200; -it(`should work for a file ${count} times`, async () => { - const fixture = resolve(import.meta.dir, "./fetch.js.txt"); - const textToExpect = readFileSync(fixture, "utf-8"); - var ran = 0; - const server = serve({ - port: port++, - async fetch(req) { - return new Response(file(fixture)); - }, - }); - - // this gets stuck if run about 200 times awaiting all the promises - // when the promises are run altogether, instead of one at a time - // it's hard to say if this only happens here due to some weird stuff with the test runner - // or if it's "real" issue - for (let i = 0; i < count; i++) { - const response = await fetch(`http://localhost:${server.port}`); - expect(await response.text()).toBe(textToExpect); - } - - server.stop(); -}); |