Functional verify+fix across both products after the build-out/harvest marathon. All 7 subprojects WORK (production build + tests + boot smoke). - gitgram-backend: fix 2FA backup-code lifecycle + QR-secret privacy regression, messageController reaction-aggregation crash; +4 test-harness updates for new models. Build clean, 1356/1356 tests, /health 200 - gitgram-web: fix render-time location/router.replace crash in app/camera prerender; next/link test mock. Production build green (216 pages), 76/86 tests - gitgram-mobile: add expo-haptics jest mock. tsc clean, 8/8 tests - aitm-core: fix IPv4/IPv6 authz test + a2aVendored auth-allowlist classification. 541/541 tests - aitm-api: vitest timeout bump for cold-transform false timeouts. 728/728 tests, /health 200 - aitm-mcp: correct beads_mark_done test (PUT not PATCH). 176/176 tests, boots - aitm-website: build green (93 pages) Deploy note: backend needs a Prisma migration for MutedWord/Post.contentLanguage/ MessageReaction (schema validates; generate against a migration-capable Postgres). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
50 lines
1.7 KiB
TypeScript
50 lines
1.7 KiB
TypeScript
/// <reference types="vitest/globals" />
|
|
import '@testing-library/jest-dom/vitest'
|
|
import type { AnchorHTMLAttributes, ReactNode } from 'react'
|
|
|
|
// Mock next/link so it renders a plain anchor through the SAME React instance the
|
|
// test renderer uses. The real next/link is externalised and resolves this app's
|
|
// own React 18 copy, which differs from the React that the hoisted
|
|
// @testing-library/react pulls in this npm-workspace monorepo; mixing the two copies
|
|
// makes useContext read a null dispatcher and aborts rendering. The mock only needs
|
|
// to emit an <a href> — that is all the tests assert against.
|
|
interface LinkProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
|
|
href: string
|
|
children?: ReactNode
|
|
}
|
|
vi.mock('next/link', () => ({
|
|
default: ({ href, children, ...rest }: LinkProps) => (
|
|
<a href={href} {...rest}>
|
|
{children}
|
|
</a>
|
|
),
|
|
}))
|
|
|
|
// Mock Next.js router
|
|
vi.mock('next/navigation', () => ({
|
|
useRouter: () => ({
|
|
push: vi.fn(),
|
|
replace: vi.fn(),
|
|
back: vi.fn(),
|
|
prefetch: vi.fn(),
|
|
refresh: vi.fn(),
|
|
}),
|
|
usePathname: () => '/',
|
|
useSearchParams: () => new URLSearchParams(),
|
|
}))
|
|
|
|
// Mock localStorage
|
|
const localStorageMock = (() => {
|
|
let store: Record<string, string> = {}
|
|
return {
|
|
getItem: vi.fn((key: string) => store[key] ?? null),
|
|
setItem: vi.fn((key: string, value: string) => { store[key] = value }),
|
|
removeItem: vi.fn((key: string) => { delete store[key] }),
|
|
clear: vi.fn(() => { store = {} }),
|
|
get length() { return Object.keys(store).length },
|
|
key: vi.fn((index: number) => Object.keys(store)[index] ?? null),
|
|
}
|
|
})()
|
|
|
|
Object.defineProperty(window, 'localStorage', { value: localStorageMock })
|