NHSDigital / ndr_dev_support

Development tools and security support for developers
MIT License
3 stars 4 forks source link

Capybara: use animation-disabling middleware #87

Closed joshpencheon closed 3 years ago

joshpencheon commented 3 years ago

Summary

Recent versions of Capybara can automatically inject an additional middleware in the test environment, that appends animation-disabling statements to the end of the <head>. This will neuter all jQuery animations, and CSS animations/transitions.

This PR enables this middleware by default, and bumps the capybara requirement to the latest release, to get the most animation-disabling potential.

joshpencheon commented 3 years ago

Testing this with a host project, in an integration test we see:

CSS rules being injected:

/* puts Nokogiri::HTML(page.body).xpath('//head/style').text */

*, *::before, *::after {
   transition: none !important;
   animation-duration: 0s !important;
   animation-delay: 0s !important;
   scroll-behavior: auto !important;
}

And JS:

/* puts Nokogiri::HTML(page.body).xpath('//head/script').text */

(typeof jQuery !== 'undefined') && (jQuery.fx.off = true);