Skip to content

Write HTML. Render video. Built for agents.

test: pin the guards that keep script-placed scenes and unparseable scripts out of the in-place move (#5079)

Miguel Ángel3c40f37938f8
diff --git a/packages/core/src/runtime/init.subCompositionPlacement.test.ts b/packages/core/src/runtime/init.subCompositionPlacement.test.ts
index aa5b569f1f..5907bdf89a 100644
--- a/packages/core/src/runtime/init.subCompositionPlacement.test.ts
+++ b/packages/core/src/runtime/init.subCompositionPlacement.test.ts
@@ -63,6 +63,41 @@ describe("runtime sub-composition placement", () => {
expect(scene.startTime()).toBe(2);
});
+ it("leaves a scene that a script moved into another timeline where that timeline put it", () => {
+ const { root, scene } = load(1);
+ const holder = gsap.timeline({ paused: true });
+ root.add(holder, 0);
+ holder.add(scene, 2);
+
+ document.getElementById("host")!.setAttribute("data-start", "4");
+ window.__hfForceTimelineRebind?.();
+
+ expect(scene.parent).toBe(holder);
+ expect(scene.startTime()).toBe(2);
+ });
+
+ it("still moves a runtime-placed scene when the root script placed another one itself", () => {
+ document.body.innerHTML =
+ `<div data-composition-id="main" data-root="true" data-duration="10">` +
+ // Listed first, so a throw on the script-placed intro would stop the loop before the scene.
+ `<div class="clip" data-composition-id="intro" data-start="2.5" data-duration="2"></div>` +
+ `<div id="host" class="clip" data-composition-id="scene" data-start="1" data-duration="3"></div></div>`;
+ const intro = gsap.timeline({ paused: true }).to({}, { duration: 2 }, 0);
+ const scene = gsap.timeline({ paused: true }).to({}, { duration: 3 }, 0);
+ const root = gsap.timeline({ paused: true }).to({}, { duration: 1 }, 0).add(intro, 2);
+ window.__timelines = { main: root, intro, scene } as unknown as Record<
+ string,
+ RuntimeTimelineLike
+ >;
+ initSandboxRuntimeModular();
+
+ document.getElementById("host")!.setAttribute("data-start", "4");
+ window.__hfForceTimelineRebind?.();
+
+ expect(scene.startTime()).toBe(4);
+ expect(intro.startTime()).toBe(2);
+ });
+
it("leaves an unmoved scene in place on a rebind, whatever its start rounds to", () => {
const { root, scene } = load("0.33333333");
const remove = vi.spyOn(root, "remove");
diff --git a/packages/parsers/src/scriptShape.test.ts b/packages/parsers/src/scriptShape.test.ts
index 1ffaab2186..d5b2c59bf9 100644
--- a/packages/parsers/src/scriptShape.test.ts
+++ b/packages/parsers/src/scriptShape.test.ts
@@ -43,6 +43,11 @@ const w = { x: window.innerWidth - 40 }
expect(same(`tl.to("#a", {}, 1)`, `tl.to("#a", {}, 2)`, true)).toBe(true);
});
+ it("compares big integers by value without throwing", () => {
+ expect(same("a = 1n", "a = 2n")).toBe(false);
+ expect(same("a = 1n", "a = 1n")).toBe(true);
+ });
+
it("is null for a script that does not parse", () => {
expect(scriptShape("tl.to(")).toBeNull();
});
diff --git a/packages/studio/src/utils/gsapLiveRetime.realGsap.test.ts b/packages/studio/src/utils/gsapLiveRetime.realGsap.test.ts
index bdd05c50a9..ec9bc86f5e 100644
--- a/packages/studio/src/utils/gsapLiveRetime.realGsap.test.ts
+++ b/packages/studio/src/utils/gsapLiveRetime.realGsap.test.ts
@@ -436,6 +436,12 @@ it("reloads the preview, and says so, when moving the live tweens throws", async
expect(error).toHaveBeenCalledTimes(1);
});
+it("re-runs a script that does not parse as a classic script, such as one with an import", () => {
+ const before = script('import "./setup.js";', 'tl.to("#a", { x: 1, duration: 1 }, 0);');
+ const after = script('import "./setup.js";', 'tl.to("#a", { x: 1, duration: 1 }, 1);');
+ expect(planLiveRetime(before, after).kind).toBe("rerun");
+});
+
it("re-runs the script when the edit also flips an operator in a tween's value", () => {
const before = script('tl.to("#a", { x: window.innerWidth - 40, duration: 1 }, 0);');
const after = script('tl.to("#a", { x: window.innerWidth + 40, duration: 1 }, 1);');