From 914bcfdafdb14cbe22e50e74bc6e5b6a7a3ecb06 Mon Sep 17 00:00:00 2001 From: Test Date: Wed, 4 Mar 2026 23:30:52 +0100 Subject: [PATCH] fix: stub fetch in test setup to prevent jsdom@28 + Node 22 undici crash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit jsdom@28's JSDOMDispatcher passes an onError handler incompatible with Node 22's bundled undici, causing InvalidArgumentError (UND_ERR_INVALID_ARG) on CI. Stubbing globalThis.fetch prevents the dispatcher from being invoked. The previous uncaughtException handler was insufficient — it caught the wrong error code and didn't handle unhandled rejections. Co-Authored-By: Claude Opus 4.6 --- src/test/setup.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/test/setup.ts b/src/test/setup.ts index e92850fd..5f19a704 100644 --- a/src/test/setup.ts +++ b/src/test/setup.ts @@ -2,12 +2,14 @@ import '@testing-library/jest-dom/vitest' import { vi } from 'vitest' import { createElement, type ReactNode, type ComponentType } from 'react' -// Suppress undici WebSocket ERR_INVALID_ARG_TYPE in jsdom (jsdom Event ≠ Node Event) -// eslint-disable-next-line @typescript-eslint/no-explicit-any -;(globalThis as any).process?.on?.('uncaughtException', (err: Error & { code?: string }) => { - if (err.code === 'ERR_INVALID_ARG_TYPE' && err.message?.includes('Event')) return - throw err -}) +// Stub fetch to prevent jsdom@28 + Node 22 undici incompatibility. +// jsdom's JSDOMDispatcher passes an onError handler that Node 22's bundled +// undici rejects with InvalidArgumentError (UND_ERR_INVALID_ARG). +// Tests should never make real network requests — individual tests can +// override this stub via vi.mocked(fetch).mockImplementation(...). +globalThis.fetch = vi.fn(() => + Promise.resolve(new Response(null, { status: 418 })), +) as typeof globalThis.fetch // Mock scrollIntoView for jsdom (not implemented) Element.prototype.scrollIntoView = vi.fn()