test(web): stabilize flaky frontend suite timeouts and motion visibility races (#7367)

* test(web): stabilize flaky vitest timeouts and motion visibility races

* test(web): exclude no-preference from reduced-motion media query mock
This commit is contained in:
RedwindA
2026-09-14 12:38:19 +08:00
committed by GitHub
parent 7fd0638197
commit 815217ba64
2 changed files with 22 additions and 2 deletions
+16 -2
View File
@@ -17,11 +17,17 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact [email protected]
*/
import '@testing-library/jest-dom/vitest'
import { cleanup } from '@testing-library/react'
import { cleanup, configure } from '@testing-library/react'
import i18next from 'i18next'
import { initReactI18next } from 'react-i18next'
import { afterEach, beforeAll } from 'vitest'
// The testing-library default of 1000ms for findBy*/waitFor is too tight for
// this suite on contended CI runners, where a first-in-file test also pays the
// full cold-render cost. Keep it below vitest's testTimeout so async lookup
// failures still report the missing element instead of a generic test timeout.
configure({ asyncUtilTimeout: 5000 })
beforeAll(async () => {
await i18next.use(initReactI18next).init({
lng: 'en',
@@ -38,10 +44,18 @@ afterEach(() => {
cleanup()
})
// Prefer reduced motion in tests: entrance animations write inline
// `opacity: 0` on their first frame, and jsdom advances frames through a
// setTimeout-based rAF shim, so jest-dom visibility assertions would race the
// animation. The reduced-motion code paths render the same DOM without
// transient hidden states. Both `(prefers-reduced-motion: reduce)` and the
// boolean `(prefers-reduced-motion)` form match; `no-preference` does not.
Object.defineProperty(window, 'matchMedia', {
configurable: true,
value: (query: string): MediaQueryList => ({
matches: false,
matches:
query.includes('prefers-reduced-motion') &&
!query.includes('no-preference'),
media: query,
onchange: null,
addListener: () => undefined,
+6
View File
@@ -35,6 +35,12 @@ export default defineConfig({
deps: { inline: [/@lobehub\//, /antd-style/] },
},
setupFiles: ['./src/test-setup.ts'],
// Several heavy jsdom suites (channel-configuration, visual-billing-editor)
// legitimately take >5s per test on contended CI runners; the vitest
// default of 5000ms fails whichever of them crosses the line first. The
// heaviest test measures ~3.2s uncontended, so 20s keeps headroom for the
// ~4x slowdown observed on shared runners.
testTimeout: 20000,
clearMocks: true,
restoreMocks: true,
include: ['src/**/*.{test,spec}.{ts,tsx}'],