#!/bin/bash # ============================================================================= # E2E 測試運行腳本 # E2E Test Runner Script # ============================================================================= # # 使用方式: # ./scripts/run-e2e-tests.sh [選項] # # 選項: # --all 運行所有 E2E 測試 # --quick 只運行快速測試(跳過翻譯) # --matrix 只運行格式矩陣測試 # --translation 只運行翻譯測試 # --comprehensive 運行全面測試 # --report 生成 HTML 報告 # # ============================================================================= set -e # 顏色定義 RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # 腳本目錄 SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" # 輸出目錄 OUTPUT_DIR="$PROJECT_ROOT/tests/e2e/output" # 確保輸出目錄存在 mkdir -p "$OUTPUT_DIR" # 打印標題 print_header() { echo "" echo -e "${BLUE}================================================================${NC}" echo -e "${BLUE} $1${NC}" echo -e "${BLUE}================================================================${NC}" echo "" } # 打印成功訊息 print_success() { echo -e "${GREEN}✓ $1${NC}" } # 打印警告訊息 print_warning() { echo -e "${YELLOW}⚠ $1${NC}" } # 打印錯誤訊息 print_error() { echo -e "${RED}✗ $1${NC}" } # 檢查依賴 check_dependencies() { print_header "檢查測試依賴 Checking Dependencies" local missing=0 # 檢查 bun if command -v bun &> /dev/null; then print_success "bun $(bun --version)" else print_error "bun not found" missing=$((missing + 1)) fi # 檢查常用轉換工具 local tools=("inkscape" "pandoc" "ffmpeg" "magick" "soffice") for tool in "${tools[@]}"; do if command -v "$tool" &> /dev/null; then print_success "$tool found" else print_warning "$tool not found (some tests may be skipped)" fi done # 檢查翻譯工具 local translators=("pdf2zh" "babeldoc") for translator in "${translators[@]}"; do if command -v "$translator" &> /dev/null; then print_success "$translator found" else print_warning "$translator not found (translation tests will be skipped)" fi done if [ $missing -gt 0 ]; then print_error "Missing required dependencies" exit 1 fi echo "" } # 運行快速測試 run_quick_tests() { print_header "運行快速 E2E 測試 Running Quick E2E Tests" cd "$PROJECT_ROOT" bun test tests/e2e/converters.e2e.test.ts --timeout 120000 } # 運行格式矩陣測試 run_matrix_tests() { print_header "運行格式矩陣測試 Running Format Matrix Tests" cd "$PROJECT_ROOT" bun test tests/e2e/format-matrix.e2e.test.ts --timeout 300000 } # 運行翻譯測試 run_translation_tests() { print_header "運行翻譯測試 Running Translation Tests" # 檢查 API 金鑰 if [ -z "$OPENAI_API_KEY" ] && [ -z "$GOOGLE_API_KEY" ] && [ -z "$DEEPL_API_KEY" ]; then print_warning "No translation API keys found. Some tests may fail." print_warning "Set OPENAI_API_KEY, GOOGLE_API_KEY, or DEEPL_API_KEY" fi cd "$PROJECT_ROOT" bun test tests/e2e/translation.e2e.test.ts --timeout 600000 } # 運行全面測試 run_comprehensive_tests() { print_header "運行全面 E2E 測試 Running Comprehensive E2E Tests" cd "$PROJECT_ROOT" bun test tests/e2e/comprehensive.e2e.test.ts --timeout 600000 } # 運行所有測試 run_all_tests() { print_header "運行所有 E2E 測試 Running All E2E Tests" cd "$PROJECT_ROOT" bun test tests/e2e/ --timeout 600000 } # 生成 HTML 報告 generate_report() { print_header "生成測試報告 Generating Test Report" local report_file="$OUTPUT_DIR/test-report.html" cat > "$report_file" << 'EOF'
生成時間: