From d956723a831ea883028d9af67ad6ffd2733a0afd Mon Sep 17 00:00:00 2001 From: hectorqin Date: Sun, 1 Nov 2026 00:23:58 +0000 Subject: [PATCH] test(web): list-return tests use MemoryRouter; data routers fail on Node 24 The real cause of the CI failure: createMemoryRouter builds a fetch Request for every navigation, and on Node 24 (CI) undici rejects jsdom's AbortSignal ("RequestInit: Expected signal to be an instance of AbortSignal"), so no click or Back ever navigated. Locally Node 22 accepts it. The test now mounts a plain MemoryRouter, like every other test, and reads location / navigation type / navigate through a probe component. Co-Authored-By: Claude Opus 5.5 --- web/test/media-list-return.test.tsx | 34 +++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/web/test/media-list-return.test.tsx b/web/test/media-list-return.test.tsx index dc6c194..a2a5c8d 100644 --- a/web/test/media-list-return.test.tsx +++ b/web/test/media-list-return.test.tsx @@ -1,7 +1,7 @@ // @vitest-environment jsdom import { act } from 'react'; import { afterEach, describe, expect, it, vi } from 'vitest'; -import { createMemoryRouter, RouterProvider } from 'react-router-dom'; +import { MemoryRouter, Route, Routes, useLocation, useNavigate, useNavigationType, type Location, type NavigateFunction, type NavigationType } from 'react-router-dom'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { render } from '../src/shared/ui/render-root.ts'; import { RuntimeContext } from '../src/app/providers/runtime-context.tsx'; @@ -38,19 +38,35 @@ function Detail() { return

详情内容

; } +/** + * A plain MemoryRouter, not createMemoryRouter: a data router builds a fetch Request + * per navigation, and on Node 24 undici rejects jsdom's AbortSignal there, so no + * navigation ever happens in CI. A probe hands the test the router's state instead. + */ +interface RouterHandle { state: { location: Location; historyAction: NavigationType }; navigate: NavigateFunction } +function Probe({ handle }: { handle: RouterHandle }) { + handle.state = { location: useLocation(), historyAction: useNavigationType() }; + handle.navigate = useNavigate(); + return null; +} + function mount(initial: string) { - const router = createMemoryRouter([ - { path: '/media/search', element: }, - { path: '/media/favorites', element: }, - { path: '/media/:channel/history', element: }, - { path: '/media/:channel/items/:id', element: }, - ], { initialEntries: [initial] }); + const router = {} as RouterHandle; const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } }); - act(() => render(, root)); + act(() => render( + + + + } /> + } /> + } /> + } /> + + + , root)); return router; } -/** Polls until `done` holds, for up to 4s: a slow CI runner's first render alone can take over half a second. */ async function settle(done: () => boolean) { const deadline = Date.now() + 4000; while (!done() && Date.now() < deadline) await act(async () => { await new Promise(resolve => setTimeout(resolve, 10)); });