mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-29 10:10:30 +08:00
Run e2e tests in a Docker container
This commit is contained in:
Executable
+51
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env bash
|
||||
# Entrypoint for the e2e Docker container. Installs npm deps into the
|
||||
# container-private node_modules volume (only when package-lock.json changes),
|
||||
# ensures the Radicle test binaries are present, then runs Playwright. Any
|
||||
# arguments are forwarded to the test command.
|
||||
#
|
||||
# When USE_LOCAL_HTTPD=true, runs test:e2e:local (compiles radicle-httpd from
|
||||
# source and tests the frontend against it) instead of test:e2e.
|
||||
set -euo pipefail
|
||||
|
||||
cd /work
|
||||
|
||||
# The container runs as root, so anything it writes into the bind-mounted repo
|
||||
# would otherwise be root-owned on the host. Hand those paths back to the
|
||||
# invoking user (HOST_UID/HOST_GID set by scripts/test-e2e-docker) on exit.
|
||||
# radicle-httpd/target lives in a named volume, so it's not host-visible.
|
||||
cleanup() {
|
||||
if [ -n "${HOST_UID:-}" ]; then
|
||||
chown -R "$HOST_UID:${HOST_GID:-$HOST_UID}" \
|
||||
tests/tmp tests/artifacts tests/visual/snapshots build .svelte-kit \
|
||||
2>/dev/null || true
|
||||
fi
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
LOCK_HASH=$(md5sum package-lock.json | cut -d' ' -f1)
|
||||
STAMP=node_modules/.lockhash
|
||||
if [ ! -f "$STAMP" ] || [ "$(cat "$STAMP")" != "$LOCK_HASH" ]; then
|
||||
echo "📦 Installing npm dependencies..."
|
||||
npm ci
|
||||
echo "$LOCK_HASH" >"$STAMP"
|
||||
else
|
||||
echo "📦 npm dependencies up to date."
|
||||
fi
|
||||
|
||||
echo "⬇️ Ensuring Radicle test binaries..."
|
||||
mkdir -p tests/artifacts
|
||||
./scripts/install-binaries
|
||||
|
||||
NPM_SCRIPT="test:e2e"
|
||||
if [ "${USE_LOCAL_HTTPD:-}" = "true" ]; then
|
||||
NPM_SCRIPT="test:e2e:local"
|
||||
echo "🦀 Local httpd mode: radicle-httpd will be compiled from source."
|
||||
fi
|
||||
|
||||
echo "🧪 Running e2e tests ($NPM_SCRIPT)..."
|
||||
set +e
|
||||
npm run "$NPM_SCRIPT" -- "$@"
|
||||
status=$?
|
||||
set -e
|
||||
exit "$status"
|
||||
Executable
+51
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env bash
|
||||
# Build and run the Playwright e2e suite inside a Docker container. Use this
|
||||
# when the host OS is not supported by Playwright's browser builds.
|
||||
#
|
||||
# Usage:
|
||||
# scripts/test-e2e-docker # all chromium e2e tests
|
||||
# scripts/test-e2e-docker tests/e2e/foo.spec.ts # a single spec
|
||||
# scripts/test-e2e-docker --project chromium -g "some test"
|
||||
# scripts/test-e2e-docker --local # build radicle-httpd from
|
||||
# # source and test against it
|
||||
#
|
||||
# Any non-flag arguments are forwarded to the test command. When none are
|
||||
# given, defaults to `--project chromium`.
|
||||
set -euo pipefail
|
||||
|
||||
REPO_ROOT=$(cd "$(dirname "$0")/.." && pwd)
|
||||
cd "$REPO_ROOT"
|
||||
|
||||
COMPOSE="docker compose -f docker-compose.e2e.yml"
|
||||
|
||||
# Strip our own --local flag; forward everything else to Playwright.
|
||||
LOCAL=false
|
||||
ARGS=()
|
||||
for arg in "$@"; do
|
||||
if [ "$arg" = "--local" ]; then
|
||||
LOCAL=true
|
||||
else
|
||||
ARGS+=("$arg")
|
||||
fi
|
||||
done
|
||||
|
||||
SERVICE=e2e
|
||||
EXTRA_ENV=()
|
||||
if $LOCAL; then
|
||||
SERVICE=e2e-local
|
||||
EXTRA_ENV=(-e USE_LOCAL_HTTPD=true)
|
||||
fi
|
||||
|
||||
$COMPOSE build "$SERVICE"
|
||||
|
||||
if [ "${#ARGS[@]}" -eq 0 ]; then
|
||||
ARGS=(--project chromium)
|
||||
fi
|
||||
|
||||
# SKIP_SETUP (no value) forwards the host's value through, mirroring the
|
||||
# native runner's fast-iteration flag.
|
||||
exec $COMPOSE run --rm \
|
||||
-e HOST_UID="$(id -u)" -e HOST_GID="$(id -g)" \
|
||||
-e SKIP_SETUP \
|
||||
"${EXTRA_ENV[@]}" \
|
||||
"$SERVICE" "${ARGS[@]}"
|
||||
Reference in New Issue
Block a user