Browser smoke check clicks a link and a form button with nav.js live and fails on any page error
Browse files at this commitc2d290a8ddab9fce73d3d0a699a70d9c6a57eee6Parent: 28236ca- test
- browser smoke check clicks a link and a form button with nav.js live and fails on any page error
5 changed files +105 -0
- .gitignore +3 -0
- scripts/smoke/bun.lock +15 -0
- scripts/smoke/package.json +8 -0
- scripts/smoke/run.sh +45 -0
- scripts/smoke/smoke.mjs +34 -0
.gitignoremodified+3 -0
| @@ -11,3 +11,6 @@ ssh_host_ed25519_key | |||
| 11 | # local config; copy config/forge.example.toml | 11 | # local config; copy config/forge.example.toml |
| 12 | /config/forge.toml | 12 | /config/forge.toml |
| 13 | .~lock.*# | 13 | .~lock.*# |
| 14 | + | ||
| 15 | +# smoke check deps | ||
| 16 | +/scripts/smoke/node_modules | ||
scripts/smoke/bun.lockadded+15 -0
| @@ -0,0 +1,15 @@ | |||
| 1 | +{ | ||
| 2 | + "lockfileVersion": 2, | ||
| 3 | + "configVersion": 1, | ||
| 4 | + "workspaces": { | ||
| 5 | + "": { | ||
| 6 | + "name": "forge-smoke", | ||
| 7 | + "dependencies": { | ||
| 8 | + "playwright-core": "1.64.1", | ||
| 9 | + }, | ||
| 10 | + }, | ||
| 11 | + }, | ||
| 12 | + "packages": { | ||
| 13 | + "playwright-core": ["playwright-core@1.64.1", "", { "bin": { "playwright-core": "cli.js" } }, "sha512-BC4s8y6SEVA6Q1rSxZTto8hI1KUI3xXlHGZgvGqP4IqPdI/a6FX9H29IDNz7vKo9l21b6LfYosScPL6M3xxyDQ=="], | ||
| 14 | + } | ||
| 15 | +} | ||
scripts/smoke/package.jsonadded+8 -0
| @@ -0,0 +1,8 @@ | |||
| 1 | +{ | ||
| 2 | + "name": "forge-smoke", | ||
| 3 | + "private": true, | ||
| 4 | + "type": "module", | ||
| 5 | + "dependencies": { | ||
| 6 | + "playwright-core": "1.64.1" | ||
| 7 | + } | ||
| 8 | +} | ||
scripts/smoke/run.shadded+45 -0
| @@ -0,0 +1,45 @@ | |||
| 1 | +#!/usr/bin/env bash | ||
| 2 | +# Browser smoke check: starts forge on a throwaway data dir and clicks through it with nav.js live. | ||
| 3 | +# Usage: scripts/smoke/run.sh [--no-build] | ||
| 4 | +# Env: SMOKE_PORT=17670 forge port (user content +1, ssh +2) | ||
| 5 | +set -euo pipefail | ||
| 6 | + | ||
| 7 | +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" | ||
| 8 | +HERE="$ROOT/scripts/smoke" | ||
| 9 | +OUT="$ROOT/target/smoke" | ||
| 10 | +PORT="${SMOKE_PORT:-17670}" | ||
| 11 | +BIN="$ROOT/target/debug/forge" | ||
| 12 | + | ||
| 13 | +[[ "${1:-}" == --no-build ]] || (cd "$ROOT" && cargo build -q -p forge-web) | ||
| 14 | +[[ -x $BIN ]] || { echo "[smoke] missing $BIN" >&2; exit 1; } | ||
| 15 | +(cd "$HERE" && bun install --silent && bunx playwright-core install chromium-headless-shell >/dev/null) | ||
| 16 | + | ||
| 17 | +pkill -f -- "--config $OUT/forge.toml" 2>/dev/null || true | ||
| 18 | +rm -rf "$OUT" && mkdir -p "$OUT/data" | ||
| 19 | +cat > "$OUT/forge.toml" <<TOML | ||
| 20 | +database = "$OUT/data/forge.db" | ||
| 21 | +data_dir = "$OUT/data" | ||
| 22 | +listen = "127.0.0.1:$PORT" | ||
| 23 | +base_url = "http://127.0.0.1:$PORT" | ||
| 24 | +user_content_base_url = "http://127.0.0.1:$((PORT + 1))" | ||
| 25 | +user_content_listen = "127.0.0.1:$((PORT + 1))" | ||
| 26 | +ssh_listen = "127.0.0.1:$((PORT + 2))" | ||
| 27 | +ssh_public_host = "127.0.0.1" | ||
| 28 | +ssh_public_port = $((PORT + 2)) | ||
| 29 | +registration = "open" | ||
| 30 | +trusted_proxies = [] | ||
| 31 | + | ||
| 32 | +[mail] | ||
| 33 | +transport = "log" | ||
| 34 | +TOML | ||
| 35 | + | ||
| 36 | +"$BIN" --config "$OUT/forge.toml" > "$OUT/forge.log" 2>&1 & | ||
| 37 | +PID=$! | ||
| 38 | +trap 'kill $PID 2>/dev/null || true; wait $PID 2>/dev/null || true' EXIT INT TERM | ||
| 39 | +for _ in $(seq 60); do | ||
| 40 | + curl -fsS "http://127.0.0.1:$PORT/healthz" >/dev/null 2>&1 && break | ||
| 41 | + sleep 0.5 | ||
| 42 | +done | ||
| 43 | +curl -fsS "http://127.0.0.1:$PORT/healthz" >/dev/null || { echo "[smoke] forge did not start, see $OUT/forge.log" >&2; exit 1; } | ||
| 44 | + | ||
| 45 | +bun "$HERE/smoke.mjs" "http://127.0.0.1:$PORT" | ||
scripts/smoke/smoke.mjsadded+34 -0
| @@ -0,0 +1,34 @@ | |||
| 1 | +// Clicks through a running forge with nav.js live and fails on any page error, or when a link or a | ||
| 2 | +// form button does nothing. Catches what the HTTP-only e2e tests cannot: a broken nav.js. | ||
| 3 | +// Usage: bun smoke.mjs [base-url] (default http://127.0.0.1:17670) | ||
| 4 | +import { chromium } from 'playwright-core'; | ||
| 5 | + | ||
| 6 | +const base = process.argv[2] || 'http://127.0.0.1:17670'; | ||
| 7 | +const errors = []; | ||
| 8 | +const fail = (msg) => { console.error('[smoke] FAIL ' + msg); process.exitCode = 1; }; | ||
| 9 | + | ||
| 10 | +const browser = await chromium.launch({ headless: true }); | ||
| 11 | +try { | ||
| 12 | + const page = await browser.newPage(); | ||
| 13 | + page.on('pageerror', (e) => errors.push(e.message)); | ||
| 14 | + | ||
| 15 | + await page.goto(base + '/', { waitUntil: 'networkidle' }); | ||
| 16 | + if (!(await page.evaluate(() => document.documentElement.classList.contains('js')))) { | ||
| 17 | + fail('nav.js did not run (no html.js)'); | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + // A form button: the theme toggle posts and the page comes back in the other theme. | ||
| 21 | + const before = await page.evaluate(() => document.documentElement.dataset.theme); | ||
| 22 | + await page.click('.theme-form button'); | ||
| 23 | + await page.waitForFunction((t) => document.documentElement.dataset.theme !== t, before, { timeout: 5000 }) | ||
| 24 | + .catch(() => fail('theme button did nothing')); | ||
| 25 | + | ||
| 26 | + // A link: a soft navigation lands on the explore page. | ||
| 27 | + await page.click('a.topbar-link[href="/explore"]'); | ||
| 28 | + await page.waitForURL(base + '/explore', { timeout: 5000 }).catch(() => fail('explore link did nothing')); | ||
| 29 | +} finally { | ||
| 30 | + await browser.close(); | ||
| 31 | +} | ||
| 32 | + | ||
| 33 | +for (const e of errors) { fail('page error: ' + e); } | ||
| 34 | +if (!process.exitCode) { console.log('[smoke] ok'); } | ||