// @vitest-environment node import { ChakraProvider } from '@chakra-ui/react'; import { createMemoryHistory, createRouter, HeadContent, RouterProvider, rootRouteId, } from '@tanstack/react-router'; import type { ReactNode } from 'react'; import { prerender } from 'react-dom/static'; import { describe, expect, it } from 'vitest'; import { routerOptions } from './router'; import sitePages from './sitePages'; import system from './theme'; // What the HTML of every page holds for visitors without JavaScript: all // content visible, and every empty deferred photo next to a twin that shows // it (BR-RVL-01, BR-IMG-01). Rendered like src/prerender.test.tsx does. const TestShell = ({ children }: { children: ReactNode }) => ( <> {children} ); async function prerenderPath(path: string) { const router = createRouter({ ...routerOptions(), history: createMemoryHistory({ initialEntries: [path] }), }); const rootOptions = router.routesById[rootRouteId].options as { shellComponent?: typeof TestShell; }; rootOptions.shellComponent = TestShell; await router.load(); const { prelude } = await prerender( , ); return new Response(prelude).text(); } const count = (html: string, pattern: RegExp) => html.match(pattern)?.length ?? 0; describe('prerendered display fallbacks', () => { it.each([...Object.keys(sitePages), '/onbekend'])( 'shows %s with one noscript twin per deferred photo and nothing hidden', async (path) => { const html = await prerenderPath(path); const deferred = count(html, /]*\bdata-deferred\b[^>]*>/g); const twins = count(html, /