mirror of
https://github.com/bitbaum/orangecat.git
synced 2026-12-04 05:17:20 +01:00
Full parity: 282 test files / 2645 tests green before and after.
- vitest.config.ts mirrors the old moduleNameMapper as ordered resolve.alias
entries; jsdom env, globals, 30s timeout, v8 coverage with the same ratchet.
- vitest.setup.ts ports jest.setup.ts; lucide-react is now a vi.mock Proxy
(any icon resolves — the old CJS-alias Proxy surfaced no named exports and
every unlisted icon crashed renders as "Element type is invalid").
- Codemod jest.* -> vi.* across tests; @jest-environment -> @vitest-environment.
- Constructor mocks use function expressions (vitest news the implementation;
arrows are not constructable).
- Factories returning a bare component now return { default: ... };
one TDZ factory moved under vi.hoisted; one require() -> await import().
- jest.isolateModulesAsync dropped in the auth smoke test (resetModules +
doMock per test covers it).
- Scripts ported (positional path filters replace --testPathPatterns);
verify's --watchAll flag removed; ci.yml comment updated.
- Deleted jest.config.js, jest.setup.ts, __mocks__/vitest.js,
tsconfig.test.json, tests/jest-dom.d.ts, and the unimported jest-era
tests/utils.ts; uninstalled jest, ts-jest, jest-environment-jsdom,
@types/jest; dropped the dead mcp:jest script.
- Snapshot file rewritten in Vitest format (content byte-identical).
Claude-Session: https://claude.ai/code/session_01WqKqMnHQHSmkGFfc5t7Rxn
Co-authored-by: Georgy Butaev <41178744+g-but@users.noreply.github.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
45 lines
1.0 KiB
TypeScript
45 lines
1.0 KiB
TypeScript
import { RouterContext } from 'next/dist/shared/lib/router-context.shared-runtime';
|
|
import { NextRouter } from 'next/router';
|
|
import { ReactNode } from 'react';
|
|
|
|
interface TestWrapperProps {
|
|
children: ReactNode;
|
|
router?: Partial<NextRouter>;
|
|
}
|
|
|
|
const createRouter = (router?: Partial<NextRouter>): NextRouter => ({
|
|
push: vi.fn(),
|
|
replace: vi.fn(),
|
|
prefetch: vi.fn(),
|
|
back: vi.fn(),
|
|
reload: vi.fn(),
|
|
forward: vi.fn(),
|
|
pathname: '/',
|
|
route: '/',
|
|
query: {},
|
|
asPath: '/',
|
|
basePath: '',
|
|
isLocaleDomain: false,
|
|
isReady: true,
|
|
isPreview: false,
|
|
events: {
|
|
on: vi.fn(),
|
|
off: vi.fn(),
|
|
emit: vi.fn(),
|
|
},
|
|
isFallback: false,
|
|
beforePopState: vi.fn(),
|
|
...router,
|
|
});
|
|
|
|
export function TestWrapper({ children, router }: TestWrapperProps) {
|
|
const mockRouter = createRouter(router);
|
|
|
|
if (typeof window !== 'undefined') {
|
|
// @ts-ignore - Set global mockRouter for tests
|
|
window.mockRouter = mockRouter;
|
|
}
|
|
|
|
return <RouterContext.Provider value={mockRouter}>{children}</RouterContext.Provider>;
|
|
}
|