From 03689da8219dcd3993c8c38503370160b696d79a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Tue, 22 Sep 2026 17:31:42 -0400 Subject: [PATCH] test(studio): cover poster, srcset and sub-composition preview asset URLs Also types the Vite adapter bundler with BundleOptions, so the shared preview options are checked against the real option set. --- .../server/studioServer.previewAssets.test.ts | 40 +++++++++++++++---- packages/studio/vite.adapter.ts | 8 +--- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/packages/cli/src/server/studioServer.previewAssets.test.ts b/packages/cli/src/server/studioServer.previewAssets.test.ts index f280dd8923..14f6cb4151 100644 --- a/packages/cli/src/server/studioServer.previewAssets.test.ts +++ b/packages/cli/src/server/studioServer.previewAssets.test.ts @@ -9,17 +9,33 @@ const COMPOSITION = `
+ + +
`; +const SCENE = ``; + +const PIC = Buffer.alloc(4096, 7); +const PIC_2X = Buffer.alloc(8192, 9); + let root: string; let server: StudioServer; beforeEach(() => { root = fs.mkdtempSync(path.join(tmpdir(), "hf-preview-assets-")); fs.mkdirSync(path.join(root, "assets")); + fs.mkdirSync(path.join(root, "compositions")); fs.writeFileSync(path.join(root, "index.html"), COMPOSITION); - fs.writeFileSync(path.join(root, "assets", "pic.png"), Buffer.alloc(4096, 7)); + fs.writeFileSync(path.join(root, "compositions", "scene.html"), SCENE); + fs.writeFileSync(path.join(root, "assets", "pic.png"), PIC); + fs.writeFileSync(path.join(root, "assets", "pic@2x.png"), PIC_2X); fs.writeFileSync(path.join(root, "assets", "brand.ttf"), Buffer.alloc(1024, 3)); + fs.writeFileSync(path.join(root, "assets", "clip.mp4"), Buffer.alloc(1024, 5)); server = createStudioServer({ projectDir: root, projectName: "film" }); }); @@ -28,8 +44,14 @@ afterEach(() => { fs.rmSync(root, { recursive: true, force: true }); }); +async function fetchAsset(url: string): Promise { + const response = await server.app.request(`/api/projects/film/preview/${url}`); + expect(response.status).toBe(200); + return Buffer.from(await response.arrayBuffer()); +} + describe("studio preview document", () => { - it("keeps image and font URLs instead of inlining them as base64", async () => { + it("keeps every asset URL instead of inlining it as base64", async () => { const response = await server.app.request("/api/projects/film/preview"); const html = await response.text(); @@ -37,13 +59,15 @@ describe("studio preview document", () => { // Served by the bundler, not the raw-HTML fallback, so the assertions below mean something. expect(html).toContain('data-hyperframes-preview-runtime="1" src="/api/runtime.js"'); expect(html).not.toContain("base64,"); - expect(html.match(/src="assets\/pic\.png"/g)).toHaveLength(2); + expect(html.match(/src="assets\/pic\.png"/g)?.length).toBeGreaterThanOrEqual(3); expect(html).toContain("url(assets/brand.ttf)"); - // The kept URL resolves against the preview's through the asset route. + expect(html).toContain('poster="assets/pic.png"'); + expect(html).toContain('srcset="assets/pic.png 1x, assets/pic@2x.png 2x"'); + // Kept URLs resolve against the preview's through the asset route. expect(html).toContain(''); - const asset = await server.app.request("/api/projects/film/preview/assets/pic.png"); - expect(asset.status).toBe(200); - expect(asset.headers.get("Content-Type")).toBe("image/png"); - expect(Buffer.from(await asset.arrayBuffer())).toEqual(Buffer.alloc(4096, 7)); + expect(await fetchAsset("assets/pic.png")).toEqual(PIC); + const nested = html.match(/]*id="nested" src="([^"]+)"/)?.[1]; + expect(nested).toBe("assets/pic@2x.png"); + expect(await fetchAsset(nested ?? "")).toEqual(PIC_2X); }); }); diff --git a/packages/studio/vite.adapter.ts b/packages/studio/vite.adapter.ts index 88a714080e..4a4578c779 100644 --- a/packages/studio/vite.adapter.ts +++ b/packages/studio/vite.adapter.ts @@ -24,6 +24,7 @@ import { PREVIEW_BUNDLE_OPTIONS, } from "@hyperframes/studio-server"; import type { RegistryItem } from "@hyperframes/core/registry"; +import type { BundleOptions } from "@hyperframes/core/compiler"; import { createRetryingModuleLoader, ensureProducerDist } from "./vite.producer"; import { createStudioDevRenderBodyScripts } from "./vite.studioMotion"; import { generateThumbnail, findSystemChrome } from "./vite.browser"; @@ -101,12 +102,7 @@ export function createViteAdapter( server: ViteDevServer, signatureCache: ProjectSignatureCache, ): StudioApiAdapter { - let _bundler: - | (( - dir: string, - options?: { runtime?: "inline" | "placeholder"; inlineColorGradingLuts?: boolean }, - ) => Promise) - | null = null; + let _bundler: ((dir: string, options?: BundleOptions) => Promise) | null = null; let _producerModuleLoader: | (() => Promise<{ createRenderJob: (config: {