-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "test-got", | ||
"dependencies": { | ||
"got": "13.0.0" | ||
} | ||
} |