#!/bin/bash echo "🚀 分层测试系统验证" echo "==========================" echo "" # 颜色定义 GREEN='\033[0;32m' RED='\033[0;31m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # 验证计数器 TOTAL_CHECKS=0 PASSED_CHECKS=0 FAILED_CHECKS=0 # 验证函数 check_file() { local file=$1 local description=$2 TOTAL_CHECKS=$((TOTAL_CHECKS + 1)) if [ -f "$file" ]; then echo -e "${GREEN}✅${NC} $description: $file" PASSED_CHECKS=$((PASSED_CHECKS + 1)) return 0 else echo -e "${RED}❌${NC} $description: $file (文件不存在)" FAILED_CHECKS=$((FAILED_CHECKS + 1)) return 1 fi } check_dir() { local dir=$1 local description=$2 TOTAL_CHECKS=$((TOTAL_CHECKS + 1)) if [ -d "$dir" ]; then echo -e "${GREEN}✅${NC} $description: $dir" PASSED_CHECKS=$((PASSED_CHECKS + 1)) return 0 else echo -e "${RED}❌${NC} $description: $dir (目录不存在)" FAILED_CHECKS=$((FAILED_CHECKS + 1)) return 1 fi } check_script() { local script=$1 local description=$2 TOTAL_CHECKS=$((TOTAL_CHECKS + 1)) if [ -f "$script" ] && [ -x "$script" ]; then echo -e "${GREEN}✅${NC} $description: $script" PASSED_CHECKS=$((PASSED_CHECKS + 1)) return 0 else echo -e "${RED}❌${NC} $description: $script (文件不存在或不可执行)" FAILED_CHECKS=$((FAILED_CHECKS + 1)) return 1 fi } check_npm_script() { local script_name=$1 local description=$2 TOTAL_CHECKS=$((TOTAL_CHECKS + 1)) if npm run | grep -q "$script_name"; then echo -e "${GREEN}✅${NC} $description: npm run $script_name" PASSED_CHECKS=$((PASSED_CHECKS + 1)) return 0 else echo -e "${RED}❌${NC} $description: npm run $script_name (脚本不存在)" FAILED_CHECKS=$((FAILED_CHECKS + 1)) return 1 fi } echo "📁 检查配置文件" echo "-------------------" check_file "e2e/src/config/test-tiers.ts" "测试层级配置" check_file "e2e/src/config/test-tags.ts" "测试标记配置" check_file "e2e/playwright.config.tiered.ts" "分层测试Playwright配置" check_file ".woodpecker/test-tiered.yml" "Woodpecker CI配置" check_file ".woodpecker/test-tiered-simple.yml" "简化版Woodpecker CI配置" echo "" echo "🔧 检查工具文件" echo "-------------------" check_file "e2e/src/utils/test-history.ts" "测试历史管理器" check_file "e2e/src/utils/test-scheduler.ts" "智能测试调度器" check_file "e2e/src/utils/test-reporter.ts" "测试报告生成器" check_file "e2e/src/utils/test-monitor.ts" "测试监控器" check_file "e2e/src/utils/test-alert.ts" "测试告警管理器" check_file "e2e/src/utils/test-optimizer.ts" "测试性能优化器" echo "" echo "📝 检查脚本文件" echo "-------------------" check_file "e2e/global-setup.ts" "全局设置脚本" check_file "e2e/global-teardown.ts" "全局清理脚本" check_file "e2e/scripts/generate-report.js" "CI报告生成脚本" check_file "scripts/validate-woodpecker-config.js" "Woodpecker配置验证脚本" echo "" echo "📚 检查文档文件" echo "-------------------" check_file "README-TIERED-TESTING.md" "快速入门指南" check_file "docs/test-optimization-guide.md" "测试优化指南" check_file "docs/test-tiering-best-practices.md" "最佳实践文档" echo "" echo "🎯 检查NPM脚本" echo "-------------------" check_npm_script "test:tier:fast" "快速层测试脚本" check_npm_script "test:tier:standard" "标准层测试脚本" check_npm_script "test:tier:deep" "深度层测试脚本" check_npm_script "test:tier:all" "所有层级测试脚本" check_npm_script "test:tier:ci" "CI测试脚本" echo "" echo "📊 检查测试文件" echo "-------------------" check_dir "e2e/src/tests/smoke" "冒烟测试目录" check_dir "e2e/src/tests/api" "API测试目录" check_dir "e2e/src/tests/admin" "管理后台测试目录" echo "" echo "🔍 验证TypeScript编译" echo "-------------------" TOTAL_CHECKS=$((TOTAL_CHECKS + 1)) if cd e2e && npx tsc --noEmit src/config/test-tiers.ts src/config/test-tags.ts src/utils/*.ts 2>/dev/null; then echo -e "${GREEN}✅${NC} TypeScript编译通过" PASSED_CHECKS=$((PASSED_CHECKS + 1)) else echo -e "${RED}❌${NC} TypeScript编译失败" FAILED_CHECKS=$((FAILED_CHECKS + 1)) fi cd .. echo "" echo "📈 生成验证报告" echo "==========================" echo "" echo "总检查项: $TOTAL_CHECKS" echo -e "${GREEN}通过: $PASSED_CHECKS${NC}" echo -e "${RED}失败: $FAILED_CHECKS${NC}" echo "" if [ $FAILED_CHECKS -eq 0 ]; then echo -e "${GREEN}🎉 所有验证通过!分层测试系统已就绪。${NC}" exit 0 else echo -e "${YELLOW}⚠️ 发现 $FAILED_CHECKS 个问题,请检查并修复。${NC}" exit 1 fi