e2e tests: framer-motion
animations are not disabled by plugin disabling CSS animations #43282
Description
What
The disable-animation
plugin runs during e2e tests in order to make them "more stable" (see original PR).
But this set of styles don't have an impact on animations happening via the framer-motion
library (as noted by @talldan in #43186 (review)) — this is because framer-motion
"manually" sets the animated values as inline styles for each frame (instead of relying on native CSS animations and transforms).
Proposed next steps
The best solution that comes to my mind is:
- add a script to the
disable-animation
plugin, setting a global variable that can be read in app code - add the
MotionConfig
component (see docs): when the global variable from the point before is defined, thereducedMotion
option can be set toalways
, while normally it would be set touser
It should be noted that this is only a suboptimal solution:
- From the docs: "When motion is reduced, transform and layout animations will be disabled. Other animations, like opacity and backgroundColor, will persist." — so this wouldn't fix entirely the issue (disabling all transitions/animations)
- this is not great, since our tests wouldn't be running the same code that our user see
An alternative approach could be to manually check for that global "e2e_disable_css_animations" variable in the React code, and conditionally render an alternative to framer-motion
components that doesn't animate (i.e. a normal div
instead of a motion.div
) — although this approach would also mean that our e2e tests would not actually test the same exact components that are rendered in our user's browsers
Activity