trip-planner/tests/run-tests.sh

111 lines
2.8 KiB
Bash
Raw Normal View History

2025-09-27 01:26:58 +02:00
#!/bin/bash
# Test Runner Script for Trip Planner E2E Tests
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Default values
TEST_TYPE="local"
TEST_FILE=""
HEADLESS="false"
# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
--docker)
TEST_TYPE="docker"
shift
;;
--headless)
HEADLESS="true"
shift
;;
--auth)
TEST_FILE="e2e/auth.test.js"
shift
;;
--full-auth)
TEST_FILE="e2e/full-auth-flow.test.js"
shift
;;
--help)
echo "Usage: ./run-tests.sh [options]"
echo ""
echo "Options:"
echo " --docker Run tests using Docker Selenium (requires Docker setup)"
echo " --headless Run tests in headless mode"
echo " --auth Run auth.test.js only"
echo " --full-auth Run full-auth-flow.test.js only"
echo " --help Show this help message"
echo ""
echo "Examples:"
echo " ./run-tests.sh # Run all tests with local Chrome"
echo " ./run-tests.sh --docker # Run all tests with Docker Selenium"
echo " ./run-tests.sh --full-auth # Run full auth test only"
echo " ./run-tests.sh --headless # Run locally in headless mode"
exit 0
;;
*)
echo -e "${RED}Unknown option: $1${NC}"
echo "Use --help for usage information"
exit 1
;;
esac
done
# Check if npm packages are installed
if [ ! -d "node_modules" ]; then
echo -e "${YELLOW}Installing npm packages...${NC}"
npm install
fi
# Check if Docker services are running (for Docker mode)
if [ "$TEST_TYPE" = "docker" ]; then
echo -e "${YELLOW}Checking Docker services...${NC}"
# Check if selenium-hub is running
if ! podman ps | grep -q "selenium-hub"; then
echo -e "${RED}Selenium Hub is not running!${NC}"
echo "Please start Docker services with: podman-compose -f ../docker-compose.dev.yml up -d"
exit 1
fi
# Check if frontend is accessible
if ! curl -s -o /dev/null -w "%{http_code}" http://localhost:5173 | grep -q "200"; then
echo -e "${RED}Frontend is not accessible at http://localhost:5173${NC}"
echo "Please start the frontend service"
exit 1
fi
fi
# Create screenshots directory if it doesn't exist
mkdir -p screenshots
# Run tests
echo -e "${GREEN}Running tests...${NC}"
echo "Mode: $TEST_TYPE"
echo "Headless: $HEADLESS"
if [ "$TEST_TYPE" = "local" ]; then
# Local Chrome execution
if [ -n "$TEST_FILE" ]; then
HEADLESS=$HEADLESS npm test -- $TEST_FILE
else
HEADLESS=$HEADLESS npm test
fi
else
# Docker Selenium execution
if [ -n "$TEST_FILE" ]; then
HEADLESS=$HEADLESS npm run test:docker -- $TEST_FILE
else
HEADLESS=$HEADLESS npm run test:docker
fi
fi
echo -e "${GREEN}Tests completed!${NC}"