From e9f9041b2565fa19c4e3d89c40f1594780fa6b1c Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Tue, 14 Apr 2026 03:47:01 +0000 Subject: [PATCH] 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> --- web/vitest.setup.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/web/vitest.setup.ts b/web/vitest.setup.ts index b945f675f7..6211fcd2f4 100644 --- a/web/vitest.setup.ts +++ b/web/vitest.setup.ts @@ -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