#!/bin/bash # 本地测试脚本 # 使用本地运行的前端和后端服务进行测试 set -e echo "🚀 启动Novalon本地测试..." # 检查Node.js是否安装 if ! command -v node &> /dev/null; then echo "❌ 错误: Node.js未安装" exit 1 fi # 检查npm是否安装 if ! command -v npm &> /dev/null; then echo "❌ 错误: npm未安装" exit 1 fi # 检查服务是否运行 echo "🔍 检查本地服务状态..." # 检查前端服务 if ! curl -f http://localhost:3001 &> /dev/null 2>&1; then echo "⚠️ 警告: 前端服务未运行 (http://localhost:3001)" echo "请先启动前端服务: cd novalon-manage-web && npm run dev" read -p "是否继续测试? (y/n) " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi else echo "✅ 前端服务已运行 (http://localhost:3001)" fi # 检查后端服务 if ! curl -f http://localhost:8084/actuator/health &> /dev/null 2>&1; then echo "⚠️ 警告: 后端服务未运行 (http://localhost:8084)" echo "请先启动后端服务: cd novalon-manage-api && mvn spring-boot:run" read -p "是否继续测试? (y/n) " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 fi else echo "✅ 后端服务已运行 (http://localhost:8084)" fi # 创建测试结果目录 echo "📁 创建测试结果目录..." mkdir -p test-results playwright-report # 进入前端目录 cd novalon-manage-web # 安装依赖(如果需要) if [ ! -d "node_modules" ]; then echo "📦 安装依赖..." npm install fi # 安装Playwright浏览器(如果需要) if ! npx playwright --version &> /dev/null 2>&1; then echo "🎭 安装Playwright浏览器..." npx playwright install --with-deps chromium fi # 运行测试 echo "🧪 开始运行测试..." echo "" # 设置环境变量 export TEST_BASE_URL=http://localhost:3001 export CI=false # 运行Playwright测试 npx playwright test --reporter=json --reporter=html --reporter=junit # 检查测试结果 if [ $? -eq 0 ]; then echo "" echo "✅ 测试执行完成!" echo "" echo "📊 测试报告:" echo " - HTML报告: novalon-manage-web/playwright-report/index.html" echo " - JSON报告: novalon-manage-web/test-results/results.json" echo " - JUnit报告: novalon-manage-web/test-results/junit.xml" echo "" echo "📈 查看HTML报告:" echo " open novalon-manage-web/playwright-report/index.html" echo "" else echo "" echo "❌ 测试执行失败!" echo "" echo "📊 查看失败详情:" echo " open novalon-manage-web/playwright-report/index.html" echo "" exit 1 fi # 运行质量门禁检查 echo "🚪 执行质量门禁检查..." if [ -f "e2e/qualityGate.js" ]; then node e2e/qualityGate.js check test-results/results.json else echo "⚠️ 质量门禁工具未找到,跳过检查" fi # 更新测试趋势数据 echo "📈 更新测试趋势数据..." if [ -f "e2e/testTrendAnalyzer.js" ]; then node e2e/testTrendAnalyzer.js add test-results/custom-report.json echo "" echo "📊 测试趋势分析:" node e2e/testTrendAnalyzer.js report else echo "⚠️ 测试趋势分析工具未找到,跳过分析" fi echo "" echo "🎉 本地测试完成!" echo ""