|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +# Detect app path: use first argument, or APP_PATH env, or try to detect from current directory |
| 5 | +if [ -n "$1" ] && [ -d "$1" ]; then |
| 6 | + APP_PATH="$1" |
| 7 | + shift |
| 8 | +elif [ -n "$1" ] && [ -d "volumes/nextcloud/$1" ]; then |
| 9 | + # Try with volumes/nextcloud prefix |
| 10 | + APP_PATH="volumes/nextcloud/$1" |
| 11 | + shift |
| 12 | +elif [ -n "$APP_PATH" ]; then |
| 13 | + APP_PATH="$APP_PATH" |
| 14 | +elif [ -f "package.json" ] && [ -f "appinfo/info.xml" ]; then |
| 15 | + # We're inside an app directory |
| 16 | + APP_PATH="." |
| 17 | +else |
| 18 | + echo "Usage: test-e2e <app-path> [playwright-options]" |
| 19 | + echo "Or set APP_PATH environment variable" |
| 20 | + echo "Or run from within an app directory" |
| 21 | + echo "" |
| 22 | + echo "Examples:" |
| 23 | + echo " test-e2e apps-extra/libresign" |
| 24 | + echo " test-e2e volumes/nextcloud/apps-extra/libresign" |
| 25 | + exit 1 |
| 26 | +fi |
| 27 | + |
| 28 | +# Resolve the absolute path |
| 29 | +if [[ "$APP_PATH" == "." ]]; then |
| 30 | + CONTAINER_PATH=$(pwd) |
| 31 | +else |
| 32 | + CONTAINER_PATH=$(cd "$APP_PATH" 2>/dev/null && pwd) || { |
| 33 | + echo "Error: Directory not found: $APP_PATH" |
| 34 | + exit 1 |
| 35 | + } |
| 36 | +fi |
| 37 | + |
| 38 | +# Determine the relative path for the container |
| 39 | +# Support paths like: volumes/nextcloud/apps-extra/libresign or apps-extra/libresign |
| 40 | +if [[ "$CONTAINER_PATH" =~ volumes/nextcloud(.*)$ ]]; then |
| 41 | + RELATIVE_PATH="${BASH_REMATCH[1]}" |
| 42 | + RELATIVE_PATH="${RELATIVE_PATH#/}" |
| 43 | +else |
| 44 | + # Assume it's a path relative to nextcloud root |
| 45 | + RELATIVE_PATH="${CONTAINER_PATH##*/volumes/nextcloud/}" |
| 46 | + if [[ "$RELATIVE_PATH" == "$CONTAINER_PATH" ]]; then |
| 47 | + # Not in volumes/nextcloud, assume it's an app path at the root |
| 48 | + RELATIVE_PATH="${CONTAINER_PATH##*php82-master/}" |
| 49 | + fi |
| 50 | +fi |
| 51 | + |
| 52 | +CONTAINER="nextcloud-playwright" |
| 53 | +WORKSPACE="/var/www/html/$RELATIVE_PATH" |
| 54 | + |
| 55 | +GREEN='\033[0;32m' |
| 56 | +BLUE='\033[0;34m' |
| 57 | +YELLOW='\033[1;33m' |
| 58 | +NC='\033[0m' # No Color |
| 59 | + |
| 60 | +echo -e "${BLUE}🎭 Executing E2E tests for: $RELATIVE_PATH${NC}" |
| 61 | + |
| 62 | +# Check if container is running |
| 63 | +if ! docker compose ps playwright | grep -q "Up"; then |
| 64 | + echo -e "${YELLOW}⚠️ Container playwright is not running. Starting...${NC}" |
| 65 | + docker compose up -d playwright |
| 66 | + sleep 2 |
| 67 | +fi |
| 68 | + |
| 69 | +# Check if deps are installed |
| 70 | +if ! docker compose exec -T playwright test -d "${WORKSPACE}/node_modules/@playwright" 2>/dev/null; then |
| 71 | + echo -e "${YELLOW}📦 Installing Playwright dependencies...${NC}" |
| 72 | + docker compose exec -w "$WORKSPACE" playwright npm ci |
| 73 | +fi |
| 74 | + |
| 75 | +# Run tests |
| 76 | +echo -e "${GREEN}🧪 Running Playwright tests...${NC}" |
| 77 | +docker compose exec -w "$WORKSPACE" playwright npx playwright test "$@" |
| 78 | + |
| 79 | +EXIT_CODE=$? |
| 80 | + |
| 81 | +if [ $EXIT_CODE -eq 0 ]; then |
| 82 | + echo -e "${GREEN}✅ Tests completed successfully!${NC}" |
| 83 | +else |
| 84 | + echo -e "${YELLOW}⚠️ Some tests failed. To see the report:${NC}" |
| 85 | + echo -e " docker compose exec -w \"$WORKSPACE\" playwright npx playwright show-report" |
| 86 | +fi |
| 87 | + |
| 88 | +exit $EXIT_CODE |
0 commit comments