Add regression test for linear motion-value animation (#2826)#3727
Add regression test for linear motion-value animation (#2826)#3727mattgperry wants to merge 1 commit into
Conversation
Locks in linear progression for animate(motionValue, [0, 1], { ease:
"linear", type: "keyframes", times: [0, 1] }) bound to motion.div opacity
— the scenario from the bug report. The current pipeline produces linear
output (verified at 25%, 50% and 75% of duration); the regression test
prevents the original failure from coming back.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Greptile SummaryAdds a regression test for issue #2826 —
Confidence Score: 4/5Safe to merge — only adds test files with no changes to library source code. The Cypress spec relies entirely on wall-clock cy.wait() delays and a ±0.1 opacity tolerance. A mild non-linear easing regression could stay within those bounds undetected, and the suite could become flaky on slower CI runners. Neither concern blocks merging, but the spec would benefit from tighter assertions (via cy.clock()/cy.tick()) to serve as a stronger long-term regression guard. The Cypress spec (packages/framer-motion/cypress/integration/issue-2826-linear-motion-value.ts) is the only file worth a second look — the test page itself is straightforward. Important Files Changed
Sequence DiagramsequenceDiagram
participant Cypress
participant Browser
participant React
participant MotionValue
Cypress->>Browser: "cy.visit(?test=issue-2826-linear-motion-value)"
Browser->>React: mount App
React->>MotionValue: useMotionValue(0)
React->>MotionValue: "animate(opacity, [0,1], {duration:10, ease:linear})"
MotionValue->>Browser: "updates #box style.opacity on each RAF"
Cypress->>Cypress: wait(2500ms)
Cypress->>Browser: "get(#box).then() - getComputedStyle.opacity approx 0.25"
Cypress->>Cypress: wait(2500ms)
Cypress->>Browser: then() - getComputedStyle.opacity approx 0.50
Cypress->>Cypress: wait(2500ms)
Cypress->>Browser: then() - getComputedStyle.opacity approx 0.75
Reviews (1): Last reviewed commit: "Add regression test for linear motion-va..." | Re-trigger Greptile |
| .then(([$element]: any) => { | ||
| const opacity = parseFloat( | ||
| getComputedStyle($element).opacity | ||
| ) | ||
| // 50% through 10s should be ~0.5 | ||
| expect(opacity).to.be.greaterThan(0.5 - tolerance) | ||
| expect(opacity).to.be.lessThan(0.5 + tolerance) | ||
| }) |
There was a problem hiding this comment.
Stale subject reuse for 50 % and 75 % checks
After the first .then() returns undefined, Cypress keeps the original jQuery subject from .get("#box") and passes it through the subsequent .wait()/.then() calls. This works correctly because $element is a live DOM reference and getComputedStyle reads the current value at call time — but the pattern is subtle. If this chain is ever refactored (e.g. an early return is added, or a cy.wrap() is inserted), the 2nd and 3rd .then() blocks could silently receive the wrong subject. Consider re-querying with .get("#box") before each check for clarity and resilience.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| @@ -0,0 +1,35 @@ | |||
| describe("issue 2826: animate(motionValue) with ease: 'linear' renders linearly", () => { | |||
| it("opacity progresses linearly across the duration", () => { | |||
| const tolerance = 0.1 | |||
There was a problem hiding this comment.
Tolerance may be too wide to catch subtle regressions
A tolerance of 0.1 (±10 %) means the test passes as long as opacity is anywhere between 0.15–0.35, 0.40–0.60, and 0.65–0.85. A regression that replaced the linear ease with a mild ease-in or ease-out curve could produce values that fall inside those windows and go undetected. The wide band is understandable for wall-clock–based CI timing, but pairing it with cy.clock() / cy.tick() would allow a much tighter tolerance (e.g. 0.02) and make this a stronger regression guard without flakiness risk.
Summary
Adds a regression test mirroring the exact reproduction from issue #2826:
useMotionValue(0)+animate(value, [0, 1], { ease: "linear", type: "keyframes", times: [0, 1] })drivingmotion.divopacity. The test asserts the rendered opacity tracks linearly at the 25 %, 50 %, and 75 % marks of a 10 s animation.Investigation
The user's repro uses framer-motion 6.2.8 (Feb 2022). On the current
main, both the JS animation pipeline (JSAnimation+ thekeyframesgenerator) and the rendered DOM opacity progress linearly — I could not reproduce the reported flicker at 50 % in Jest (JSDOM) or in Cypress (Electron Chrome, React 18 and React 19). The likely culprit was fixed incidentally during the rewrite of the animation pipeline between v6 and v12.Rather than landing speculative code changes for a bug I cannot trigger, this PR locks in the desired behavior so a regression to the original buggy state would fail CI.
dev/react/src/tests/issue-2826-linear-motion-value.tsxpackages/framer-motion/cypress/integration/issue-2826-linear-motion-value.tsFixes #2826
Test plan
yarn buildsucceedsyarn test— 797 tests pass