diff options
author | 2022-08-29 13:34:44 -0700 | |
---|---|---|
committer | 2022-08-29 13:34:44 -0700 | |
commit | 15415c72d55255b7d878395bf521c6f5865fc93f (patch) | |
tree | dd9d6ad8aa7154c8ac8ce71eee6e7f6799dbecc2 /test/bun.js | |
parent | 9d8fb814130a5af6206233eb5c08d974b75148ac (diff) | |
download | bun-request-body-stream.tar.gz bun-request-body-stream.tar.zst bun-request-body-stream.zip |
Define `Request.prototype.body`request-body-stream
Diffstat (limited to 'test/bun.js')
-rw-r--r-- | test/bun.js/serve.test.ts | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/test/bun.js/serve.test.ts b/test/bun.js/serve.test.ts index 8961372c1..fb541da24 100644 --- a/test/bun.js/serve.test.ts +++ b/test/bun.js/serve.test.ts @@ -1,4 +1,4 @@ -import { file, serve } from "bun"; +import { file, readableStreamToText, serve } from "bun"; import { describe, expect, it } from "bun:test"; import { readFileSync } from "fs"; import { resolve } from "path"; @@ -12,6 +12,26 @@ class TestPass extends Error { } } +describe("request body streaming", () => { + it("works", async () => { + var server = serve({ + port: port++, + development: false, + + async fetch(req: Request) { + const text = await readableStreamToText(req.body); + return new Response(text); + }, + }); + + var res = await fetch(`http://localhost:${server.port}`, { + body: "hello", + method: "POST", + }); + expect(await res.text()).toBe("hello"); + }); +}); + describe("streaming", () => { describe("error handler", () => { it("throw on pull reports an error and close the connection", async () => { |