SVG2Icon • 技术指南

版本 v1.1.0

svg2icon-技术-v1.1.0

CI 门禁 —— GitHub Actions

本路线图描述如何在 GitHub Actions 中通过分层测试把关变更,确保套件通过后方可合并。

目标

  • 在每个 PR 与 main 上强制执行快速的单元/集成测试
  • 将 Cypress E2E 冒烟用例设为必过门禁
  • 通过缓存与工件保持运行确定性

推荐作业布局

  • Lint + 单元/集成(快速)
  • E2E UI(Cypress):侧栏渲染、项目 CRUD、基本下载
  • 可选夜间任务:视觉回归与更广的 E2E

工作流示例(参考)

name: CI
on:
  pull_request:
  push:
    branches: [ main ]

jobs:
  unit:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with: { node-version: 20, cache: npm }
      - run: npm ci
      - run: npm run build --if-present
      - run: npm test --workspaces -- --reporter=dot

  e2e:
    runs-on: ubuntu-latest
    needs: unit
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with: { node-version: 20, cache: npm }
      - run: npm ci
      # 在已知端口以临时 userData 启动应用(开发)
      - run: |
          export SVG2ICON_USER_DATA=$(mktemp -d)
          nohup npm run dev &
          npx wait-on http://localhost:5173 || true
      # 运行 Cypress E2E
      - uses: cypress-io/github-action@v6
        with:
          build: npm run build --if-present
          start: npm run dev
          wait-on: 'http://localhost:5173'
        env:
          SVG2ICON_USER_DATA: ${{ runner.temp }}
      - name: Upload videos and screenshots
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: cypress-artifacts
          path: |
            cypress/videos/**
            cypress/screenshots/**

说明:

  • 优先使用 npm ciactions/setup-node 缓存以加速
  • 若需 Electron,使用 Xvfb 或内建无头模式
  • 使用临时 userData 目录,确保 CI 干净且测试相互独立

分支保护(必需检查)

  • 在 GitHub 的 Branch protection 规则中将 unite2e 标记为必需
  • 启用“Require status checks to pass before merging”,并选择上述作业

控制不稳定性

  • 为 E2E 启用重试(Cypress retries: { runMode: 2 }
  • 通过测试 ID(如 data-testid="sidebar")稳定选择器
  • 保持 E2E 轻量;把细节逻辑下沉到单/集成测试

工件与排查

  • 失败时上传 Cypress 截图/视频
  • 可选上传生成的 ZIP 以验证打包;注意控制大小

下一步

  1. 落地包含 unit + e2e 的基础工作流
  2. 添加覆盖侧栏 + 项目 CRUD 的小型 Cypress 套件
  3. 扩展打包断言与(可选)夜间视觉回归
Skip to main content