|
| 1 | +// A composition nested in a timed scene through a neutral wrapper plays on the scene's clock, not |
| 2 | +// the root's (#4334). Needs Chrome + ffmpeg: integration lane. |
| 3 | + |
| 4 | +import { copyFileSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; |
| 5 | +import { tmpdir } from "node:os"; |
| 6 | +import { join, resolve } from "node:path"; |
| 7 | +import { afterAll, beforeAll, describe, expect, it } from "vitest"; |
| 8 | +import { resolveConfig } from "@hyperframes/engine"; |
| 9 | +import { createRenderJob, executeRenderJob } from "../renderOrchestrator.js"; |
| 10 | +import { HAS_FFMPEG, frameLevels } from "./frameLevelsTestFixtures.js"; |
| 11 | + |
| 12 | +const WIDTH = 160; |
| 13 | +const HEIGHT = 90; |
| 14 | +const FPS = 30; |
| 15 | + |
| 16 | +// The scene starts at 1 s; the inner composition fades its box in over its own first second. |
| 17 | +const INDEX = `<!DOCTYPE html> |
| 18 | +<html lang="en"> |
| 19 | +<head> |
| 20 | + <meta charset="UTF-8" /> |
| 21 | + <script src="assets/gsap.min.js"></script> |
| 22 | + <style> |
| 23 | + * { margin: 0; padding: 0; } body { overflow: hidden; background: #000; } |
| 24 | + #inner, #box { position: absolute; inset: 0; } |
| 25 | + #box { background: #fff; opacity: 0; } |
| 26 | + </style> |
| 27 | +</head> |
| 28 | +<body> |
| 29 | + <div id="root" data-composition-id="main" data-start="0" data-duration="2" |
| 30 | + data-width="${WIDTH}" data-height="${HEIGHT}" data-fps="${FPS}"> |
| 31 | + <div id="scene" data-composition-id="scene" data-start="1" data-duration="1" data-track-index="0" |
| 32 | + data-width="${WIDTH}" data-height="${HEIGHT}"> |
| 33 | + <section> |
| 34 | + <div id="inner" data-composition-id="inner" data-duration="1" |
| 35 | + data-width="${WIDTH}" data-height="${HEIGHT}"><div id="box"></div></div> |
| 36 | + </section> |
| 37 | + </div> |
| 38 | + </div> |
| 39 | + <script> |
| 40 | + window.__timelines["main"] = gsap.timeline({ paused: true }); |
| 41 | + window.__timelines["scene"] = gsap.timeline({ paused: true }).set({}, {}, 1); |
| 42 | + window.__timelines["inner"] = gsap |
| 43 | + .timeline({ paused: true }) |
| 44 | + .to("#box", { opacity: 1, duration: 1, ease: "none" }); |
| 45 | + </script> |
| 46 | +</body> |
| 47 | +</html> |
| 48 | +`; |
| 49 | + |
| 50 | +let root: string; |
| 51 | + |
| 52 | +describe.skipIf(!HAS_FFMPEG)("a composition behind a wrapper — real render (#4334)", () => { |
| 53 | + let levels: number[]; |
| 54 | + |
| 55 | + beforeAll(async () => { |
| 56 | + root = mkdtempSync(join(tmpdir(), "hf-wrapped-mount-")); |
| 57 | + mkdirSync(join(root, "assets"), { recursive: true }); |
| 58 | + copyFileSync( |
| 59 | + resolve(import.meta.dirname, "../../../../core/node_modules/gsap/dist/gsap.min.js"), |
| 60 | + join(root, "assets/gsap.min.js"), |
| 61 | + ); |
| 62 | + writeFileSync(join(root, "index.html"), INDEX); |
| 63 | + const job = createRenderJob({ |
| 64 | + fps: FPS, |
| 65 | + quality: "draft", |
| 66 | + format: "mp4", |
| 67 | + hdrMode: "force-sdr", |
| 68 | + workers: 1, |
| 69 | + producerConfig: resolveConfig({ browserGpuMode: "software" }), |
| 70 | + }); |
| 71 | + const output = join(root, "out.mp4"); |
| 72 | + await executeRenderJob(job, root, output); |
| 73 | + levels = frameLevels(output, WIDTH, HEIGHT); |
| 74 | + }, 120_000); |
| 75 | + |
| 76 | + afterAll(() => { |
| 77 | + if (root) rmSync(root, { recursive: true, force: true }); |
| 78 | + }); |
| 79 | + |
| 80 | + it("fades the box in over the scene's second, not the root's first", () => { |
| 81 | + expect(levels).toHaveLength(2 * FPS); |
| 82 | + expect(levels[Math.round(0.5 * FPS)]!).toBeLessThan(5); |
| 83 | + // Half way through the scene the box is half faded in (about 128 of 255). |
| 84 | + expect(levels[Math.round(1.5 * FPS)]!).toBeGreaterThan(90); |
| 85 | + expect(levels[Math.round(1.5 * FPS)]!).toBeLessThan(165); |
| 86 | + expect(levels[Math.round(1.25 * FPS)]!).toBeLessThan(levels[Math.round(1.75 * FPS)]!); |
| 87 | + }); |
| 88 | +}); |
0 commit comments