|
1 | 1 | import gsap from "gsap"; |
2 | 2 | import { describe, expect, it } from "vitest"; |
3 | | -import { seekGsapTimeline } from "./gsap"; |
| 3 | +import { rerenderGsapTimelineAt, seekGsapTimeline } from "./gsap"; |
4 | 4 | import { producerStandIn } from "./gsapStandIn.test-helpers"; |
5 | 5 | import type { RuntimeTimelineLike } from "../types"; |
6 | 6 |
|
@@ -136,9 +136,45 @@ function panelAt(frames: number[], fps?: number, standIn = false): Map<number, n |
136 | 136 | return opacity; |
137 | 137 | } |
138 | 138 |
|
| 139 | +/** The panel at each frame through both steps of a real seek: the seek, then the runtime's re-render. */ |
| 140 | +function panelThroughRuntimeSeek(frames: number[], standIn = false): Map<number, number> { |
| 141 | + const { panel, timeline } = fadeInterruptedBySet(standIn); |
| 142 | + const opacity = new Map<number, number>(); |
| 143 | + for (const frame of frames) { |
| 144 | + const t = frame / SET_FPS; |
| 145 | + if (!seekGsapTimeline(timeline, t, false, undefined, SET_FPS)) { |
| 146 | + rerenderGsapTimelineAt( |
| 147 | + { |
| 148 | + totalTime: timeline.totalTime!.bind(timeline), |
| 149 | + totalDuration: timeline.totalDuration?.bind(timeline), |
| 150 | + getChildren: timeline.getChildren?.bind(timeline), |
| 151 | + }, |
| 152 | + t, |
| 153 | + ); |
| 154 | + } |
| 155 | + opacity.set(frame, panel.opacity); |
| 156 | + } |
| 157 | + return opacity; |
| 158 | +} |
| 159 | + |
139 | 160 | describe("a render where a set interrupts a running tween", () => { |
140 | 161 | const preview = panelAt(range(0, 90)); |
141 | 162 |
|
| 163 | + it("keeps the set's value through the runtime's re-render, however frames are shared out", () => { |
| 164 | + for (const standIn of [false, true]) { |
| 165 | + for (const workers of [1, 2, 3, 4, 6]) { |
| 166 | + for (let worker = 0; worker < workers; worker++) { |
| 167 | + for (const [frame, opacity] of panelThroughRuntimeSeek( |
| 168 | + range(worker, 90, workers), |
| 169 | + standIn, |
| 170 | + )) { |
| 171 | + if (frame >= SET_FPS) expect([workers, frame, opacity]).toEqual([workers, frame, 1]); |
| 172 | + } |
| 173 | + } |
| 174 | + } |
| 175 | + } |
| 176 | + }); |
| 177 | + |
142 | 178 | it("lands every frame where preview does when one worker renders in order", () => { |
143 | 179 | for (const [frame, opacity] of panelAt(range(0, 90), SET_FPS)) { |
144 | 180 | expect([frame, opacity]).toEqual([frame, preview.get(frame)]); |
|
0 commit comments