diff --git a/web/src/test-setup.ts b/web/src/test-setup.ts index 3dea53b41..240b00e34 100644 --- a/web/src/test-setup.ts +++ b/web/src/test-setup.ts @@ -17,11 +17,17 @@ along with this program. If not, see . For commercial licensing, please contact support@quantumnous.com */ 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, diff --git a/web/vitest.config.ts b/web/vitest.config.ts index 168d9c6b8..a1a063609 100644 --- a/web/vitest.config.ts +++ b/web/vitest.config.ts @@ -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}'],