diff options
author | 2022-06-27 05:46:26 -0700 | |
---|---|---|
committer | 2022-06-27 05:46:26 -0700 | |
commit | 292f60a8a840111e135312c1d604154a9908a325 (patch) | |
tree | 04c330dc0bc228f0a6173919d9044f3ac9df354a | |
parent | cfcd8a1531c762859e221932ada50f5a1da5bfd0 (diff) | |
download | bun-292f60a8a840111e135312c1d604154a9908a325.tar.gz bun-292f60a8a840111e135312c1d604154a9908a325.tar.zst bun-292f60a8a840111e135312c1d604154a9908a325.zip |
[http server] couple more tests
-rw-r--r-- | src/bun.js/builtins/js/ReadableStreamInternals.js | 1 | ||||
-rw-r--r-- | test/bun.js/serve.test.ts | 47 |
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; |