0
0
mirror of https://github.com/honojs/hono.git synced 2024-11-21 18:18:57 +01:00

fix(vercel): remove requestContext (#3549)

This commit is contained in:
Yusuke Wada 2024-10-23 09:36:24 +09:00 committed by GitHub
parent 631c0010ca
commit 7735f2f03c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 22 deletions

View File

@ -1,28 +1,23 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Hono } from '../../hono'
import { handle } from './handler'
describe('Adapter for Next.js', () => {
it('Should return 200 response with a `waitUntil` value', async () => {
it('Should return 200 response', async () => {
const app = new Hono()
app.get('/api/foo', async (c) => {
app.get('/api/author/:name', async (c) => {
const name = c.req.param('name')
return c.json({
path: '/api/foo',
/**
* Checking if the `waitUntil` value is passed.
*/
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
waitUntil: c.executionCtx.waitUntil() as any,
path: '/api/author/:name',
name,
})
})
const handler = handle(app)
const req = new Request('http://localhost/api/foo')
const res = await handler(req, { waitUntil: () => 'waitUntil' } as any)
const req = new Request('http://localhost/api/author/hono')
const res = await handler(req)
expect(res.status).toBe(200)
expect(await res.json()).toEqual({
path: '/api/foo',
waitUntil: 'waitUntil',
path: '/api/author/:name',
name: 'hono',
})
})
@ -38,10 +33,6 @@ describe('Adapter for Next.js', () => {
const handler = handle(app)
const req = new Request('http://localhost/api/error')
expect(() =>
handler(req, {
waitUntil: () => {},
} as any)
).toThrowError('Custom Error')
expect(() => handler(req)).toThrowError('Custom Error')
})
})

View File

@ -1,9 +1,8 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import type { Hono } from '../../hono'
import type { FetchEventLike } from '../../types'
export const handle =
(app: Hono<any, any, any>) =>
(req: Request, requestContext: FetchEventLike): Response | Promise<Response> => {
return app.fetch(req, {}, requestContext as any)
(req: Request): Response | Promise<Response> => {
return app.fetch(req)
}