diff --git a/.gitignore b/.gitignore index 4da2d797ebb..d88c2597cef 100644 --- a/.gitignore +++ b/.gitignore @@ -67,6 +67,7 @@ cpu.out /indexers /log /public/assets/img/avatar +/tests/e2e-output /tests/integration/gitea-integration-* /tests/integration/indexers-* /tests/*.ini diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1df5b36cce8..baa288061fa 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -178,7 +178,15 @@ Here's how to run the test suite: | :------------------------------------------ | :------------------------------------------------------- | ------------------------------------------- | |``make test[\#SpecificTestName]`` | run unit test(s) | | |``make test-sqlite[\#SpecificTestName]`` | run [integration](tests/integration) test(s) for SQLite | [More details](tests/integration/README.md) | -|``make test-e2e`` | run [end-to-end](tests/e2e) test(s) using Playwright | Requires a running Gitea server | +|``make test-e2e`` | run [end-to-end](tests/e2e) test(s) using Playwright | | + +- e2e test environment variables + +| Variable | Description | +| :-------------- | :-------------------------------------------------------------------------- | +|``E2E_URL`` | URL of the Gitea server to test against (default: read from ``app.ini``) | +|``E2E_DEBUG`` | When set, show Gitea server output (only for auto-started server) | +|``E2E_FLAGS`` | Additional flags passed to Playwright (e.g. ``--headed --debug``) | ## Translation diff --git a/Makefile b/Makefile index cf61bc89a27..e619e06096e 100644 --- a/Makefile +++ b/Makefile @@ -559,7 +559,7 @@ playwright: deps-frontend .PHONY: test-e2e test-e2e: playwright - EXECUTABLE=$(EXECUTABLE) ./tools/test-e2e.sh $(E2E_FLAGS) + @EXECUTABLE=$(EXECUTABLE) ./tools/test-e2e.sh $(E2E_FLAGS) .PHONY: bench-sqlite bench-sqlite: integrations.sqlite.test generate-ini-sqlite diff --git a/playwright.config.ts b/playwright.config.ts index a194960a502..0bc844f6626 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -3,6 +3,7 @@ import {defineConfig, devices} from '@playwright/test'; export default defineConfig({ testDir: './tests/e2e/', + outputDir: './tests/e2e-output/', testMatch: /.*\.test\.ts/, forbidOnly: Boolean(env.CI), reporter: 'list', diff --git a/tools/test-e2e.sh b/tools/test-e2e.sh index 67b46698d95..ac43bb82e47 100755 --- a/tools/test-e2e.sh +++ b/tools/test-e2e.sh @@ -23,13 +23,41 @@ E2E_URL="${E2E_URL%/}" echo "Using Gitea server: $E2E_URL" +SERVER_PID="" +cleanup() { + if [ -n "$SERVER_PID" ]; then + echo "Stopping temporary Gitea server (PID $SERVER_PID)..." + kill "$SERVER_PID" 2>/dev/null || true + wait "$SERVER_PID" 2>/dev/null || true + fi +} +trap cleanup EXIT + +# For local development, if no gitea server is running, start a temporary one. +if [ -z "${CI:-}" ] && ! curl -sf --max-time 5 "$E2E_URL" > /dev/null 2>&1; then + if [ ! -x "./$EXECUTABLE" ]; then + echo "error: ./$EXECUTABLE not found or not executable, run 'make backend' first" >&2 + exit 1 + fi + echo "Starting temporary Gitea server..." + if [ -n "${E2E_DEBUG:-}" ]; then + "./$EXECUTABLE" web & + else + "./$EXECUTABLE" web > /dev/null 2>&1 & + fi + SERVER_PID=$! +fi + # Verify server is reachable, retry for up to 2 minutes for slow startup MAX_WAIT=120 ELAPSED=0 while ! curl -sf --max-time 5 "$E2E_URL" > /dev/null 2>&1; do + if [ -n "$SERVER_PID" ] && ! kill -0 "$SERVER_PID" 2>/dev/null; then + echo "error: Gitea server process exited unexpectedly" >&2 + exit 1 + fi if [ "$ELAPSED" -ge "$MAX_WAIT" ]; then echo "error: Gitea server at $E2E_URL is not reachable after ${MAX_WAIT}s" >&2 - echo "Start Gitea first: ./${EXECUTABLE}" >&2 exit 1 fi sleep 2 @@ -54,4 +82,4 @@ export E2E_URL export E2E_USER export E2E_PASSWORD -exec pnpm exec playwright test "$@" +pnpm exec playwright test "$@"