From c934ede5dfebe033b358d1197d449d79110a1730 Mon Sep 17 00:00:00 2001 From: Niclas Overby Date: Sun, 12 Jul 2026 23:10:47 +0200 Subject: [PATCH] chore(web/wiki-dioxus): Add nushell dev-server reuse scripts (serve-up, test-reuse) Signed-off-by: Niclas Overby --- scripts/serve-up.nu | 36 ++++++++++++++++++++++++++++++++++++ scripts/test-reuse.nu | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 scripts/serve-up.nu create mode 100644 scripts/test-reuse.nu diff --git a/scripts/serve-up.nu b/scripts/serve-up.nu new file mode 100644 index 00000000..14a5f058 --- /dev/null +++ b/scripts/serve-up.nu @@ -0,0 +1,36 @@ +#!/usr/bin/env nu +# Start a persistent `dx serve` (once) so test runs can `--reuse` it and skip the +# ~minute rebuild. `dx serve` hot-reloads on edits; scripts/test-reuse.nu waits +# for that before running. Idempotent — does nothing if the server is already up. +# +# nu scripts/serve-up.nu # start (or confirm) the dev server on :8134 + +const PORT = 8134 +const LOG = "/tmp/wiki-dxserve.log" + +def serving [] { (do -i { ^curl -sf -o /dev/null $"http://127.0.0.1:($PORT)/" } | complete).exit_code == 0 } + +def main [] { + # Run from the project root (this script lives in ./scripts). + cd ($env.FILE_PWD | path dirname) + if (serving) { + print $"dx serve already up on :($PORT)" + return + } + # Detach so it outlives this script (nushell backgrounds through bash nohup). + let pid = (^bash -c $'nohup dx serve --port ($PORT) > "($LOG)" 2>&1 & echo $!' | str trim) + print $"started dx serve pid ($pid); waiting for the first build..." + mut ready = false + for _ in 1..240 { + let built = (try { (open --raw $LOG) | str contains "Build completed" } catch { false }) + if $built and (serving) { $ready = true; break } + sleep 1sec + } + if $ready { + print $"dx serve ready on :($PORT)" + } else { + print "dx serve did not finish its first build:" + if ($LOG | path exists) { print (open --raw $LOG | lines | last 15 | str join "\n") } + exit 2 + } +} diff --git a/scripts/test-reuse.nu b/scripts/test-reuse.nu new file mode 100644 index 00000000..0e172dfd --- /dev/null +++ b/scripts/test-reuse.nu @@ -0,0 +1,34 @@ +#!/usr/bin/env nu +# Run the browser harness against an already-running `dx serve` (skips the build). +# Waits for any in-progress hot-reload rebuild (after a Rust edit) to settle first, +# then runs `test-browser.nu --firefox --reuse`. Extra flags are forwarded, so: +# +# nu scripts/test-reuse.nu # fast reuse run +# nu scripts/test-reuse.nu --shots # + capture screenshots +# +# Reads WIKI_EMAIL / WIKI_PASSWORD from the environment (never committed) to enable +# the authenticated tests. Start the server once with scripts/serve-up.nu. + +const PORT = 8134 +const LOG = "/tmp/wiki-dxserve.log" + +def serving [] { (do -i { ^curl -sf -o /dev/null $"http://127.0.0.1:($PORT)/" } | complete).exit_code == 0 } + +def main [...args: string] { + cd ($env.FILE_PWD | path dirname) + if not (serving) { + print $"no dx serve on :($PORT) — run `nu scripts/serve-up.nu` first" + exit 3 + } + # Wait for any rebuild triggered by a recent edit to finish: the serve log's + # modified time stops advancing for 2s (dx serve is idle). + if ($LOG | path exists) { + for _ in 1..120 { + let a = (ls $LOG | get 0.modified) + sleep 2sec + let b = (ls $LOG | get 0.modified) + if $a == $b { break } + } + } + ^nu test-browser.nu --firefox --reuse ...$args +} -- 2.51.2