0
0
mirror of https://github.com/honojs/hono.git synced 2024-12-01 10:51:01 +00:00
hono/deno_dist/helper/testing/index.ts
hagishi 2e5e1b2f0c
feat: add Hono test client (RPC) (#1451)
* feat: add test client helper

* refactor:  rename from hc to testClient
2023-09-17 09:04:07 +09:00

19 lines
618 B
TypeScript

import { hc } from '../../client/index.ts'
import type { Hono } from '../../hono.ts'
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type ExtractEnv<T> = T extends Hono<infer E, any, any> ? E : never
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const testClient = <T extends Hono<any, any, any>>(
app: T,
Env?: ExtractEnv<T>['Bindings'] | {},
executionCtx?: ExecutionContext
) => {
const customFetch = (input: RequestInfo | URL, init?: RequestInit) => {
return app.request(input, init, Env, executionCtx)
}
return hc<typeof app>('', { fetch: customFetch })
}