diff --git a/source/_base.css b/source/_base.css index ccbfd151c..dae75bb04 100644 --- a/source/_base.css +++ b/source/_base.css @@ -57,6 +57,7 @@ @media print, (prefers-reduced-motion: reduce) { .animated { + animation-delay: 0s !important; animation-duration: 1ms !important; transition-duration: 1ms !important; animation-iteration-count: 1 !important; diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 000000000..88116d303 --- /dev/null +++ b/tests/README.md @@ -0,0 +1,14 @@ +# Reduced-motion regression + +Build the CSS with `npm install` and `npm start`. Install the optional browser +runner with `npm install --no-save --package-lock=false @playwright/test`, then +run `npx playwright install chromium firefox webkit` and +`node tests/reduced-motion.js`. + +The check covers all three distribution builds, normal/reduced-motion/print +media, visible entrance content, and delivery of `animationend`. +An optional CSS filename can be passed to test a previous build. + +For a manual reproduction, open `tests/reduced-motion.html` after building and +toggle the operating system's reduced-motion preference (or emulate it in +browser developer tools), then reload. Check print preview as well. diff --git a/tests/reduced-motion.html b/tests/reduced-motion.html new file mode 100644 index 000000000..7c69f58b7 --- /dev/null +++ b/tests/reduced-motion.html @@ -0,0 +1,21 @@ + + + +
+ Build with npm start. With reduced motion enabled, the message below should appear immediately + and report animationend. With no preference, it should retain its five-second delay. Also check + print preview. +
+Waiting for animationend...
++ This content should not remain hidden for five seconds under reduced motion. +
+ + diff --git a/tests/reduced-motion.js b/tests/reduced-motion.js new file mode 100644 index 000000000..7652ba994 --- /dev/null +++ b/tests/reduced-motion.js @@ -0,0 +1,70 @@ +// Build with `npm start`, install @playwright/test locally, then run this file with Node. +// Optional argument: a built CSS file (defaults to all three distribution builds). +const assert = require('assert'); +const fs = require('fs'); +const path = require('path'); +const {chromium, firefox, webkit} = require('@playwright/test'); + +(async () => { + const files = process.argv.slice(2); + if (!files.length) files.push('animate.css', 'animate.min.css', 'animate.compat.css'); + for (const engine of [chromium, firefox, webkit]) { + const browser = await engine.launch(); + try { + for (const file of files) { + const css = fs.readFileSync(path.resolve(file), 'utf8'); + const prefix = file.includes('compat') ? '' : 'animate__'; + const page = await browser.newPage(); + try { + for (const mode of ['normal', 'reduce', 'print']) { + await page.emulateMedia({ + media: mode === 'print' ? 'print' : 'screen', + reducedMotion: mode === 'reduce' ? 'reduce' : 'no-preference', + }); + await page.setContent(``); + const result = await page.evaluate( + async ({prefix, mode}) => { + const el = document.createElement('div'); + el.textContent = 'Delayed content'; + el.className = `${prefix}animated ${prefix}fadeIn ${prefix}delay-5s`; + let ended = false; + el.addEventListener('animationend', () => { + ended = true; + }); + document.body.appendChild(el); + const delay = getComputedStyle(el).animationDelay; + if (mode !== 'normal') { + await Promise.race([ + new Promise((resolve) => + el.addEventListener('animationend', resolve, {once: true}), + ), + new Promise((resolve) => setTimeout(resolve, 1500)), + ]); + } + return {delay, ended, opacity: getComputedStyle(el).opacity}; + }, + {prefix, mode}, + ); + assert.strictEqual( + result.delay, + mode === 'normal' ? '5s' : '0s', + `${engine.name()} ${file} ${mode}`, + ); + if (mode !== 'normal') { + assert(result.ended, 'animationend should still fire promptly'); + assert.strictEqual(result.opacity, '1', 'Content should be visible'); + } + } + } finally { + await page.close(); + } + } + console.log(`PASS: ${engine.name()} normal/reduced/print delays and completion`); + } finally { + await browser.close(); + } + } +})().catch((error) => { + console.error(error); + process.exitCode = 1; +});