From dc9c6c4e2eb5822ffd28e0197985eb08e06127f2 Mon Sep 17 00:00:00 2001 From: dave caruso Date: Tue, 29 Aug 2023 15:20:30 -0700 Subject: [PATCH] got test --- test/js/third_party/got/got.test.ts | 38 ++++++++++++++++++++++++++++ test/js/third_party/got/package.json | 6 +++++ 2 files changed, 44 insertions(+) create mode 100644 test/js/third_party/got/got.test.ts create mode 100644 test/js/third_party/got/package.json 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" + } +}