Skip to content

Commit

Permalink
got test
Browse files Browse the repository at this point in the history
  • Loading branch information
paperdave committed Aug 29, 2023
1 parent 163b45c commit dc9c6c4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
38 changes: 38 additions & 0 deletions test/js/third_party/got/got.test.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
6 changes: 6 additions & 0 deletions test/js/third_party/got/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "test-got",
"dependencies": {
"got": "13.0.0"
}
}

0 comments on commit dc9c6c4

Please sign in to comment.