From dd22c1db110145ea693ce01327c9318418a60c35 Mon Sep 17 00:00:00 2001 From: Zain Date: Tue, 16 Dec 2025 16:15:14 +0800 Subject: [PATCH] =?UTF-8?q?ci(workflows):=20=E4=BC=98=E5=8C=96=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E6=B5=81=E7=A8=8B=E5=B9=B6=E6=B7=BB=E5=8A=A0=E5=AE=8C?= =?UTF-8?q?=E6=95=B4=E6=B5=8B=E8=AF=95=E5=B7=A5=E4=BD=9C=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加新的测试脚本命令并优化CI工作流程 将常规CI测试改为快速测试模式 添加完整的测试工作流用于定期和发布时运行 调整vitest配置以支持并行测试和超时设置 更新测试错误日志前缀以增强可读性 --- .github/workflows/ci.yml | 7 +-- .github/workflows/complete-tests.yml | 71 ++++++++++++++++++++++++++++ package.json | 3 ++ tests/unit/storage.test.ts | 10 ++-- vitest.config.ts | 15 ++++++ 5 files changed, 98 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/complete-tests.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 373a2b8..1e4f6e2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -73,11 +73,12 @@ jobs: run: npm ci # ------------------------------------------ - # 步骤 4: 运行测试(带覆盖率) + # 步骤 4: 运行快速测试(无覆盖率,更快) # ------------------------------------------ - - name: 🧪 Run tests with coverage - run: npm run test:coverage + - name: 🧪 Run fast tests + run: npm run test:ci continue-on-error: false + timeout-minutes: 3 # ------------------------------------------ # 步骤 5: 上传测试覆盖率 diff --git a/.github/workflows/complete-tests.yml b/.github/workflows/complete-tests.yml new file mode 100644 index 0000000..495380e --- /dev/null +++ b/.github/workflows/complete-tests.yml @@ -0,0 +1,71 @@ +# ========================================== +# GitHub Actions Workflow: Complete Test Suite +# ========================================== +# +# 功能:运行完整的测试套件(包括性能测试) +# +# 触发条件: +# - 手动触发 +# - 每周定时运行 +# - Release 标签 +# +# 时长:约 5-10 分钟 +# +# ========================================== + +name: Complete Tests + +# 触发条件 +on: + # 手动触发 + workflow_dispatch: + + # 每周一早上运行 + schedule: + - cron: '0 0 * * 1' + + # Release 标签触发 + push: + tags: + - 'v*.*.*' + +# 环境变量 +env: + NODE_VERSION: '20' + +jobs: + complete-tests: + name: Complete Test Suite + runs-on: ubuntu-latest + timeout-minutes: 15 + + steps: + - name: 📥 Checkout repository + uses: actions/checkout@v4 + + - name: 🔧 Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ env.NODE_VERSION }} + cache: 'npm' + + - name: 📦 Install dependencies + run: npm ci + + # 运行所有单元和集成测试 + - name: 🧪 Run unit and integration tests + run: npm run test:ci + continue-on-error: false + + # 运行性能测试 + - name: 📊 Run performance tests + run: npm run test:performance + continue-on-error: false + + # 可选:运行 E2E 测试 + # - name: 🎭 Run E2E tests + # run: npm run test:e2e + # continue-on-error: false + + - name: ✅ All tests completed + run: echo "✅ Complete test suite passed!" diff --git a/package.json b/package.json index 6af9921..02fe4dc 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,9 @@ "test": "vitest", "test:ui": "vitest --ui", "test:coverage": "vitest --coverage", + "test:ci": "vitest run --coverage", + "test:full": "vitest run --coverage --config vitest.config.full.ts", + "test:performance": "vitest run tests/performance", "test:e2e": "playwright test", "test:e2e:ui": "playwright test --ui", "test:e2e:debug": "playwright test --debug", diff --git a/tests/unit/storage.test.ts b/tests/unit/storage.test.ts index 07cbdf1..eb7ab0a 100644 --- a/tests/unit/storage.test.ts +++ b/tests/unit/storage.test.ts @@ -75,7 +75,7 @@ describe('StorageManager', () => { expect(mockChromeStorage.set).toHaveBeenCalledWith({ [key]: value }); expect(console.error).toHaveBeenCalledWith( - 'Failed to save to chrome.storage:', + '[CDR] Failed to save to chrome.storage:', expect.any(Error) ); expect(mockLocalStorage.setItem).toHaveBeenCalledWith(key, JSON.stringify(value)); @@ -133,7 +133,7 @@ describe('StorageManager', () => { expect(mockChromeStorage.get).toHaveBeenCalledWith(key); expect(console.error).toHaveBeenCalledWith( - 'Failed to read from chrome.storage:', + '[CDR] Failed to read from chrome.storage:', expect.any(Error) ); expect(mockLocalStorage.getItem).toHaveBeenCalledWith(key); @@ -191,7 +191,7 @@ describe('StorageManager', () => { expect(mockChromeStorage.remove).toHaveBeenCalledWith(key); expect(console.error).toHaveBeenCalledWith( - 'Failed to remove from chrome.storage:', + '[CDR] Failed to remove from chrome.storage:', expect.any(Error) ); expect(mockLocalStorage.removeItem).toHaveBeenCalledWith(key); @@ -213,7 +213,7 @@ describe('StorageManager', () => { expect(mockChromeStorage.clear).toHaveBeenCalled(); expect(console.error).toHaveBeenCalledWith( - 'Failed to clear chrome.storage:', + '[CDR] Failed to clear chrome.storage:', expect.any(Error) ); expect(mockLocalStorage.clear).toHaveBeenCalled(); @@ -257,7 +257,7 @@ describe('StorageManager', () => { const keys = await storageManager.getAllKeys(); expect(console.error).toHaveBeenCalledWith( - 'Failed to get keys from chrome.storage:', + '[CDR] Failed to get keys from chrome.storage:', expect.any(Error) ); expect(keys).toEqual(['local-key1', 'local-key2']); diff --git a/vitest.config.ts b/vitest.config.ts index 3b1ae82..63c42fe 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -4,11 +4,26 @@ export default defineConfig({ test: { globals: true, environment: 'jsdom', + + // 测试超时配置 + testTimeout: 10000, // 10秒(默认5秒太短) + hookTimeout: 10000, + + // 排除慢速测试(用于快速反馈) exclude: [ '**/node_modules/**', '**/dist/**', '**/e2e/**', // E2E 测试由 Playwright 处理 + '**/performance/**', // 性能测试不在常规 CI 中运行 + // 暂时排除有问题的 quark-adapter 测试 + // '**/quark-adapter.test.ts', // 修复后可以移除这行 ], + + // 启用并行测试(加速执行) + threads: true, + maxThreads: 4, + minThreads: 1, + coverage: { provider: 'v8', reporter: ['text', 'json', 'html'],