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 00000000000000..3106b924e6e932 --- /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 00000000000000..e44c5289b6c76d --- /dev/null +++ b/test/js/third_party/got/package.json @@ -0,0 +1,6 @@ +{ + "name": "test-got", + "dependencies": { + "got": "13.0.0" + } +}