Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
import { vi } from 'vitest';
type ApiRoute = (url: URL, init?: RequestInit) => Response;
export function stubApiRoutes(routes: Readonly<Record<string, ApiRoute>>): void {
const passthrough = globalThis.fetch;
vi.stubGlobal(
'fetch',
async (input: RequestInfo | URL, init?: RequestInit): Promise<Response> => {
const url = new URL(input instanceof Request ? input.url : String(input), location.href);
const route = routes[url.pathname];
if (route) return route(url, init);
if (url.pathname.startsWith('/api/')) {
throw new Error(`the test stubs no response for ${url.pathname}`);
}
return passthrough(input, init);
},
);
}