← back to Wine Finder Next

run-tests.sh

148 lines

#!/bin/bash

# Wine Membership Platform - Test Runner Script
# This script provides an easy way to run different test suites

set -e

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color

# Print banner
echo -e "${BLUE}═══════════════════════════════════════════════════════${NC}"
echo -e "${BLUE}  Wine Membership Platform - Test Runner${NC}"
echo -e "${BLUE}═══════════════════════════════════════════════════════${NC}"
echo ""

# Function to print section header
print_header() {
    echo -e "\n${YELLOW}▶ $1${NC}"
    echo "─────────────────────────────────────────────────────"
}

# Function to print success
print_success() {
    echo -e "${GREEN}✓ $1${NC}"
}

# Function to print error
print_error() {
    echo -e "${RED}✗ $1${NC}"
}

# Check if npm is installed
if ! command -v npm &> /dev/null; then
    print_error "npm is not installed. Please install Node.js and npm first."
    exit 1
fi

# Check if dependencies are installed
if [ ! -d "node_modules" ]; then
    print_header "Installing dependencies..."
    npm install
fi

# Parse command line arguments
TEST_TYPE=${1:-all}

case $TEST_TYPE in
    unit)
        print_header "Running Unit Tests"
        npm run test:unit
        ;;

    integration)
        print_header "Running Integration Tests"
        npm run test:integration
        ;;

    security)
        print_header "Running Security Tests"
        npm run test:security
        ;;

    performance)
        print_header "Running Performance Tests"
        npm run test:performance
        ;;

    e2e)
        print_header "Running E2E Tests"
        npm run test:e2e
        ;;

    coverage)
        print_header "Running Tests with Coverage"
        npm run test:coverage
        print_success "Coverage report generated at: coverage/lcov-report/index.html"
        ;;

    ci)
        print_header "Running CI Test Suite"
        npm run test:ci
        ;;

    all)
        print_header "Running Complete Test Suite"

        print_header "1/5 - Unit Tests"
        npm run test:unit || print_error "Unit tests failed"

        print_header "2/5 - Integration Tests"
        npm run test:integration || print_error "Integration tests failed"

        print_header "3/5 - Security Tests"
        npm run test:security || print_error "Security tests failed"

        print_header "4/5 - Performance Tests"
        npm run test:performance || print_error "Performance tests failed"

        print_header "5/5 - E2E Tests"
        npm run test:e2e || print_error "E2E tests failed"

        print_success "All test suites completed!"
        ;;

    watch)
        print_header "Running Tests in Watch Mode"
        npm test
        ;;

    help|--help|-h)
        echo "Usage: ./run-tests.sh [TEST_TYPE]"
        echo ""
        echo "Test Types:"
        echo "  unit          - Run unit tests only"
        echo "  integration   - Run integration tests only"
        echo "  security      - Run security tests only"
        echo "  performance   - Run performance tests only"
        echo "  e2e           - Run E2E tests only"
        echo "  coverage      - Run tests with coverage report"
        echo "  ci            - Run tests in CI mode"
        echo "  watch         - Run tests in watch mode"
        echo "  all           - Run all test suites (default)"
        echo "  help          - Show this help message"
        echo ""
        echo "Examples:"
        echo "  ./run-tests.sh unit"
        echo "  ./run-tests.sh coverage"
        echo "  ./run-tests.sh all"
        exit 0
        ;;

    *)
        print_error "Unknown test type: $TEST_TYPE"
        echo "Run './run-tests.sh help' for usage information"
        exit 1
        ;;
esac

echo ""
echo -e "${BLUE}═══════════════════════════════════════════════════════${NC}"
echo -e "${GREEN}Test execution completed!${NC}"
echo -e "${BLUE}═══════════════════════════════════════════════════════${NC}"