|
| 1 | +import { afterEach, describe, expect, it, vi } from "vitest"; |
| 2 | +import { mkdtempSync, rmSync, writeFileSync } from "node:fs"; |
| 3 | +import { tmpdir } from "node:os"; |
| 4 | +import { join } from "node:path"; |
| 5 | + |
| 6 | +const probed = vi.hoisted(() => ({ paths: [] as string[] })); |
| 7 | + |
| 8 | +vi.mock("@hyperframes/engine", async (importOriginal) => { |
| 9 | + const actual = await importOriginal<typeof import("@hyperframes/engine")>(); |
| 10 | + return { |
| 11 | + ...actual, |
| 12 | + extractMediaMetadata: async (path: string) => { |
| 13 | + probed.paths.push(path); |
| 14 | + return { durationSeconds: 1, isVFR: false }; |
| 15 | + }, |
| 16 | + probeMediaProfile: async (path: string) => { |
| 17 | + probed.paths.push(path); |
| 18 | + return { hasVideoStream: true, hasAudioStream: false, visualKind: "moving" }; |
| 19 | + }, |
| 20 | + analyzeKeyframeIntervals: async (path: string) => { |
| 21 | + probed.paths.push(path); |
| 22 | + return { isProblematic: false, maxIntervalSeconds: 0 }; |
| 23 | + }, |
| 24 | + }; |
| 25 | +}); |
| 26 | + |
| 27 | +vi.mock("../utils/ffprobe.js", async (importOriginal) => { |
| 28 | + const actual = await importOriginal<typeof import("../utils/ffprobe.js")>(); |
| 29 | + return { |
| 30 | + ...actual, |
| 31 | + extractMediaMetadata: async (path: string) => { |
| 32 | + probed.paths.push(path); |
| 33 | + return { durationSeconds: 1, isVFR: false }; |
| 34 | + }, |
| 35 | + }; |
| 36 | +}); |
| 37 | + |
| 38 | +import { compileForRender } from "./htmlCompiler.js"; |
| 39 | + |
| 40 | +describe("hidden video clips", () => { |
| 41 | + let projectDir: string | undefined; |
| 42 | + |
| 43 | + afterEach(() => { |
| 44 | + if (projectDir) rmSync(projectDir, { recursive: true, force: true }); |
| 45 | + projectDir = undefined; |
| 46 | + probed.paths.length = 0; |
| 47 | + }); |
| 48 | + |
| 49 | + it("are not probed or collected, while a visible clip still is", async () => { |
| 50 | + projectDir = mkdtempSync(join(tmpdir(), "hf-hidden-probe-")); |
| 51 | + for (const src of ["own.mp4", "inherited.mp4", "shown.mp4"]) { |
| 52 | + writeFileSync(join(projectDir, src), "fixture"); |
| 53 | + } |
| 54 | + const htmlPath = join(projectDir, "index.html"); |
| 55 | + writeFileSync( |
| 56 | + htmlPath, |
| 57 | + `<!doctype html><html><body> |
| 58 | + <div data-composition-id="root" data-width="320" data-height="180" data-duration="1"> |
| 59 | + <video id="own" src="own.mp4" data-hidden data-start="0" data-duration="1"></video> |
| 60 | + <div data-hidden><video id="inherited" src="inherited.mp4" data-start="0" data-duration="1"></video></div> |
| 61 | + <video id="shown" src="shown.mp4" data-start="0" data-duration="1"></video> |
| 62 | + </div> |
| 63 | + </body></html>`, |
| 64 | + ); |
| 65 | + |
| 66 | + const compiled = await compileForRender(projectDir, htmlPath, join(projectDir, "downloads")); |
| 67 | + await new Promise<void>((resolve) => setTimeout(resolve, 0)); |
| 68 | + |
| 69 | + expect(compiled.videos.map((v) => v.id)).toEqual(["shown"]); |
| 70 | + expect(probed.paths.length).toBeGreaterThan(0); |
| 71 | + expect(probed.paths.every((path) => path.endsWith("shown.mp4"))).toBe(true); |
| 72 | + }); |
| 73 | +}); |
0 commit comments