playwright-e2e-docker/scripts/init-e2e.sh

67 lines
2.4 KiB
Bash
Raw Permalink Normal View History

#!/bin/bash
# Initialize E2E testing infrastructure in a project
#
# Usage: npx @transquinnftw/playwright-e2e-docker init
# or: ./scripts/init-e2e.sh /path/to/project
set -e
PROJECT_DIR="${1:-.}"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
TEMPLATE_DIR="$SCRIPT_DIR/../templates"
echo "Initializing Playwright E2E Docker infrastructure..."
# Create e2e directory
mkdir -p "$PROJECT_DIR/e2e"
mkdir -p "$PROJECT_DIR/e2e/mock-service"
mkdir -p "$PROJECT_DIR/test-results"
# Copy templates
echo "Copying Docker templates..."
cp "$TEMPLATE_DIR/Dockerfile" "$PROJECT_DIR/e2e/"
cp "$TEMPLATE_DIR/docker-compose.yml" "$PROJECT_DIR/e2e/"
cp "$TEMPLATE_DIR/mock-service.Dockerfile" "$PROJECT_DIR/e2e/"
echo "Copying mock service template..."
cp "$TEMPLATE_DIR/mock-service/app.py" "$PROJECT_DIR/e2e/mock-service/"
cp "$TEMPLATE_DIR/mock-service/__init__.py" "$PROJECT_DIR/e2e/mock-service/"
echo "Copying test templates..."
cp "$TEMPLATE_DIR/electron.ts" "$PROJECT_DIR/e2e/"
cp "$TEMPLATE_DIR/example.e2e.ts" "$PROJECT_DIR/e2e/"
# Check if playwright.config.ts exists
if [ ! -f "$PROJECT_DIR/playwright.config.ts" ]; then
echo "Copying Playwright config..."
cp "$TEMPLATE_DIR/playwright.config.ts" "$PROJECT_DIR/"
else
echo "playwright.config.ts already exists, skipping..."
fi
# Add .gitignore entries
echo "Updating .gitignore..."
if [ -f "$PROJECT_DIR/.gitignore" ]; then
if ! grep -q "test-results" "$PROJECT_DIR/.gitignore"; then
echo -e "\n# E2E test artifacts\ntest-results/\nplaywright-report/" >> "$PROJECT_DIR/.gitignore"
fi
else
echo -e "# E2E test artifacts\ntest-results/\nplaywright-report/" > "$PROJECT_DIR/.gitignore"
fi
echo ""
echo "E2E infrastructure initialized!"
echo ""
echo "Next steps:"
echo " 1. Add @transquinnftw/playwright-e2e-docker and @playwright/test to devDependencies"
echo " 2. Customize e2e/docker-compose.yml for your backend services"
echo " 3. Customize e2e/mock-service/app.py for your API"
echo " 4. Update e2e/electron.ts with your app's main path"
echo " 5. Add npm scripts to package.json:"
echo ""
echo ' "test:e2e": "pnpm test:e2e:docker",'
echo ' "test:e2e:docker": "docker build -f e2e/Dockerfile -t app-e2e . && docker run --rm -v $(pwd)/test-results:/app/test-results app-e2e",'
echo ' "test:e2e:full": "docker compose -f e2e/docker-compose.yml up --build --abort-on-container-exit --exit-code-from e2e-tests",'
echo ' "test:e2e:down": "docker compose -f e2e/docker-compose.yml down -v"'
echo ""