2025/03/02

使用 GitHub Actions 在 NX Monorepo 中實現單元測試與 Cypress E2E 測試


  # 單元測試及E2E測試
  test:
    name: 單元測試及E2E測試
    runs-on: [ self-hosted, Ubuntu, 24.04 ]
    steps:
      # 單元測試
      - name: Unit Test
        run: pnpm nx test project
      # E2E 測試
      - name: E2E Test
        run: |
          # 安裝依賴套件
          sudo apt install -y libgtk2.0-0t64 libgtk-3-0t64 libgbm-dev libnotify-dev libnss3 libxss1 libasound2t64 libxtst6 xauth xvfb
          # 安裝 Cypress
          pnpm cypress install
          # 驗證 Cypress
          pnpm cypress verify
          # 執行 E2E 測試
          pnpm nx e2e project --headless