mirror of
https://github.com/readest/readest.git
synced 2026-11-29 19:02:28 +00:00
The webdriver wait in test-tauri.sh started counting when tauri dev was spawned, but tauri dev compiles the Rust backend first, so a cold cache compile (4m54s on PR 5639) consumed the whole 300s budget and the wait reported a bogus timeout 6 seconds after the binary launched. The wait now has its own 900s budget; a crashed app still fails fast through the liveness check. Also skip every step of build_tauri_app, the slowest PR check, when neither the Rust backend, the vendored native packages, nor the tauri test harness changed, mirroring how rust_lint and the koplugin steps are gated. Frontend-only PRs are covered by the web build and test jobs, and the job still reports success so it stays green as a required check. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
80 lines
2.8 KiB
Bash
Executable file
80 lines
2.8 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
#
|
|
# Starts a Next.js dev server, launches the Tauri app with webdriver
|
|
# (no file watcher, no built-in dev server), waits for the WebDriver
|
|
# server on port 4445, runs tests, then tears down everything cleanly.
|
|
#
|
|
set -euo pipefail
|
|
|
|
DEV_PORT=3000
|
|
WEBDRIVER_PORT=4445
|
|
POLL_INTERVAL=3
|
|
TIMEOUT=300
|
|
# `tauri dev` compiles the Rust backend before it launches the binary, and a
|
|
# cold CI cache can spend 5+ minutes in that compile, so the WebDriver wait
|
|
# needs its own budget rather than sharing (and losing) the dev-server one.
|
|
# A crashed app still fails fast via the liveness check in the wait loop.
|
|
WEBDRIVER_TIMEOUT=900
|
|
|
|
cleanup() {
|
|
if [[ -n "${TAURI_PID:-}" ]]; then
|
|
pkill -P "$TAURI_PID" 2>/dev/null || true
|
|
kill "$TAURI_PID" 2>/dev/null || true
|
|
wait "$TAURI_PID" 2>/dev/null || true
|
|
fi
|
|
if [[ -n "${DEV_PID:-}" ]]; then
|
|
pkill -P "$DEV_PID" 2>/dev/null || true
|
|
kill "$DEV_PID" 2>/dev/null || true
|
|
wait "$DEV_PID" 2>/dev/null || true
|
|
fi
|
|
lsof -ti :"$WEBDRIVER_PORT" 2>/dev/null | xargs kill 2>/dev/null || true
|
|
lsof -ti :"$DEV_PORT" 2>/dev/null | xargs kill 2>/dev/null || true
|
|
}
|
|
|
|
trap cleanup EXIT INT TERM
|
|
|
|
echo "Starting Next.js dev server..."
|
|
dotenv -e .env.tauri -- next dev &
|
|
DEV_PID=$!
|
|
|
|
echo "Waiting for dev server on port $DEV_PORT..."
|
|
elapsed=0
|
|
while ! curl -sf "http://localhost:${DEV_PORT}" >/dev/null 2>&1; do
|
|
if ! kill -0 "$DEV_PID" 2>/dev/null; then
|
|
echo "ERROR: Dev server exited unexpectedly."
|
|
exit 1
|
|
fi
|
|
if (( elapsed >= TIMEOUT )); then
|
|
echo "ERROR: Timed out waiting for dev server on port $DEV_PORT."
|
|
exit 1
|
|
fi
|
|
sleep "$POLL_INTERVAL"
|
|
(( elapsed += POLL_INTERVAL ))
|
|
done
|
|
|
|
echo "Starting Tauri app with webdriver (no-watch, skip beforeDevCommand)..."
|
|
# webdriver-remote grants the app commands to the vitest tester page, which
|
|
# tauri treats as a remote origin (served from vitest's port, not the devUrl).
|
|
# It is excluded from app.security.capabilities in tauri.conf.json, so it only
|
|
# exists in this harness run.
|
|
dotenv -e .env.tauri -- tauri dev --features webdriver --no-watch \
|
|
--config '{"build":{"beforeDevCommand":""},"app":{"security":{"capabilities":["default","desktop-capability","webdriver-remote"]}}}' &
|
|
TAURI_PID=$!
|
|
|
|
echo "Waiting for WebDriver server on port $WEBDRIVER_PORT (timeout ${WEBDRIVER_TIMEOUT}s)..."
|
|
elapsed=0
|
|
while ! curl -sf "http://127.0.0.1:${WEBDRIVER_PORT}/status" >/dev/null 2>&1; do
|
|
if ! kill -0 "$TAURI_PID" 2>/dev/null; then
|
|
echo "ERROR: Tauri app exited before WebDriver became ready."
|
|
exit 1
|
|
fi
|
|
if (( elapsed >= WEBDRIVER_TIMEOUT )); then
|
|
echo "ERROR: Timed out waiting for WebDriver on port $WEBDRIVER_PORT."
|
|
exit 1
|
|
fi
|
|
sleep "$POLL_INTERVAL"
|
|
(( elapsed += POLL_INTERVAL ))
|
|
done
|
|
|
|
echo "WebDriver is ready. Running Tauri tests..."
|
|
pnpm vitest --config vitest.tauri.config.mts --watch=false
|