Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

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

Copilote9f9041b2565
diff --git a/web/vitest.setup.ts b/web/vitest.setup.ts
index b945f675f71..6211fcd2f4f 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