Open bogeychan opened 3 months ago
1.1.3
WSL Ubuntu
// test.test.ts import { t, Elysia, ParseError, NotFoundError, ValidationError, InternalServerError, } from "elysia"; import { describe, it, expect, beforeEach } from "bun:test"; let isOnResponseCalled: boolean; class CustomError extends Error {} const app = new Elysia() .onAfterResponse(() => { isOnResponseCalled = true; }) .post("/", () => "yay", { body: t.Object({ test: t.String(), }), }) .get("/customError", () => { throw new CustomError("whelp"); }) .get("/internalError", () => { throw new InternalServerError("whelp"); }); beforeEach(() => { isOnResponseCalled = false; }); export const newReq = (params?: { path?: string; headers?: Record<string, string>; method?: string; body?: string; }) => new Request(`http://localhost${params?.path ?? "/"}`, params); describe("Error", () => { it.each([ ["NotFoundError", newReq({ path: "/notFound" })], [ "ParseError", newReq({ method: "POST", headers: { "Content-Type": "application/json" }, body: "", }), ], [ "ValidationError", newReq({ method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({}), }), ], ["CustomError", newReq({ path: "/customError" })], ["InternalServerError", newReq({ path: "/internalError" })], ])("%s should call onResponse", async (_name, request) => { expect(isOnResponseCalled).toBeFalse(); await app.handle(request); expect(isOnResponseCalled).toBeTrue(); }); });
bun test
all tests pass:
✓ Error > NotFoundError should call onResponse ✓ Error > ParseError should call onResponse ✓ Error > ValidationError should call onResponse ✓ Error > CustomError should call onResponse ✓ Error > InternalServerError should call onResponse
NotFoundError test fails:
✗ Error > NotFoundError should call onResponse ✓ Error > ParseError should call onResponse ✓ Error > ValidationError should call onResponse ✓ Error > CustomError should call onResponse ✓ Error > InternalServerError should call onResponse
works as expected with aot: false
aot: false
What version of Elysia.JS is running?
1.1.3
What platform is your computer?
WSL Ubuntu
What steps can reproduce the bug?
What is the expected behavior?
all tests pass:
What do you see instead?
NotFoundError test fails:
Additional information
works as expected with
aot: false