mirror of
https://github.com/langgenius/dify.git
synced 2026-04-15 09:57:03 +08:00
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:
parent
175290fa04
commit
e9f9041b25
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user