#!/usr/bin/env bash # Runs Playwright smoke tests inside the official Playwright container against # the running PedScribe app. Usage: npm run e2e (or ./scripts/e2e.sh) set -euo pipefail cd "$(dirname "$0")/.." IMAGE="mcr.microsoft.com/playwright:v1.50.0-noble" # --- PREFLIGHT: static reference linter --- # Catches the class of bug where a JS file reaches for an id that no # HTML element (or dynamic id assignment anywhere in the repo) ever # produces — the lightbox + adminMilestones dead-code bugs were both # this shape and both went undetected until someone tripped over them # in the real app. Fails the build before tests even start. echo "==> Static reference lint" docker run --rm -v "$PWD:/work" -w /work node:20-alpine \ node scripts/lint-references.js # --- SEED: the accounts the fixtures log in as --- # Idempotent, and the only place the admin account comes from. Run inside the # app container because that is where the database credentials are: the # entrypoint exports them from OpenBao into the Node process and nowhere else. # Non-fatal, so a run against a stack that is already seeded is not blocked by # a container that happens not to be up. E2E_CONTAINER="${E2E_CONTAINER:-pediatric-ai-scribe-e2e}" echo "==> Seeding e2e accounts" if docker exec "$E2E_CONTAINER" node e2e/seed.js; then : else echo " seed skipped ($E2E_CONTAINER not running or not seedable); tests will fail on login if the accounts are missing" >&2 fi # Host network and a loopback URL, because the browser only treats loopback as # a secure context over plain http, and the app cannot sign in without one. BASE_URL="${BASE_URL:-http://127.0.0.1:3553}" docker run --rm --ipc=host \ --network=host \ -v "$PWD/e2e":/work \ -w /work \ -e BASE_URL="$BASE_URL" \ -e CI=true \ "$IMAGE" \ sh -c "npm install --no-audit --no-fund --silent && npx playwright test"