import { afterEach, beforeEach, describe, expect, it } from "vitest"; import * as fs from "node:fs"; import * as path from "node:path"; import { STUDIO_PREVIEW_ERRORS } from "@hyperframes/core/studio-preview-mark"; import { createStudioServer, type StudioServer } from "./studioServer.js"; import { cleanupStudioServerRoot, makeStudioServerRoot } from "./studioServerTestFixture.js"; const mounts = (src: string, count: number) => `
`.repeat( count, ); let root: string; let projectDir: string; let server: StudioServer; beforeEach(() => { ({ root, projectDir } = makeStudioServerRoot("hf-preview-too-large-")); // Four levels of ten: 11,110 mounts from five small files. fs.writeFileSync( path.join(projectDir, "index.html"), `
${mounts("level-0.html", 10)}
`, ); for (let level = 0; level < 3; level += 1) { fs.writeFileSync( path.join(projectDir, `level-${level}.html`), ``, ); } fs.writeFileSync( path.join(projectDir, "level-3.html"), ``, ); server = createStudioServer({ projectDir, projectName: "film" }); }); afterEach(() => { cleanupStudioServerRoot(server, root); }); describe("studio preview of a project over the mount limit", () => { it("serves the refusal, not the raw page that would expand the mounts in the browser", async () => { const response = await server.app.request("/api/projects/film/preview"); const html = await response.text(); expect(html).toContain(`window.${STUDIO_PREVIEW_ERRORS}=[`); expect(html).toContain("Mount large or repeated scenes fewer times"); expect(html).not.toContain("

Leaf

"); expect(html).not.toContain('data-composition-src="level-0.html"'); }); });