Download packages/kap-server/test/helpers/sharedServer.ts from SaylorTwift/kimi-code: direct link, hf CLI and curl.
- Browser
- Download file 897 Bytes
-
https://huggingface.co/SaylorTwift/kimi-code/resolve/main/packages/kap-server/test/helpers/sharedServer.ts
- Command line
-
hf download hf://SaylorTwift/kimi-code/packages/kap-server/test/helpers/sharedServer.ts
-
curl -L -o sharedServer.ts https://huggingface.co/SaylorTwift/kimi-code/resolve/main/packages/kap-server/test/helpers/sharedServer.ts
897 Bytes
| import { inject } from 'vitest'; | |
| export interface SharedServerContext { | |
| readonly base: string; | |
| readonly token: string; | |
| } | |
| declare module 'vitest' { | |
| interface ProvidedContext { | |
| readonly sharedServer: SharedServerContext; | |
| } | |
| } | |
| export function sharedServer(): SharedServerContext { | |
| return inject('sharedServer'); | |
| } | |
| export function sharedAuthHeaders(extra: Record<string, string> = {}): Record<string, string> { | |
| return { ...extra, authorization: `Bearer ${sharedServer().token}` }; | |
| } | |
| interface SharedFetchOptions { | |
| readonly method?: string; | |
| readonly headers?: Record<string, string>; | |
| readonly body?: string; | |
| readonly signal?: AbortSignal; | |
| } | |
| export async function sharedAuthedFetch(path: string, init: SharedFetchOptions = {}): Promise<Response> { | |
| return fetch(`${sharedServer().base}${path}`, { | |
| ...init, | |
| headers: sharedAuthHeaders(init.headers), | |
| } as never); | |
| } | |