mirror of
https://gh-proxy.org/https://github.com/klinsmaya/new-api.git
synced 2026-11-10 18:36:57 +08:00
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:
+16
-2
@@ -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,
|
||||
|
||||
@@ -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}'],
|
||||
|
||||
Reference in New Issue
Block a user