diff options
author | 2023-07-11 12:48:32 -0700 | |
---|---|---|
committer | 2023-07-11 12:48:32 -0700 | |
commit | ae7bc37e94185726196a9cf77850379390904d4a (patch) | |
tree | 48467d82dc537c25a99eb6af355f5a3ce1cd72d8 /test | |
parent | 31ab56d36238528c6f44c52a6cbf600744a91f0a (diff) | |
download | bun-ae7bc37e94185726196a9cf77850379390904d4a.tar.gz bun-ae7bc37e94185726196a9cf77850379390904d4a.tar.zst bun-ae7bc37e94185726196a9cf77850379390904d4a.zip |
fix iterating stack trace (#3600)
* `i + 1` and remove `defer`
* a test
* fix test
Diffstat (limited to 'test')
-rw-r--r-- | test/js/bun/http/error-response.js | 8 | ||||
-rw-r--r-- | test/js/bun/http/serve.test.ts | 15 |
2 files changed, 23 insertions, 0 deletions
diff --git a/test/js/bun/http/error-response.js b/test/js/bun/http/error-response.js new file mode 100644 index 000000000..3284c146b --- /dev/null +++ b/test/js/bun/http/error-response.js @@ -0,0 +1,8 @@ +const s = Bun.serve({ + fetch(req, res) { + s.stop(true); + throw new Error("1"); + }, + port: 0, +}); +fetch(`http://${s.hostname}:${s.port}`).then(res => console.log(res.status)); diff --git a/test/js/bun/http/serve.test.ts b/test/js/bun/http/serve.test.ts index 7182ba68d..bba35c085 100644 --- a/test/js/bun/http/serve.test.ts +++ b/test/js/bun/http/serve.test.ts @@ -2,8 +2,10 @@ import { file, gc, Serve, serve, Server } from "bun"; import { afterEach, describe, it, expect, afterAll } from "bun:test"; import { readFileSync, writeFileSync } from "fs"; import { resolve } from "path"; +import { bunExe, bunEnv } from "harness"; import { renderToReadableStream } from "react-dom/server"; import app_jsx from "./app.jsx"; +import { spawn } from "child_process"; type Handler = (req: Request) => Response; afterEach(() => gc(true)); @@ -980,6 +982,19 @@ describe("should support Content-Range with Bun.file()", () => { } }); +it("formats error responses correctly", async () => { + const c = spawn(bunExe(), ["./error-response.js"], { cwd: import.meta.dir, env: bunEnv }); + + var output = ""; + c.stderr.on("data", chunk => { + output += chunk.toString(); + }); + c.stderr.on("end", () => { + expect(output).toContain('throw new Error("1");'); + c.kill(); + }); +}); + it("request body and signal life cycle", async () => { { const headers = { |