chore: Add global fetch mock in vitest.setup.ts to suppress happy-dom ECONNREFUSED errors (#35131)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com>
This commit is contained in:
Copilot 2026-04-14 03:47:01 +00:00 committed by GitHub
parent 175290fa04
commit e9f9041b25
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -74,6 +74,18 @@ if (typeof globalThis.IntersectionObserver === 'undefined') {
}
}
// Mock global fetch to prevent happy-dom from making real network calls
// (which would cause ECONNREFUSED errors against localhost:5001).
// Individual tests can still override via vi.spyOn(globalThis, 'fetch') or reassignment.
globalThis.fetch = vi.fn(() =>
Promise.resolve(
new Response(JSON.stringify({}), {
status: 200,
headers: { 'Content-Type': 'application/json' },
}),
),
) as unknown as typeof fetch
afterEach(async () => {
// Wrap cleanup in act() to flush pending React scheduler work
// This prevents "window is not defined" errors from React 19's scheduler