diff options
author | 2023-08-29 15:20:30 -0700 | |
---|---|---|
committer | 2023-09-13 17:26:08 -0700 | |
commit | bdc5aedecd39d6d09caab83842f82e0d6790c4c7 (patch) | |
tree | c44d2a09e32583be7c1bb3a19c47a6bfa59cfc33 | |
parent | fa32687552297a1f8c72280747b668752681bc30 (diff) | |
download | bun-bdc5aedecd39d6d09caab83842f82e0d6790c4c7.tar.gz bun-bdc5aedecd39d6d09caab83842f82e0d6790c4c7.tar.zst bun-bdc5aedecd39d6d09caab83842f82e0d6790c4c7.zip |
got test
-rw-r--r-- | test/js/third_party/got/got.test.ts | 38 | ||||
-rw-r--r-- | test/js/third_party/got/package.json | 6 |
2 files changed, 44 insertions, 0 deletions
diff --git a/test/js/third_party/got/got.test.ts b/test/js/third_party/got/got.test.ts new file mode 100644 index 000000000..3106b924e --- /dev/null +++ b/test/js/third_party/got/got.test.ts @@ -0,0 +1,38 @@ +import { test, expect, describe } from "bun:test"; +import got from "got"; +import { Readable } from "stream"; + +describe("got", () => { + test("should work", async () => { + const server = Bun.serve({ + fetch(request, server) { + return new Response("Hello World!"); + }, + }); + + const response = await got(`http://${server.hostname}:${server.port}/`); + expect(response.statusCode).toBe(200); + expect(response.body).toBe("Hello World!"); + expect(response.headers["content-length"]).toBe("12"); + expect(response.url).toBe(`http://${server.hostname}:${server.port}/`); + + server.stop(); + }); + + test("json response", async () => { + const server = Bun.serve({ + async fetch(request, server) { + expect(request.method).toBe("POST"); + const data = await request.json(); + expect(data).toEqual({ hello: "world" }); + + return new Response("Hello world"); + }, + }); + + const stream = await got.post(`http://${server.hostname}:${server.port}/`, { json: { hello: "world" } }); + expect(stream.body).toBe("Hello World!"); + + server.stop(); + }); +}); diff --git a/test/js/third_party/got/package.json b/test/js/third_party/got/package.json new file mode 100644 index 000000000..e44c5289b --- /dev/null +++ b/test/js/third_party/got/package.json @@ -0,0 +1,6 @@ +{ + "name": "test-got", + "dependencies": { + "got": "13.0.0" + } +} |