test: add end-to-end browser tests with Playwright
Set up tests/e2e/ with a login page test covering branding, accessibility, form structure, theme colors, and static asset serving. Includes run.sh that manages the app lifecycle (start, test, stop) automatically.
This commit is contained in:
parent
84e61464c7
commit
e8fd7eb01d
4 changed files with 236 additions and 0 deletions
78
tests/e2e/run.sh
Executable file
78
tests/e2e/run.sh
Executable file
|
|
@ -0,0 +1,78 @@
|
|||
#!/usr/bin/env bash
|
||||
# Run Porchlight end-to-end browser tests.
|
||||
#
|
||||
# Usage:
|
||||
# ./run.sh # run all test_*.js files
|
||||
# ./run.sh test_login.js # run a specific test
|
||||
#
|
||||
# Prerequisites:
|
||||
# npm install && npm run setup (once, to install playwright + chromium)
|
||||
#
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
||||
|
||||
PORT="${E2E_PORT:-8099}"
|
||||
export TARGET_URL="http://127.0.0.1:${PORT}"
|
||||
|
||||
# --- Start the app ---
|
||||
echo "Starting Porchlight on port ${PORT}..."
|
||||
OIDC_OP_ISSUER="${TARGET_URL}" \
|
||||
OIDC_OP_DEBUG=true \
|
||||
OIDC_OP_SQLITE_PATH=:memory: \
|
||||
uv run --directory "$PROJECT_ROOT" \
|
||||
uvicorn fastapi_oidc_op.app:create_app \
|
||||
--factory --host 127.0.0.1 --port "$PORT" \
|
||||
--log-level warning &
|
||||
SERVER_PID=$!
|
||||
|
||||
cleanup() {
|
||||
echo "Stopping server (pid ${SERVER_PID})..."
|
||||
kill "$SERVER_PID" 2>/dev/null || true
|
||||
wait "$SERVER_PID" 2>/dev/null || true
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
# --- Wait for healthy ---
|
||||
echo "Waiting for server..."
|
||||
for i in $(seq 1 30); do
|
||||
if curl -sf "${TARGET_URL}/health" >/dev/null 2>&1; then
|
||||
echo "Server ready."
|
||||
break
|
||||
fi
|
||||
if [ "$i" -eq 30 ]; then
|
||||
echo "Server failed to start within 30 seconds." >&2
|
||||
exit 1
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
|
||||
# --- Run tests ---
|
||||
FAILED=0
|
||||
|
||||
if [ $# -gt 0 ]; then
|
||||
TEST_FILES=("$@")
|
||||
else
|
||||
TEST_FILES=("$SCRIPT_DIR"/test_*.js)
|
||||
fi
|
||||
|
||||
for test_file in "${TEST_FILES[@]}"; do
|
||||
echo ""
|
||||
echo "=== Running $(basename "$test_file") ==="
|
||||
if node "$test_file"; then
|
||||
echo "=== $(basename "$test_file"): OK ==="
|
||||
else
|
||||
echo "=== $(basename "$test_file"): FAILED ==="
|
||||
FAILED=1
|
||||
fi
|
||||
done
|
||||
|
||||
echo ""
|
||||
if [ "$FAILED" -eq 0 ]; then
|
||||
echo "All e2e tests passed."
|
||||
else
|
||||
echo "Some e2e tests failed." >&2
|
||||
fi
|
||||
|
||||
exit "$FAILED"
|
||||
Loading…
Add table
Add a link
Reference in a new issue