#!/usr/bin/env bash # ROA2WEB Test Cleanup Script # Removes all temporary test files, screenshots, videos, and reports # Created: 2025-08-04 set -e # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' PURPLE='\033[0;35m' NC='\033[0m' # No Color # Configuration SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" FRONTEND_DIR="$SCRIPT_DIR" echo -e "${PURPLE}" echo "╔══════════════════════════════════════════════════════════════╗" echo "║ ROA2WEB Test Cleanup Tool ║" echo "║ ║" echo "║ Removes all temporary test files, screenshots, and reports ║" echo "╚══════════════════════════════════════════════════════════════╝" echo -e "${NC}" echo "" log_info() { echo -e "${BLUE}ℹ️ $1${NC}" } log_success() { echo -e "${GREEN}✅ $1${NC}" } log_warning() { echo -e "${YELLOW}⚠️ $1${NC}" } log_error() { echo -e "${RED}❌ $1${NC}" } # Function to safely remove files/directories safe_remove() { local path="$1" local description="$2" if [ -e "$path" ]; then if [ -d "$path" ]; then local count=$(find "$path" -type f | wc -l) rm -rf "$path" log_success "Removed $description ($count files)" else rm -f "$path" log_success "Removed $description" fi else log_info "$description - not found (already clean)" fi } # Function to count and remove files by pattern remove_by_pattern() { local pattern="$1" local description="$2" local files=($(find . -name "$pattern" -type f 2>/dev/null || true)) if [ ${#files[@]} -gt 0 ]; then for file in "${files[@]}"; do rm -f "$file" done log_success "Removed $description (${#files[@]} files)" else log_info "$description - not found" fi } log_info "Starting cleanup process..." echo "" # 1. Playwright Reports and Results log_info "Cleaning Playwright reports and results..." safe_remove "playwright-report" "Main Playwright HTML report" safe_remove "playwright-report-integration" "Integration Playwright HTML report" safe_remove "test-results" "Test results directory" # 2. Screenshots and Videos log_info "Cleaning screenshots and debug images..." remove_by_pattern "*.png" "Screenshot files" remove_by_pattern "*.jpg" "JPEG image files" remove_by_pattern "*.jpeg" "JPEG image files" remove_by_pattern "debug-*.png" "Debug screenshot files" remove_by_pattern "journey-*.png" "User journey screenshots" remove_by_pattern "button-debug.png" "Button debug screenshots" remove_by_pattern "responsive-*.png" "Responsive design screenshots" # 3. Video files log_info "Cleaning video recordings..." remove_by_pattern "*.webm" "WebM video files" remove_by_pattern "*.mp4" "MP4 video files" # 4. Test artifacts and temporary files log_info "Cleaning test artifacts..." safe_remove ".nyc_output" "Coverage output directory" safe_remove "coverage" "Coverage reports directory" remove_by_pattern "*.tmp" "Temporary files" remove_by_pattern "*.log" "Log files" # 5. Node.js and build artifacts (optional cleanup) if [ "$1" = "--deep" ]; then log_info "Deep cleanup mode - removing build artifacts..." safe_remove "node_modules/.cache" "Node modules cache" safe_remove "dist" "Build output directory" safe_remove ".vite" "Vite cache directory" fi # 6. Specific test debugging files log_info "Cleaning debugging artifacts..." remove_by_pattern "*-debug.json" "Debug JSON files" remove_by_pattern "*-report.json" "JSON report files" remove_by_pattern "*-report.xml" "XML report files" remove_by_pattern "*.har" "HAR network recording files" # 7. Clean any leftover Playwright traces safe_remove "trace.zip" "Playwright trace files" remove_by_pattern "trace-*.zip" "Individual trace files" echo "" log_success "🎉 Cleanup completed successfully!" echo "" # Show current directory size after cleanup if command -v du &> /dev/null; then dir_size=$(du -sh . 2>/dev/null | cut -f1) log_info "Current directory size: $dir_size" fi echo -e "${PURPLE}╔══════════════════════════════════════════════════════════════╗${NC}" echo -e "${PURPLE}║ Cleanup Summary ║${NC}" echo -e "${PURPLE}╚══════════════════════════════════════════════════════════════╝${NC}" echo "" log_info "All temporary test files have been cleaned" log_info "Run './cleanup-tests.sh --deep' for deep cleanup including build cache" echo "" # Optional: Show what would be ignored by git if [ -f ".gitignore" ]; then echo -e "${YELLOW}💡 Tip: Check .gitignore to ensure test artifacts are properly ignored${NC}" fi