From c5bbee94fe701f9929b03732f7881e27aca2e60c Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Tue, 1 Aug 2023 14:06:34 +0200 Subject: [PATCH] feat(app): handle bigint return types (resolves #474) --- src/app.ts | 5 +++++ test/app.test.ts | 12 +++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/app.ts b/src/app.ts index 636d4b2a..4d827a6e 100644 --- a/src/app.ts +++ b/src/app.ts @@ -231,5 +231,10 @@ function handleHandlerResponse(event: H3Event, val: any, jsonSpace?: number) { return send(event, JSON.stringify(val, undefined, jsonSpace), MIMES.json); } + // BigInt + if (valType === "bigint") { + return send(event, val.toString(), MIMES.json); + } + return false; } diff --git a/test/app.test.ts b/test/app.test.ts index 38709293..880c09db 100644 --- a/test/app.test.ts +++ b/test/app.test.ts @@ -15,7 +15,7 @@ describe("app", () => { let request: SuperTest; beforeEach(() => { - app = createApp({ debug: false }); + app = createApp({ debug: true }); request = supertest(toNodeListener(app)); }); @@ -29,6 +29,16 @@ describe("app", () => { expect(res.body).toEqual({ url: "/" }); }); + it("can return bigint directly", async () => { + app.use( + "/", + eventHandler(() => BigInt(9_007_199_254_740_991)) + ); + const res = await request.get("/"); + + expect(res.text).toBe("9007199254740991"); + }); + it("can return Response directly", async () => { app.use( "/",