mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-23 11:29:54 +00:00
test(studio): stabilize timeline performance fixtures
This commit is contained in:
@@ -5,6 +5,8 @@ import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { usePlayerStore } from "../player/store/playerStore";
|
||||
import {
|
||||
createTimelinePerformanceFixture,
|
||||
hasTimelinePerformanceFixtureLease,
|
||||
setTimelinePerformanceFixtureLease,
|
||||
type TimelinePerformanceFixtureProfile,
|
||||
} from "../player/lib/timelinePerformanceFixture";
|
||||
import { useStudioTestHooks } from "./useStudioTestHooks";
|
||||
@@ -30,6 +32,7 @@ function Probe(): null {
|
||||
|
||||
describe("timeline performance fixture", () => {
|
||||
afterEach(() => {
|
||||
setTimelinePerformanceFixtureLease(false);
|
||||
window.__studioTest = undefined;
|
||||
usePlayerStore.getState().reset();
|
||||
});
|
||||
@@ -101,9 +104,11 @@ describe("timeline performance fixture", () => {
|
||||
});
|
||||
expect(usePlayerStore.getState().elements).toHaveLength(1_000);
|
||||
expect(usePlayerStore.getState().expandedClipIds.size).toBe(1_000);
|
||||
expect(hasTimelinePerformanceFixtureLease()).toBe(true);
|
||||
unsubscribe();
|
||||
act(() => root.unmount());
|
||||
expect(window.__studioTest).toBeUndefined();
|
||||
expect(hasTimelinePerformanceFixtureLease()).toBe(false);
|
||||
});
|
||||
|
||||
it("does not mutate state when the fixture request is invalid", () => {
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
} from "../player/lib/timelinePerformanceDiagnostics";
|
||||
import {
|
||||
createTimelinePerformanceFixture,
|
||||
setTimelinePerformanceFixtureLease,
|
||||
type TimelinePerformanceFixtureSpec,
|
||||
type TimelinePerformanceFixtureSummary,
|
||||
} from "../player/lib/timelinePerformanceFixture";
|
||||
@@ -70,6 +71,7 @@ export function useStudioTestHooks({
|
||||
},
|
||||
loadTimelinePerformanceFixture: (spec) => {
|
||||
const fixture = createTimelinePerformanceFixture(spec);
|
||||
setTimelinePerformanceFixtureLease(true);
|
||||
usePlayerStore.setState({
|
||||
currentTime: 0,
|
||||
duration: fixture.summary.duration,
|
||||
@@ -91,6 +93,7 @@ export function useStudioTestHooks({
|
||||
};
|
||||
window.__studioTest = api;
|
||||
return () => {
|
||||
setTimelinePerformanceFixtureLease(false);
|
||||
window.__studioTest = undefined;
|
||||
};
|
||||
}, [applyDomSelection, buildDomSelectionFromTarget, previewIframeRef]);
|
||||
|
||||
@@ -513,6 +513,7 @@ export const Timeline = memo(function Timeline({
|
||||
<div
|
||||
ref={setContainerRef}
|
||||
aria-label="Timeline"
|
||||
data-timeline-element-count={expandedElements.length}
|
||||
className={`relative border-t select-none h-full overflow-hidden ${activeTool === "razor" ? "cursor-crosshair" : shiftHeld ? "cursor-crosshair" : "cursor-default"}`}
|
||||
onMouseMove={(e) => {
|
||||
if (activeTool === "razor" && scrollRef.current) {
|
||||
@@ -529,6 +530,7 @@ export const Timeline = memo(function Timeline({
|
||||
>
|
||||
<div
|
||||
ref={setScrollRef}
|
||||
data-timeline-scroll-viewport
|
||||
tabIndex={-1}
|
||||
className={`${zoomMode === "fit" ? "overflow-x-hidden" : "overflow-x-auto"} overflow-y-auto h-full outline-none`}
|
||||
onScroll={(e) => {
|
||||
|
||||
@@ -43,6 +43,7 @@ import {
|
||||
shouldMutePreviewAudio,
|
||||
} from "../lib/timelineIframeHelpers";
|
||||
import { scrubMusicAtSeek, stopScrubPreviewAudio } from "../lib/playbackScrub";
|
||||
import { hasTimelinePerformanceFixtureLease } from "../lib/timelinePerformanceFixture";
|
||||
import { applyCachedSourceDurations, probeMissingSourceDurations } from "../lib/mediaProbe";
|
||||
import { shouldResumeForwardPlaybackAfterSeek, shouldStopAfterSeek } from "../lib/playbackSeek";
|
||||
import { applyPreviewVariablesToUrl } from "../../hooks/previewVariablesStore";
|
||||
@@ -68,6 +69,10 @@ function timelineElementsChanged(prev: TimelineElement[], next: TimelineElement[
|
||||
});
|
||||
}
|
||||
|
||||
function resolveTimelineDuration(nextDuration: number | undefined, currentDuration: number) {
|
||||
return nextDuration ?? currentDuration;
|
||||
}
|
||||
|
||||
export function useTimelinePlayer() {
|
||||
const iframeRef = useRef<HTMLIFrameElement | null>(null);
|
||||
const rafRef = useRef<number>(0);
|
||||
@@ -85,10 +90,13 @@ export function useTimelinePlayer() {
|
||||
const { setIsPlaying, setCurrentTime, setDuration, setTimelineReady, setElements } =
|
||||
usePlayerStore.getState();
|
||||
|
||||
// The fixture lease belongs at this shared synchronization boundary so every
|
||||
// iframe discovery path has the same owner for deciding whether it may write.
|
||||
const syncTimelineElements = useCallback(
|
||||
(elements: TimelineElement[], nextDuration?: number) => {
|
||||
if (hasTimelinePerformanceFixtureLease()) return;
|
||||
const state = usePlayerStore.getState();
|
||||
const resolvedDuration = nextDuration ?? state.duration;
|
||||
const resolvedDuration = resolveTimelineDuration(nextDuration, state.duration);
|
||||
// applyCachedSourceDurations re-applies the cached probe duration: re-derived
|
||||
// elements (e.g. after a clip move) can arrive without sourceDuration, which
|
||||
// otherwise makes trimmed waveforms lose their window.
|
||||
|
||||
@@ -29,6 +29,7 @@ export interface TimelinePerformanceFixture {
|
||||
}
|
||||
|
||||
const TRACK_COUNT = 1_000;
|
||||
let fixtureLeaseActive = false;
|
||||
const PROFILE_GEOMETRY: Readonly<
|
||||
Record<TimelinePerformanceFixtureProfile, { duration: number; clipDuration: number }>
|
||||
> = Object.freeze({
|
||||
@@ -39,6 +40,15 @@ const PROFILE_GEOMETRY: Readonly<
|
||||
"remote-unsupported": { duration: 900, clipDuration: 12 },
|
||||
});
|
||||
|
||||
/** Prevent live iframe discovery from replacing an explicitly loaded dev fixture. */
|
||||
export function setTimelinePerformanceFixtureLease(active: boolean): void {
|
||||
fixtureLeaseActive = active;
|
||||
}
|
||||
|
||||
export function hasTimelinePerformanceFixtureLease(): boolean {
|
||||
return fixtureLeaseActive;
|
||||
}
|
||||
|
||||
function validateFixtureSpec(spec: TimelinePerformanceFixtureSpec) {
|
||||
if (spec.elementCount !== 1_000 && spec.elementCount !== 50_000) {
|
||||
throw new RangeError("Timeline performance fixture elementCount must be 1000 or 50000");
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<!doctype html>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Timeline virtualization QA fixture</title>
|
||||
<style>
|
||||
html,
|
||||
@@ -16,18 +16,7 @@
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div
|
||||
id="timeline-virtualization-anchor"
|
||||
class="clip"
|
||||
data-composition-id="timeline-virtualization"
|
||||
data-width="1920"
|
||||
data-height="1080"
|
||||
data-start="0"
|
||||
data-duration="60"
|
||||
data-fps="30"
|
||||
data-track-index="0"
|
||||
style="position: absolute; inset: 0"
|
||||
></div>
|
||||
<div data-hf-id="hf-biny" id="timeline-virtualization-anchor" class="clip" data-composition-id="timeline-virtualization" data-width="1920" data-height="1080" data-start="0" data-duration="60" data-fps="30" data-track-index="0" style="position: absolute; inset: 0"></div>
|
||||
<script>
|
||||
window.__timelines = window.__timelines || {};
|
||||
window.__timelines["timeline-virtualization"] = {
|
||||
|
||||
@@ -91,9 +91,7 @@ async function collectRun(page) {
|
||||
function findTimelineScroller() {
|
||||
const root = document.querySelector('[aria-label="Timeline"]');
|
||||
if (!(root instanceof HTMLElement)) throw new Error("Timeline root not mounted");
|
||||
const scroller = Array.from(root.querySelectorAll("div")).find(
|
||||
(node) => node.scrollWidth > node.clientWidth || node.scrollHeight > node.clientHeight,
|
||||
);
|
||||
const scroller = root.querySelector("[data-timeline-scroll-viewport]");
|
||||
if (!(scroller instanceof HTMLElement)) throw new Error("Timeline scroller not mounted");
|
||||
return scroller;
|
||||
}
|
||||
@@ -192,24 +190,18 @@ try {
|
||||
if (TIER === "low-resource") {
|
||||
await client.send("Emulation.setCPUThrottlingRate", { rate: 4 });
|
||||
}
|
||||
await page.goto(STUDIO_URL, { waitUntil: "domcontentloaded", timeout: 60_000 });
|
||||
await page.goto(STUDIO_URL, { waitUntil: "networkidle0", timeout: 60_000 });
|
||||
await page.waitForFunction(
|
||||
() => typeof window.__studioTest?.loadTimelinePerformanceFixture === "function",
|
||||
{ timeout: 30_000 },
|
||||
);
|
||||
await waitForStudioTestHookSettle(page);
|
||||
|
||||
await page.evaluate((profile) => {
|
||||
window.__studioTest.loadTimelinePerformanceFixture({ elementCount: 1_000, profile });
|
||||
}, PROFILE);
|
||||
await loadFixtureAndWait(page, 1_000, PROFILE);
|
||||
await client.send("HeapProfiler.collectGarbage");
|
||||
const baselineHeapBytes = await collectHeapBytes(client);
|
||||
|
||||
const summary = await page.evaluate(
|
||||
({ elementCount, profile }) =>
|
||||
window.__studioTest.loadTimelinePerformanceFixture({ elementCount, profile }),
|
||||
{ elementCount: ELEMENT_COUNT, profile: PROFILE },
|
||||
);
|
||||
await page.waitForFunction(() => document.querySelector('[aria-label="Timeline"]'));
|
||||
const summary = await loadFixtureAndWait(page, ELEMENT_COUNT, PROFILE);
|
||||
const budgets = await page.evaluate(() => window.__studioTest.timelineViewportBudgets);
|
||||
const measuredMaxReliableScrollWidth = await measureMaximumReliableScrollWidth(page);
|
||||
|
||||
@@ -232,9 +224,7 @@ try {
|
||||
run.diagnostics.mountedTimelineDescendants < budgets.maxMountedTimelineDescendants;
|
||||
}
|
||||
|
||||
await page.evaluate((profile) => {
|
||||
window.__studioTest.loadTimelinePerformanceFixture({ elementCount: 1_000, profile });
|
||||
}, PROFILE);
|
||||
await loadFixtureAndWait(page, 1_000, PROFILE);
|
||||
await client.send("HeapProfiler.collectGarbage");
|
||||
const returnedHeapBytes = await collectHeapBytes(client);
|
||||
const memoryReturned =
|
||||
@@ -296,3 +286,48 @@ try {
|
||||
await browser.close();
|
||||
}
|
||||
process.exit(exitCode);
|
||||
|
||||
async function waitForFixtureRender(page, elementCount) {
|
||||
const deadline = Date.now() + 60_000;
|
||||
let observed = null;
|
||||
while (Date.now() < deadline) {
|
||||
observed = await page.evaluate(() => ({
|
||||
modelCount: window.__playerStore?.getState().elements.length ?? null,
|
||||
renderedCount:
|
||||
document
|
||||
.querySelector('[aria-label="Timeline"]')
|
||||
?.getAttribute("data-timeline-element-count") ?? null,
|
||||
}));
|
||||
if (observed.renderedCount === String(elementCount)) {
|
||||
await page.evaluate(() => new Promise((resolve) => requestAnimationFrame(() => resolve())));
|
||||
return;
|
||||
}
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
}
|
||||
throw new Error(`Timeline fixture ${elementCount} did not render: ${JSON.stringify(observed)}`);
|
||||
}
|
||||
|
||||
async function loadFixtureAndWait(page, elementCount, profile) {
|
||||
const summary = await page.evaluate(
|
||||
({ count, fixtureProfile }) =>
|
||||
window.__studioTest.loadTimelinePerformanceFixture({
|
||||
elementCount: count,
|
||||
profile: fixtureProfile,
|
||||
}),
|
||||
{ count: elementCount, fixtureProfile: profile },
|
||||
);
|
||||
await waitForFixtureRender(page, elementCount);
|
||||
return summary;
|
||||
}
|
||||
|
||||
async function waitForStudioTestHookSettle(page) {
|
||||
await page.evaluate(async () => {
|
||||
const nextFrame = () => new Promise((resolve) => requestAnimationFrame(resolve));
|
||||
for (;;) {
|
||||
const candidate = window.__studioTest;
|
||||
await nextFrame();
|
||||
await nextFrame();
|
||||
if (candidate === window.__studioTest) return;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user