(
overrides: {
registryFails?: boolean;
missing?: string[];
/** Inject `registryDependencies` into served items, keyed by item name. */
dependencies?: Record<string, string[] | undefined>;
} = {},
)
| 48 | } |
| 49 | |
| 50 | function mockFetch( |
| 51 | overrides: { |
| 52 | registryFails?: boolean; |
| 53 | missing?: string[]; |
| 54 | /** Inject `registryDependencies` into served items, keyed by item name. */ |
| 55 | dependencies?: Record<string, string[] | undefined>; |
| 56 | } = {}, |
| 57 | ): void { |
| 58 | vi.stubGlobal( |
| 59 | "fetch", |
| 60 | vi.fn(async (urlInput: string | URL) => { |
| 61 | const url = typeof urlInput === "string" ? urlInput : urlInput.toString(); |
| 62 | if (url.endsWith("/registry.json") && !overrides.registryFails) { |
| 63 | return new Response(JSON.stringify(MANIFEST), { status: 200 }); |
| 64 | } |
| 65 | const m = /\/(examples|blocks|components)\/([^/]+)\/registry-item\.json$/.exec(url); |
| 66 | if (m && !overrides.missing?.includes(m[2]!)) { |
| 67 | const type = m[1] === "examples" ? "hyperframes:example" : "hyperframes:block"; |
| 68 | const item = buildItem(m[2]!, type); |
| 69 | if (overrides.dependencies && item.name in overrides.dependencies) { |
| 70 | item.registryDependencies = overrides.dependencies[item.name]; |
| 71 | } |
| 72 | return new Response(JSON.stringify(item), { status: 200 }); |
| 73 | } |
| 74 | return new Response("not found", { status: 404 }); |
| 75 | }), |
| 76 | ); |
| 77 | } |
| 78 | |
| 79 | function uniqueBaseUrl(): string { |
| 80 | // Unique per-test so the 24h on-disk cache doesn't pollute sibling tests. |
no test coverage detected