Roo-Code/webview-ui/vitest.setup.ts
Roo Code ebadc1c76c fix: add timeout configurations to prevent flaky tests in CI
- Add explicit test timeout (15s), hook timeout (10s), and teardown timeout (10s) to vitest config
- Configure retry logic for CI environments to handle occasional flaky tests
- Add asyncUtilTimeout configuration to testing library to fail faster
- Resolves issue where tests would hang indefinitely in CI showing dots continuously

Fixes the flaky test issue reported in GitHub Actions run 16625858640
2025-07-30 15:35:46 +00:00

76 lines
2.1 KiB
TypeScript

import "@testing-library/jest-dom"
import "@testing-library/jest-dom/vitest"
// Force React into development mode for tests
// This is needed to enable act(...) function in React Testing Library
globalThis.process = globalThis.process || {}
globalThis.process.env = globalThis.process.env || {}
globalThis.process.env.NODE_ENV = "development"
class MockResizeObserver {
observe() {}
unobserve() {}
disconnect() {}
}
global.ResizeObserver = MockResizeObserver
// Fix for Microsoft FAST Foundation compatibility with JSDOM
// FAST Foundation tries to set HTMLElement.focus property, but it's read-only in JSDOM
// The issue is that FAST Foundation's handleUnsupportedDelegatesFocus tries to set element.focus = originalFocus
// but JSDOM's HTMLElement.focus is a getter-only property
Object.defineProperty(HTMLElement.prototype, "focus", {
get: function () {
return (
this._focus ||
function () {
// Mock focus behavior for tests
}
)
},
set: function (value) {
this._focus = value
},
configurable: true,
})
Object.defineProperty(window, "matchMedia", {
writable: true,
value: vi.fn().mockImplementation((query) => ({
matches: false,
media: query,
onchange: null,
addListener: vi.fn(),
removeListener: vi.fn(),
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
})),
})
// Mock scrollIntoView which is not available in jsdom
Element.prototype.scrollIntoView = vi.fn()
// Suppress console.log during tests to reduce noise.
// Keep console.error for actual errors.
const originalConsoleLog = console.log
const originalConsoleWarn = console.warn
const originalConsoleInfo = console.info
console.log = () => {}
console.warn = () => {}
console.info = () => {}
afterAll(() => {
console.log = originalConsoleLog
console.warn = originalConsoleWarn
console.info = originalConsoleInfo
})
// Set default timeout for waitFor operations to prevent hanging
import { configure } from "@testing-library/react"
configure({
// Reduce default timeout for waitFor to fail faster in CI
asyncUtilTimeout: 5000, // 5 seconds instead of default 1000ms
})