#!/usr/bin/env python3 """Runs the window's page tests (tests/ui/*.js) in headless Chrome. Each test file runs in the real page (crates/kiri/src/ui/index.html, with its icons) after tests/ui/fixture.js, and calls report() with lines that start with PASS or FAIL. Exits non-zero if any test fails or a page errors. python3 scripts/ui-test.py [tests/ui/switch.js ...] """ import html, os, re, subprocess, sys, tempfile ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) CHROME = os.environ.get("CHROME", "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome") UI = os.path.join(ROOT, "crates/kiri/src/ui") def page(test, os_name=None): index = open(os.path.join(UI, "index.html")).read().replace("/*ICONS*/", open(os.path.join(UI, "icons.js")).read()) if os_name and os_name != "macos": index = index.replace("
", f'', 1) fixture = open(os.path.join(ROOT, "tests/ui/fixture.js")).read() report = 'const report = (lines) => document.body.insertAdjacentHTML("beforeend", `${lines.join("\\n")}`);'
catch = ''
return index[: index.rindex("")] + catch + f"