mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-23 11:29:54 +00:00
Studio asked for the preview only once the player mounted, about 640 ms into a first open. It now requests it the moment the page loads, and again when the hash names another project, so the build or cache read overlaps Studio's boot.
23 lines
811 B
TypeScript
23 lines
811 B
TypeScript
// @vitest-environment happy-dom
|
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import { prefetchPreviewForHash } from "./previewPrefetch";
|
|
|
|
describe("prefetchPreviewForHash", () => {
|
|
afterEach(() => vi.unstubAllGlobals());
|
|
|
|
it("requests the opening project's preview once, not on every hash update", () => {
|
|
const fetchStub = vi.fn(() => Promise.resolve(new Response("")));
|
|
vi.stubGlobal("fetch", fetchStub);
|
|
|
|
prefetchPreviewForHash("#project/demo");
|
|
prefetchPreviewForHash("#project/demo?t=2&tab=design");
|
|
prefetchPreviewForHash("#project/other");
|
|
prefetchPreviewForHash("#settings");
|
|
|
|
expect(fetchStub.mock.calls.map(([url]) => new URL(String(url)).pathname)).toEqual([
|
|
"/api/projects/demo/preview",
|
|
"/api/projects/other/preview",
|
|
]);
|
|
});
|
|
});
|