MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / mockFetch

Function mockFetch

packages/cli/src/registry/resolver.test.ts:50–77  ·  view source on GitHub ↗
(
  overrides: {
    registryFails?: boolean;
    missing?: string[];
    /** Inject `registryDependencies` into served items, keyed by item name. */
    dependencies?: Record<string, string[] | undefined>;
  } = {},
)

Source from the content-addressed store, hash-verified

48}
49
50function 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
79function uniqueBaseUrl(): string {
80 // Unique per-test so the 24h on-disk cache doesn't pollute sibling tests.

Callers 1

resolver.test.tsFile · 0.70

Calls 1

buildItemFunction · 0.70

Tested by

no test coverage detected