aboutsummaryrefslogtreecommitdiff
path: root/test/bun.js
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-06-27 05:46:26 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-06-27 05:46:26 -0700
commit292f60a8a840111e135312c1d604154a9908a325 (patch)
tree04c330dc0bc228f0a6173919d9044f3ac9df354a /test/bun.js
parentcfcd8a1531c762859e221932ada50f5a1da5bfd0 (diff)
downloadbun-292f60a8a840111e135312c1d604154a9908a325.tar.gz
bun-292f60a8a840111e135312c1d604154a9908a325.tar.zst
bun-292f60a8a840111e135312c1d604154a9908a325.zip
[http server] couple more tests
Diffstat (limited to '')
-rw-r--r--test/bun.js/serve.test.ts47
1 files changed, 46 insertions, 1 deletions
diff --git a/test/bun.js/serve.test.ts b/test/bun.js/serve.test.ts
index 0bf81f228..dd491c297 100644
--- a/test/bun.js/serve.test.ts
+++ b/test/bun.js/serve.test.ts
@@ -193,6 +193,36 @@ it("should work for a hello world", async () => {
server.stop();
});
+it("should work for a blob", async () => {
+ const fixture = resolve(import.meta.dir, "./fetch.js.txt");
+ const textToExpect = readFileSync(fixture, "utf-8");
+
+ const server = serve({
+ port: port++,
+ fetch(req) {
+ return new Response(new Blob([textToExpect]));
+ },
+ });
+ const response = await fetch(`http://localhost:${server.port}`);
+ expect(await response.text()).toBe(textToExpect);
+ server.stop();
+});
+
+it("should work for a blob stream", async () => {
+ const fixture = resolve(import.meta.dir, "./fetch.js.txt");
+ const textToExpect = readFileSync(fixture, "utf-8");
+
+ const server = serve({
+ port: port++,
+ fetch(req) {
+ return new Response(new Blob([textToExpect]).stream());
+ },
+ });
+ const response = await fetch(`http://localhost:${server.port}`);
+ expect(await response.text()).toBe(textToExpect);
+ server.stop();
+});
+
it("should work for a file", async () => {
const fixture = resolve(import.meta.dir, "./fetch.js.txt");
const textToExpect = readFileSync(fixture, "utf-8");
@@ -208,6 +238,21 @@ it("should work for a file", async () => {
server.stop();
});
+it("should work for a file stream", async () => {
+ const fixture = resolve(import.meta.dir, "./fetch.js.txt");
+ const textToExpect = readFileSync(fixture, "utf-8");
+
+ const server = serve({
+ port: port++,
+ fetch(req) {
+ return new Response(file(fixture).stream());
+ },
+ });
+ const response = await fetch(`http://localhost:${server.port}`);
+ expect(await response.text()).toBe(textToExpect);
+ server.stop();
+});
+
it("fetch should work with headers", async () => {
const fixture = resolve(import.meta.dir, "./fetch.js.txt");
@@ -234,7 +279,7 @@ it("fetch should work with headers", async () => {
});
var count = 200;
-it(`should work for a file ${count} times`, async () => {
+it(`should work for a file ${count} times serial`, async () => {
const fixture = resolve(import.meta.dir, "./fetch.js.txt");
const textToExpect = readFileSync(fixture, "utf-8");
var ran = 0;