#!/usr/bin/env python3 """Isolated browser tests of DOM reconciliation, preview alignment and owner labels. Run from the repository root. Does not emulate the server or OT protocol. """ from __future__ import annotations import base64 from pathlib import Path from playwright.sync_api import sync_playwright ROOT = Path(__file__).resolve().parents[1] def module_url(content: str) -> str: return "data:text/javascript;base64," + base64.b64encode(content.encode()).decode() def main(): reconcile = (ROOT / "static/js/dom-reconcile.js").read_text() editor_source = (ROOT / "static/js/note-editor.js").read_text() presence_source = editor_source.split(" function updatePresence(users) {", 1)[1].split(" function updateLatency", 1)[0] presence_source = "function updatePresence(users) {" + presence_source badges_source = editor_source.split(" let renderedAuthorshipOwners = [];", 1)[1].split(" function syncOwnerLabels()", 1)[0] badges_source = "let renderedAuthorshipOwners = [];" + badges_source geometry_source = "let previewPositionCache = null;" + editor_source.split(" let previewPositionCache = null;", 1)[1].split(" function previewScrollAnchor()", 1)[0] markdown = (ROOT / "static/js/markdown.js").read_text() markdown = "const EMOJI_SHORTCODES = {}; const t = (key, v, fallback) => fallback; const parseImageAlias = () => null;\n" + "\n".join( line for line in markdown.splitlines() if not line.startswith("import ") ) + "\nexport { firstRenderedTextRect };\n" html = '''