testing setup
This commit is contained in:
26
test/trpc/vitest.trpcProxyClient.ts
Normal file
26
test/trpc/vitest.trpcProxyClient.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { createTRPCProxyClient, httpBatchLink } from '@trpc/client'
|
||||
import { fetchRequestHandler } from '@trpc/server/adapters/fetch'
|
||||
import { trpcRouter, type TrpcRouter } from '~/server/routers/_app'
|
||||
|
||||
// This simulates the server without HTTP
|
||||
function serverHandler(path: string, req: Request) {
|
||||
return fetchRequestHandler({
|
||||
endpoint: '/api/trpc',
|
||||
router: trpcRouter,
|
||||
req,
|
||||
createContext: () => ({}),
|
||||
})
|
||||
}
|
||||
|
||||
export function createTestTrpcClient() {
|
||||
return createTRPCProxyClient<TrpcRouter>({
|
||||
links: [
|
||||
httpBatchLink({
|
||||
url: 'http://localhost/api/trpc',
|
||||
fetch: (input, init) => {
|
||||
return serverHandler(input as string, new Request(input as string, init))
|
||||
},
|
||||
}),
|
||||
],
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user