aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bun.js/builtins/js/ReadableStreamInternals.js1
-rw-r--r--test/bun.js/serve.test.ts47
2 files changed, 47 insertions, 1 deletions
diff --git a/src/bun.js/builtins/js/ReadableStreamInternals.js b/src/bun.js/builtins/js/ReadableStreamInternals.js
index 317c78171..2bd707622 100644
--- a/src/bun.js/builtins/js/ReadableStreamInternals.js
+++ b/src/bun.js/builtins/js/ReadableStreamInternals.js
@@ -951,6 +951,7 @@ function initializeTextStream(underlyingSource, highWaterMark)
var estimatedLength = 0;
var closingPromise = @newPromise();
var calledDone = false;
+
var sink = {
start() {
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;