Extract shared test runner (helpers.js), add file-based SQLite with setup_db.py for fixture seeding, and add tests for auth guard, credentials management, full registration flow, health endpoint, password auth, and magic link registration errors. 66 checks across 7 test files.
90 lines
2.1 KiB
Bash
Executable file
90 lines
2.1 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}"
|
|
|
|
# --- Temp directory for e2e state ---
|
|
E2E_TMPDIR="$(mktemp -d)"
|
|
export OIDC_OP_SQLITE_PATH="${E2E_TMPDIR}/e2e_test.db"
|
|
export OIDC_OP_SIGNING_KEY_PATH="${E2E_TMPDIR}/keys"
|
|
|
|
# --- Start the app ---
|
|
echo "Starting Porchlight on port ${PORT}..."
|
|
echo " DB: ${OIDC_OP_SQLITE_PATH}"
|
|
OIDC_OP_ISSUER="${TARGET_URL}" \
|
|
OIDC_OP_DEBUG=true \
|
|
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
|
|
rm -rf "$E2E_TMPDIR"
|
|
}
|
|
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
|
|
|
|
# --- Seed test data ---
|
|
echo "Seeding test data..."
|
|
E2E_FIXTURES=$(uv run --directory "$PROJECT_ROOT" python tests/e2e/setup_db.py)
|
|
export E2E_FIXTURES
|
|
echo "Test fixtures: ${E2E_FIXTURES}"
|
|
|
|
# --- 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"
|