Skip to content

Commit

Permalink
feat(app): handle bigint return types (resolves #474)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Aug 1, 2023
1 parent 4af66eb commit c5bbee9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
12 changes: 11 additions & 1 deletion test/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe("app", () => {
let request: SuperTest<Test>;

beforeEach(() => {
app = createApp({ debug: false });
app = createApp({ debug: true });
request = supertest(toNodeListener(app));
});

Expand All @@ -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(
"/",
Expand Down

0 comments on commit c5bbee9

Please sign in to comment.