|
| 1 | +#!/bin/bash |
| 2 | +# E2E Test Runner with CI Config Swap |
| 3 | +# This script temporarily replaces static/config.json with static/config.ci.json |
| 4 | +# during e2e tests and restores it afterward. |
| 5 | + |
| 6 | +set -e # Exit on error |
| 7 | + |
| 8 | +# Colors for output |
| 9 | +RED='\033[0;31m' |
| 10 | +GREEN='\033[0;32m' |
| 11 | +YELLOW='\033[1;33m' |
| 12 | +BLUE='\033[0;34m' |
| 13 | +NC='\033[0m' # No Color |
| 14 | + |
| 15 | +CONFIG_DIR="static" |
| 16 | +CONFIG_FILE="${CONFIG_DIR}/config.json" |
| 17 | +CI_CONFIG_FILE="${CONFIG_DIR}/config.ci.json" |
| 18 | +BACKUP_FILE="${CONFIG_DIR}/config.json.backup" |
| 19 | + |
| 20 | +# Function to restore config on exit |
| 21 | +cleanup() { |
| 22 | + local exit_code=$? |
| 23 | + |
| 24 | + if [ -f "$BACKUP_FILE" ]; then |
| 25 | + echo -e "\n${BLUE}🔄 Restoring original config.json...${NC}" |
| 26 | + mv "$BACKUP_FILE" "$CONFIG_FILE" |
| 27 | + echo -e "${GREEN}✅ Original config.json restored${NC}" |
| 28 | + fi |
| 29 | + |
| 30 | + if [ $exit_code -ne 0 ]; then |
| 31 | + echo -e "${RED}❌ Tests failed with exit code: $exit_code${NC}" |
| 32 | + else |
| 33 | + echo -e "${GREEN}✅ Tests completed successfully${NC}" |
| 34 | + fi |
| 35 | + |
| 36 | + exit $exit_code |
| 37 | +} |
| 38 | + |
| 39 | +# Register cleanup function to run on script exit |
| 40 | +trap cleanup EXIT INT TERM |
| 41 | + |
| 42 | +# Check if nostr-relay is running on port 7000 |
| 43 | +echo -e "${BLUE}🔍 Checking for local nostr-relay on port 7000...${NC}" |
| 44 | +if ! nc -z localhost 7000 2>/dev/null && ! lsof -i:7000 >/dev/null 2>&1 && ! ss -tuln 2>/dev/null | grep -q ":7000 "; then |
| 45 | + echo -e "${RED}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" |
| 46 | + echo -e "${RED}❌ ERROR: Nostr relay is not running on port 7000!${NC}" |
| 47 | + echo -e "${RED}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" |
| 48 | + echo -e "" |
| 49 | + echo -e "The E2E tests require a local nostr relay running on ${YELLOW}ws://localhost:7000${NC}" |
| 50 | + echo -e "" |
| 51 | + echo -e "To start the relay, run:" |
| 52 | + echo -e " ${GREEN}docker compose up -d${NC}" |
| 53 | + echo -e "" |
| 54 | + echo -e "Then verify it's running with:" |
| 55 | + echo -e " ${GREEN}docker compose ps${NC}" |
| 56 | + echo -e "" |
| 57 | + echo -e "Once the relay is running, try this command again." |
| 58 | + echo -e "${RED}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" |
| 59 | + |
| 60 | + # Unset trap to avoid cleanup on this error exit |
| 61 | + trap - EXIT INT TERM |
| 62 | + exit 1 |
| 63 | +fi |
| 64 | +echo -e "${GREEN}✅ Nostr relay is running on port 7000${NC}" |
| 65 | +echo "" |
| 66 | + |
| 67 | +# Main script |
| 68 | +echo -e "${YELLOW}⚠️ WARNING: E2E Test Config Swap${NC}" |
| 69 | +echo -e "${YELLOW}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" |
| 70 | +echo -e "This script will temporarily replace:" |
| 71 | +echo -e " ${BLUE}${CONFIG_FILE}${NC}" |
| 72 | +echo -e "with:" |
| 73 | +echo -e " ${BLUE}${CI_CONFIG_FILE}${NC}" |
| 74 | +echo -e "" |
| 75 | +echo -e "The original config will be restored automatically after the tests." |
| 76 | +echo -e "${YELLOW}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" |
| 77 | +echo "" |
| 78 | + |
| 79 | +# Check if CI config exists |
| 80 | +if [ ! -f "$CI_CONFIG_FILE" ]; then |
| 81 | + echo -e "${RED}❌ Error: ${CI_CONFIG_FILE} not found!${NC}" |
| 82 | + exit 1 |
| 83 | +fi |
| 84 | + |
| 85 | +# Backup current config |
| 86 | +if [ -f "$CONFIG_FILE" ]; then |
| 87 | + echo -e "${BLUE}📦 Backing up current config.json...${NC}" |
| 88 | + cp "$CONFIG_FILE" "$BACKUP_FILE" |
| 89 | + echo -e "${GREEN}✅ Backup created: ${BACKUP_FILE}${NC}" |
| 90 | +else |
| 91 | + echo -e "${YELLOW}⚠️ No existing config.json found, skipping backup${NC}" |
| 92 | +fi |
| 93 | + |
| 94 | +# Copy CI config to config.json |
| 95 | +echo -e "${BLUE}🔄 Copying config.ci.json to config.json...${NC}" |
| 96 | +cp "$CI_CONFIG_FILE" "$CONFIG_FILE" |
| 97 | +echo -e "${GREEN}✅ CI config activated${NC}" |
| 98 | +echo "" |
| 99 | + |
| 100 | +# Run e2e tests |
| 101 | +echo -e "${BLUE}🧪 Running E2E tests...${NC}" |
| 102 | +echo -e "${YELLOW}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" |
| 103 | +playwright test "$@" |
| 104 | + |
| 105 | +# Note: cleanup function will be called automatically due to trap |
0 commit comments