|
1 | 1 | // fallow-ignore-file code-duplication |
2 | 2 | import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; |
3 | 3 | import { initSandboxRuntimeModular } from "./init"; |
| 4 | +import { TYPEGPU_PRESENT_HEARTBEAT_MS } from "./adapters/typegpu"; |
4 | 5 | import type { RuntimeTimelineLike } from "./types"; |
5 | 6 |
|
6 | 7 | function createMockTimeline(duration: number): RuntimeTimelineLike { |
@@ -122,6 +123,7 @@ describe("initSandboxRuntimeModular", () => { |
122 | 123 | delete (window as { __hfAutoNoopRegistered?: boolean }).__hfAutoNoopRegistered; |
123 | 124 | delete window.gsap; |
124 | 125 | vi.restoreAllMocks(); |
| 126 | + vi.useRealTimers(); |
125 | 127 | window.requestAnimationFrame = originalRequestAnimationFrame; |
126 | 128 | window.cancelAnimationFrame = originalCancelAnimationFrame; |
127 | 129 | }); |
@@ -370,6 +372,31 @@ describe("initSandboxRuntimeModular", () => { |
370 | 372 | expect(child.style.visibility).toBe("visible"); |
371 | 373 | }); |
372 | 374 |
|
| 375 | + it("keeps WebGPU presentation active after renderSeek pauses the frame", async () => { |
| 376 | + vi.useFakeTimers(); |
| 377 | + |
| 378 | + const root = document.createElement("div"); |
| 379 | + root.setAttribute("data-composition-id", "main"); |
| 380 | + root.setAttribute("data-root", "true"); |
| 381 | + root.setAttribute("data-requires-webgpu", ""); |
| 382 | + root.setAttribute("data-duration", "10"); |
| 383 | + document.body.appendChild(root); |
| 384 | + window.__timelines = { main: createMockTimeline(10) }; |
| 385 | + |
| 386 | + const times: number[] = []; |
| 387 | + const onSeek = (event: Event) => { |
| 388 | + times.push((event as CustomEvent<{ time: number }>).detail.time); |
| 389 | + }; |
| 390 | + window.addEventListener("hf-seek", onSeek); |
| 391 | + |
| 392 | + initSandboxRuntimeModular(); |
| 393 | + window.__player?.renderSeek(4); |
| 394 | + await vi.advanceTimersByTimeAsync(TYPEGPU_PRESENT_HEARTBEAT_MS); |
| 395 | + |
| 396 | + window.removeEventListener("hf-seek", onSeek); |
| 397 | + expect(times).toEqual([0, 4, 4]); |
| 398 | + }); |
| 399 | + |
373 | 400 | it("uses export render fps when quantizing renderSeek", () => { |
374 | 401 | const infoSpy = vi.spyOn(console, "info").mockImplementation(() => {}); |
375 | 402 | const root = document.createElement("div"); |
|
0 commit comments