From 2f5cba36ad6146ffa0bca5830ba3dae6964bc3ed Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Mon, 8 Jun 2026 22:09:13 -0500 Subject: test(theme-studio): add a one-command test runner and make target The browser hash gates were run by hand through headless Chrome, so a picker-JS regression only surfaced if someone remembered to run them. run-tests.sh now drives the whole pyramid in one command: regenerate the page, the Python templating tests, the Node unit tests plus inline-integrity, a syntax check of the spliced page script, and the six browser hash gates. It exits non-zero on any failure, and make theme-studio-test calls it. The browser gates need a Chromium-family browser. When none is found they report SKIPPED rather than passing, so a machine without Chrome can't turn the gates silently green. --- scripts/theme-studio/README.md | 18 ++++++++++ scripts/theme-studio/run-tests.sh | 73 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100755 scripts/theme-studio/run-tests.sh (limited to 'scripts/theme-studio') diff --git a/scripts/theme-studio/README.md b/scripts/theme-studio/README.md index 68d74815..044ccc2e 100644 --- a/scripts/theme-studio/README.md +++ b/scripts/theme-studio/README.md @@ -30,6 +30,24 @@ During color work, disable Hyprland inactive-window dimming so colors read true: hyprctl keyword decoration:dim_inactive false ``` +## Tests + +```bash +make theme-studio-test # from the repo root, runs the whole pyramid +scripts/theme-studio/run-tests.sh # or call the runner directly +``` + +The runner regenerates the page, runs the Python templating tests +(`test_generate.py`), the Node unit tests for `colormath.js` +(`test-colormath.mjs`, including the inline-integrity check), a syntax check of +the spliced page script, and the browser hash gates in headless Chrome +(`#selftest`, `#cursortest`, `#readouttest`, `#deltatest`, `#oklchtest`, +`#planetest`). It exits non-zero on any failure. The browser gates need a +Chromium-family browser; without one they report SKIPPED rather than passing +silently. The pure color math and the extracted picker logic (`planeCell`, +`paletteWarnings`) live in `colormath.js` so they are unit-tested directly in +Node; the DOM glue is covered by the browser hash gates. + ## Files - `generate.py` — emits the HTML+JS, and embeds the package data. Edit here to diff --git a/scripts/theme-studio/run-tests.sh b/scripts/theme-studio/run-tests.sh new file mode 100755 index 00000000..b1fe54fa --- /dev/null +++ b/scripts/theme-studio/run-tests.sh @@ -0,0 +1,73 @@ +#!/usr/bin/env bash +# Test runner for the theme-studio tool. Drives the whole pyramid in one command: +# - regenerate theme-studio.html from generate.py +# - Python templating tests (export-strip + placeholder substitution) +# - Node unit tests for colormath.js (+ inline-integrity) +# - syntax-check the spliced page ', h, re.S).group(1)) +PY + +# 5. Browser hash gates. +CHROME="" +for c in google-chrome-stable google-chrome chromium chromium-browser; do + if command -v "$c" >/dev/null 2>&1; then CHROME="$c"; break; fi +done +HASHES="selftest cursortest readouttest deltatest oklchtest planetest" +if [ -z "$CHROME" ]; then + for t in $HASHES; do skip_msg "#$t (no Chromium-family browser found)"; done +else + PROF="$(mktemp -d)" + trap 'rm -rf "$PROF"' EXIT + for t in $HASHES; do + upper="$(echo "$t" | tr '[:lower:]' '[:upper:]')" + res="$("$CHROME" --headless --no-sandbox --disable-gpu --user-data-dir="$PROF" \ + --virtual-time-budget=8000 --dump-dom "file://$HERE/theme-studio.html#$t" 2>/dev/null \ + | grep -o "${upper}[^<]*" | head -1)" + case "$res" in + *PASS*) pass_msg "#$t" ;; + *FAIL*) fail_msg "#$t -> $res" ;; + *) fail_msg "#$t -> no verdict (browser did not run the test)" ;; + esac + done +fi + +echo +if [ "$fail" -eq 0 ]; then echo "all stages green"; else echo "FAILURES above"; fi +exit "$fail" -- cgit v1.2.3