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.
78 lines
1.7 KiB
Bash
Executable file
78 lines
1.7 KiB
Bash
Executable file
#!/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"
|