import { renderToStaticMarkup } from 'react-dom/server'; import { afterEach, expect, test } from 'vite-plus/test'; import shapeScript from '../../generated/editor-skeleton-script.iife.js?raw'; import { encodeDocsPlaygroundHash } from '../../lib/docs-playground-hash.js'; import { toSkeletonLines } from '../../lib/playground-editor-shape.js'; import { EditorSkeleton } from './editor-skeleton'; let container: HTMLElement | undefined; afterEach(() => { container?.remove(); container = undefined; // The script writes `location.hash` directly; clear it so it doesn't leak // into other tests that read `location.hash`. history.replaceState(null, '', location.pathname + location.search); }); const MULTI_LINE_CODE = 'function greet(name) {\n\treturn `Hi, ${name}`;\n}\n'; // Deliberately a different shape (one row, non-empty) than `MULTI_LINE_CODE`, // mirroring the real page: the server only ever renders the skeleton for the // default code, never for the shared hash. If the script silently bailed and // left the server markup alone, asserting against `MULTI_LINE_CODE`'s shape // below would fail, proving the rewrite actually ran. const SERVER_SIDE_CODE = 'const placeholder = true;'; /** * Puts server-rendered skeleton markup (for `code`) in a detached container, * followed by the compiled pre-hydration script as a real `