Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: e2e test & ci integration #2740

Open
wants to merge 29 commits into
base: feat_v3.x
Choose a base branch
from
Open

Conversation

Alex-huxiyang
Copy link
Collaborator

@Alex-huxiyang Alex-huxiyang commented Nov 12, 2024

🤔 这个变动的性质是?

  • 新特性提交
  • 日常 bug 修复
  • 站点、文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • TypeScript 定义更新
  • 包体积优化
  • 性能优化
  • 功能增强
  • 国际化改进
  • 重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他改动(是关于什么的改动?)

🔗 相关 Issue

💡 需求背景和解决方案

☑️ 请求合并前的自查清单

⚠️ 请自检并全部勾选全部选项⚠️

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充
  • fork仓库代码是否为最新避免文件冲突
  • Files changed 没有 package.json lock 等无关文件

Summary by CodeRabbit

  • 新功能
    • 引入新的Cypress测试工作流以支持端到端测试。
    • 添加新的测试脚本以便于在H5和Taro环境中运行Cypress测试。
  • 变更
    • 更新Cypress版本并重新组织依赖项以增强开发工作流。
    • 修改Cypress配置以支持更广泛的文件类型。
    • 移除了一些不再使用的组件测试文件,简化了测试结构。
    • 更新package.json中的版本号和脚本命令。

Copy link

coderabbitai bot commented Nov 12, 2024

Walkthrough

此次变更引入了新的GitHub Actions工作流文件cypress.yml,用于支持项目的端到端(E2E)测试。该工作流在V3.0分支的推送和拉取请求时触发,包含多个步骤,包括检出代码、设置Node.js环境、安装依赖和运行H5平台的E2E测试。同时,cypress.config.ts文件的配置也进行了调整,移除了baseUrl属性,并更新了specPattern以支持多种文件类型。此外,多个Cypress测试文件被删除,并新增了多个测试套件和组件测试的占位符。

Changes

文件路径 更改摘要
.github/workflows/cypress.yml 新增工作流文件,定义E2E测试的步骤和触发条件。
cypress.config.ts 移除baseUrl属性,更新specPattern以支持*.{js,jsx,ts,tsx}文件类型。
cypress/component/Actionsheet.cy.jsx 删除文件,包含ActionSheet组件的Cypress测试。
cypress/component/Button.cy.jsx 删除文件,包含Button组件的Cypress测试。
cypress/component/Cell.cy.jsx 删除文件,包含Cell组件的Cypress测试。
cypress/e2e/h5/base.cy.js 新增测试套件,使用componentTest函数定义多个组件的测试占位符。
cypress/e2e/h5/bussiness.cy.js 新增测试套件,定义多个业务组件的测试占位符。
cypress/e2e/h5/dentry.cy.js 新增测试套件,定义多个dentry模块组件的测试占位符。
cypress/e2e/h5/exhibition.cy.js 新增测试文件,定义多个展览组件的测试占位符。
cypress/e2e/h5/feedback.cy.js 新增测试套件,定义多个反馈组件的测试占位符。
cypress/e2e/h5/index.cy.js 新增文件,组织多个E2E测试文件的导入,并实现全局错误处理机制。
cypress/e2e/h5/layout.cy.js 新增测试套件,定义多个布局组件的测试占位符。
cypress/e2e/h5/nav.cy.js 新增测试套件,定义多个导航组件的测试占位符。
cypress/e2e/h5/utils.js 新增componentTest函数,简化组件测试逻辑。
cypress/e2e/index.cy.js 删除文件,包含对多个Taro框架相关测试文件的导入和错误处理机制。
cypress/e2e/taro/base.cy.js 新增componentTest函数,简化多个组件的测试逻辑。
cypress/e2e/taro/bussiness.cy.js 新增测试套件,定义TrendArrow组件的测试占位符。
cypress/e2e/taro/dentry.cy.js 修改componentTest函数,更新测试路径和激活的组件测试。
cypress/e2e/taro/exhibition.cy.js 新增测试套件,定义多个展览组件的测试占位符。
cypress/e2e/taro/feedback.cy.js 新增测试套件,定义多个反馈组件的测试占位符。
cypress/e2e/taro/index.cy.js 新增文件,组织多个Taro相关测试文件的导入,并实现全局错误处理机制。
cypress/e2e/taro/layout.cy.js 新增测试套件,定义多个布局组件的测试占位符。
cypress/e2e/taro/nav.cy.js 新增测试套件,定义多个导航组件的测试占位符。
package.json 更新版本至3.0.0-beta.4,新增Cypress测试脚本,更新依赖项,移除旧的测试脚本。

Sequence Diagram(s)

sequenceDiagram
    participant GitHub Actions
    participant Node.js
    participant Cypress
    participant Components

    GitHub Actions->>Node.js: 设置环境
    Node.js->>Cypress: 安装依赖
    Cypress->>Components: 运行E2E测试
    Components-->>Cypress: 返回测试结果
    Cypress-->>Node.js: 测试完成
    Node.js-->>GitHub Actions: 反馈结果
Loading

Possibly related PRs

Suggested reviewers

  • irisSong
  • oasis-cloud

🐰 兔子欢呼,测试新气象,
Cypress工作流,助力无阻挡。
组件齐上阵,E2E来助力,
未来更精彩,兔子乐开怀!
🥕✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 5667f45 and 7107a70.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (1)
  • package.json (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • package.json

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the 3.x label Nov 12, 2024
Copy link

codecov bot commented Nov 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.99%. Comparing base (9332996) to head (7107a70).

Additional details and impacted files
@@            Coverage Diff             @@
##           feat_v3.x    #2740   +/-   ##
==========================================
  Coverage      83.99%   83.99%           
==========================================
  Files            220      220           
  Lines          17885    17885           
  Branches        2679     2679           
==========================================
  Hits           15023    15023           
  Misses          2857     2857           
  Partials           5        5           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 28

🧹 Outside diff range and nitpick comments (16)
cypress/e2e/h5/index.cy.js (1)

1-7: 建议为测试类别添加文档说明

测试文件按照功能模块进行了良好的分类,建议在文件顶部添加注释来说明每个测试类别的用途,以提高代码的可维护性。

添加如下注释:

+/**
+ * Cypress E2E 测试入口文件
+ * - base.cy: 基础组件测试
+ * - layout.cy: 布局组件测试
+ * - nav.cy: 导航组件测试
+ * - dentry.cy: 数据录入组件测试
+ * - bussiness.cy: 业务组件测试
+ * - exhibition.cy: 展示组件测试
+ * - feedback.cy: 反馈组件测试
+ */
 import './base.cy'
 import './layout.cy'
cypress/e2e/taro/index.cy.js (1)

9-11: 建议完善异常处理机制

当前的异常处理直接忽略所有未捕获的异常,建议:

  1. 添加注释说明为什么要忽略这些异常
  2. 考虑添加异常日志记录,以便于问题排查

建议修改为:

+// 忽略所有未捕获的异常,防止测试因第三方库或其他非关键异常而中断
 Cypress.on('uncaught:exception', (err, runnable) => {
+  // 记录异常信息以便调试
+  console.warn('捕获到未处理的异常:', err.message);
   return false
 })
cypress/e2e/h5/bussiness.cy.js (2)

1-1: 文件名和描述块中的拼写错误

文件名和描述块中的 "bussiness" 应该修改为 "business"。

应用以下更改:

- describe('bussiness components test', () => {
+ describe('business components test', () => {

同时建议将文件名从 bussiness.cy.js 更改为 business.cy.js

Also applies to: 3-3


1-10: 建议添加测试用例分组

为了更好的组织测试用例,建议将相关组件的测试进行分组。

建议重构为:

import { componentTest } from './utils'

describe('business components test', () => {
  describe('展示类组件', () => {
    componentTest('Barrage', () => {
      // 弹幕组件测试...
    })
    componentTest('Card', () => {
      // 卡片组件测试...
    })
    componentTest('WaterMark', () => {
      // 水印组件测试...
    })
  })

  describe('功能类组件', () => {
    componentTest('TimeSelect', () => {
      // 时间选择测试...
    })
    componentTest('TrendArrow', () => {
      // 趋势箭头测试...
    })
    componentTest('AvatarCropper', () => {
      // 头像裁剪测试...
    })
  })
})
cypress/e2e/h5/nav.cy.js (1)

1-12: 建议添加测试文档注释

为了提高测试代码的可维护性,建议添加以下内容:

  • 测试套件的整体说明
  • 每个组件测试的预期行为描述
  • 测试数据和断言说明

建议添加如下注释:

import { componentTest } from './utils'

+/**
+ * 导航组件端到端测试套件
+ * 
+ * 测试范围:
+ * - 基础渲染
+ * - 交互行为
+ * - 响应式适配
+ * - 边界条件
+ */
describe('nav components test', () => {
cypress/e2e/taro/base.cy.js (1)

1-11: 建议增强 componentTest 函数的健壮性和可配置性

建议做如下改进:

  1. 添加参数验证,确保 comName 不为空
  2. 将等待时间设置为可配置参数
  3. 添加更多的错误处理机制

建议按照以下方式重构:

-const componentTest = (comName, fn) => {
+const componentTest = (comName, fn, options = { waitTime: 1000 }) => {
+  if (!comName) {
+    throw new Error('组件名称不能为空');
+  }
   const getPath = (component) =>
     `${Cypress.env('baseUrl')}base/pages/${component.toLowerCase()}/index`

   it(`${comName} successfully passes`, () => {
+    cy.intercept('GET', getPath(comName)).as('pageLoad')
     cy.visit(getPath(comName))
+    cy.wait('@pageLoad')
     cy.get('.applets-demo-header').contains(comName)
-    cy.wait(1000)
+    cy.wait(options.waitTime)
     fn()
   })
 }
cypress/e2e/h5/utils.js (1)

1-2: 建议优化路径构建逻辑

建议将 getPath 函数提取到外部,使其可重用,并添加路径验证。

+const validatePath = (path) => {
+  if (!path.startsWith('/')) return `/${path}`
+  return path
+}
+export const getPath = (component) => `${Cypress.env('baseUrl')}${validatePath(component)}`
+
 export const componentTest = (comName, fn, delay = 800) => {
-  const getPath = (component) => `${Cypress.env('baseUrl')}${component}`
   // ... rest of the code
.github/workflows/cypress.yml (3)

3-9: 建议扩展工作流触发条件

建议考虑将工作流触发条件扩展到主分支(main/master),以确保所有重要更改都经过端到端测试。这样可以在合并到主分支之前捕获潜在问题。

 on:
   push:
     branches:
+      - main
       - V3.0
   pull_request:
     branches:
+      - main
       - V3.0

21-25: 建议优化缓存策略

当前的缓存配置可以进一步优化,建议添加缓存恢复/保存的键值以提高缓存命中率。

 - uses: actions/setup-node@v4
   with:
     node-version: '20'
     cache: 'pnpm'
+    cache-dependency-path: '**/pnpm-lock.yaml'

11-13: 建议优化工作流架构

当前工作流使用单一作业顺序执行所有测试。建议考虑以下架构改进:

  1. 将 H5 和 Taro 测试拆分为并行作业
  2. 添加部署验证步骤
  3. 配置测试矩阵以覆盖不同的浏览器/设备

建议重构工作流结构如下:

jobs:
  setup:
    # 共享环境设置
  
  test-h5:
    needs: setup
    # H5 测试配置
    
  test-taro:
    needs: setup
    # Taro 测试配置
    
  deploy-preview:
    needs: [test-h5, test-taro]
    # 部署预览环境
cypress/e2e/h5/feedback.cy.js (2)

1-2: 建议添加工具函数的类型定义

为了提高代码的可维护性和可读性,建议为 componentTest 工具函数添加 TypeScript 类型定义。

建议修改如下:

-import { componentTest } from './utils'
+import { componentTest } from './utils'
+
+// 添加类型注释
+// componentTest: (component: string, testFn: () => void) => void

3-20: 建议添加测试用例说明文档

为了帮助其他开发者理解测试用例的目的和覆盖范围,建议在测试套件开始处添加必要的说明文档。

+/**
+ * 反馈类组件端到端测试
+ * 
+ * 测试范围:
+ * - 基础渲染
+ * - 组件交互
+ * - 事件触发
+ * - 异常处理
+ */
 describe('feedback components test', () => {
cypress/e2e/h5/exhibition.cy.js (1)

1-23: 建议优化测试文件的组织结构

当前文件包含了19个组件的测试,可能会导致文件过大难以维护。建议:

  1. 将测试按照组件类型拆分为多个文件,例如:

    • exhibition-basic.cy.js
    • exhibition-interactive.cy.js
    • exhibition-complex.cy.js
  2. 为每个测试添加详细的测试说明,包括测试目的和测试场景。

是否需要我提供具体的文件拆分方案?

.github/workflows/ci.yml (2)

Line range hint 83-109: 建议优化标签添加任务的实现

当前实现存在以下可以改进的地方:

  1. 缺少对 github.event.pull_request 是否存在的检查
  2. 标签判断逻辑可以更清晰
  3. 建议添加更多的日志输出便于调试

建议按照以下方式优化代码:

  - name: Determine label based on target branch
    id: determine-label
    run: |
-     echo "${{github.event_name}}"
+     echo "Event name: ${{ github.event_name }}"
+     echo "Event type: ${{ github.event.pull_request != '' && 'pull_request' || 'other' }}"
+     
+     if [[ "${{ github.event_name }}" != "pull_request_target" ]]; then
+       echo "不是 pull request 事件,跳过添加标签"
+       echo "label=" >> $GITHUB_ENV
+       exit 0
+     fi
+     
+     echo "目标分支: ${{ github.event.pull_request.base.ref }}"
      if [[ "${{ github.event.pull_request.base.ref }}" == "next" ]]; then
+       echo "设置标签为 2.x"
        echo "label=2.x" >> $GITHUB_ENV
      elif [[ "${{ github.event.pull_request.base.ref }}" == "V3.0" ]]; then
+       echo "设置标签为 3.x"
        echo "label=3.x" >> $GITHUB_ENV
      else
+       echo "未知的目标分支,不添加标签"
        echo "label=" >> $GITHUB_ENV
      fi

Line range hint 83-109: 建议添加工作流程说明文档

为了帮助其他开发者理解此工作流程的用途,建议在仓库中添加相关文档说明:

  1. 标签的作用和含义
  2. 不同分支对应的版本关系
  3. CI 流程的触发条件

需要我帮助生成工作流程文档模板吗?

package.json (1)

95-102: 建议改进 Cypress 测试脚本配置

建议将基础 URL 配置从脚本命令中移至 cypress.config.ts 文件中,以提高可维护性和灵活性。这样可以:

  • 避免在多个地方重复配置 URL
  • 便于在不同环境间切换
  • 使配置更容易管理

建议按照以下方式重构:

-    "cypress:run": "cypress run --env baseUrl=http://localhost:5173/react/demo.html#/zh-CN/component/",
-    "cypress:open": "cypress open --env baseUrl=http://localhost:5173/react/demo.html#/zh-CN/component/",
-    "cypress:run:taro": "cypress run --env baseUrl=http://localhost:10086/#/",
-    "cypress:open:taro": "cypress open --env baseUrl=http://localhost:10086/#/",
+    "cypress:run": "cypress run",
+    "cypress:open": "cypress open",
+    "cypress:run:taro": "cypress run --config-file cypress.taro.config.ts",
+    "cypress:open:taro": "cypress open --config-file cypress.taro.config.ts",
     "e2e:h5:run": "pnpm dev & pnpm cypress:run",
     "e2e:h5:open": "pnpm dev & pnpm cypress:open",
     "e2e:taro:run": "start-server-and-test dev:taro:h5 http://localhost:10086 cypress:run:taro",
     "e2e:taro:open": "start-server-and-test dev:taro:h5 http://localhost:10086 cypress:open:taro"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 304fd2f and 8d3f08e.

⛔ Files ignored due to path filters (3)
  • cypress/screenshots/index.cy.js/layout components test -- Switch successfully passes (failed).png is excluded by !**/*.png
  • cypress/screenshots/taro/dentry.cy.js/layout components test -- Switch successfully passes (failed).png is excluded by !**/*.png
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (25)
  • .github/workflows/ci.yml (1 hunks)
  • .github/workflows/cypress.yml (1 hunks)
  • cypress.config.ts (1 hunks)
  • cypress/component/Actionsheet.cy.jsx (0 hunks)
  • cypress/component/Button.cy.jsx (0 hunks)
  • cypress/component/Cell.cy.jsx (0 hunks)
  • cypress/e2e/h5/base.cy.js (1 hunks)
  • cypress/e2e/h5/bussiness.cy.js (1 hunks)
  • cypress/e2e/h5/dentry.cy.js (1 hunks)
  • cypress/e2e/h5/exhibition.cy.js (1 hunks)
  • cypress/e2e/h5/feedback.cy.js (1 hunks)
  • cypress/e2e/h5/index.cy.js (1 hunks)
  • cypress/e2e/h5/layout.cy.js (1 hunks)
  • cypress/e2e/h5/nav.cy.js (1 hunks)
  • cypress/e2e/h5/utils.js (1 hunks)
  • cypress/e2e/index.cy.js (0 hunks)
  • cypress/e2e/taro/base.cy.js (1 hunks)
  • cypress/e2e/taro/bussiness.cy.js (1 hunks)
  • cypress/e2e/taro/dentry.cy.js (1 hunks)
  • cypress/e2e/taro/exhibition.cy.js (1 hunks)
  • cypress/e2e/taro/feedback.cy.js (1 hunks)
  • cypress/e2e/taro/index.cy.js (1 hunks)
  • cypress/e2e/taro/layout.cy.js (1 hunks)
  • cypress/e2e/taro/nav.cy.js (1 hunks)
  • package.json (3 hunks)
💤 Files with no reviewable changes (4)
  • cypress/component/Actionsheet.cy.jsx
  • cypress/component/Button.cy.jsx
  • cypress/component/Cell.cy.jsx
  • cypress/e2e/index.cy.js
🔇 Additional comments (16)
cypress.config.ts (2)

5-5: 测试文件模式更新合理

将 specPattern 更新为支持 {js,jsx,ts,tsx} 是个很好的改进:

  • 支持 TypeScript 和 JSX 文件格式
  • 符合现代 React 开发实践
  • 提供了更大的灵活性

4-6: 请确认基础URL的配置位置

baseUrl 属性的移除可能会影响测试执行。请确认:

  • 基础URL是否已在 package.json 的测试脚本中定义
  • 是否使用环境变量来管理不同环境的URL
  • H5和Taro平台的URL配置是否已妥善处理
✅ Verification successful

baseUrl配置已正确设置在package.json中

经验证,baseUrl已在package.json的测试脚本中妥善配置:

从package.json中可以看到,项目针对不同平台都有对应的测试命令:

  • H5平台: e2e:h5:run, e2e:h5:open
  • Taro平台: e2e:taro:run, e2e:taro:open

移除cypress.config.ts中的baseUrl是合理的重构,因为该配置已通过命令行参数方式传入。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查package.json中的测试脚本配置
echo "检查测试脚本配置..."
rg "cypress.*open|cypress.*run" package.json

# 检查环境配置文件
echo "检查环境配置文件..."
fd -e env -e env.local -e env.development -e env.production

Length of output: 1018

cypress/e2e/taro/index.cy.js (1)

1-7: 测试模块组织结构清晰合理!

测试文件按照功能模块进行分类,结构清晰,便于维护和扩展。

cypress/e2e/h5/layout.cy.js (1)

1-3: 测试结构设置正确

测试套件的基本结构和导入语句看起来是正确的,使用了通用的componentTest工具函数来保持测试的一致性。

cypress/e2e/h5/base.cy.js (1)

1-3: 测试套件结构正确,但需要验证工具函数的导入

测试套件的基本结构看起来不错。但是建议验证 utils.js 文件中 componentTest 函数的实现。

✅ Verification successful

Let me verify if there are any test files using this componentTest utility to understand its usage pattern.


componentTest 工具函数使用正确,但测试用例需要实现

utils.js 中的 componentTest 工具函数实现完整,它能正确设置移动设备环境并访问组件页面。该工具函数已在多个测试文件中被广泛使用,包括基础组件、导航组件、布局组件等测试套件。

建议:

  • 实现当前为空的测试回调函数 () => {}
  • 为每个组件添加基本的渲染测试和交互测试
  • 考虑添加组件特定的测试用例,验证其独特功能
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: 验证 componentTest 函数的实现
rg -A 10 "export.*componentTest" cypress/e2e/h5/

Length of output: 810


Script:

#!/bin/bash
# Find test files using componentTest
rg -B 2 -A 5 "componentTest\(" cypress/e2e/h5/

Length of output: 6620

cypress/e2e/h5/nav.cy.js (2)

1-3: 测试结构设置正确

测试套件的基本结构符合 Cypress 最佳实践,使用 componentTest 工具函数来统一测试方法。


1-12: 验证组件测试覆盖率

确保所有导航相关组件都已包含在测试中。

✅ Verification successful

Let me gather more specific information about the navigation components.


导航组件测试覆盖率已完整

根据代码库分析,当前测试文件 nav.cy.js 中已包含了所有主要导航相关组件的测试用例:

  • BackTop
  • Elevator
  • FixedNav
  • NavBar
  • SideNavBar
  • Tabbar
  • Tabs

这些测试用例与源代码中的导航组件一一对应:

  • src/packages/backtop
  • src/packages/elevator
  • src/packages/fixednav
  • src/packages/navbar
  • src/packages/sidenavbar
  • src/packages/tabbar
  • src/packages/tabs
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:检查是否所有导航组件都已包含测试用例

# 搜索 src 目录下的导航相关组件
echo "查找导航相关组件文件:"
fd -e tsx -e ts "Nav|Tab|Back|Elevator|Fixed" src/packages

# 对比已有的测试文件
echo -e "\n现有的测试文件:"
fd -e js -e ts "nav|tab|back|elevator|fixed" cypress/e2e

Length of output: 421


Script:

#!/bin/bash
# 使用 ast-grep 查找导航相关组件的定义
echo "查找导航相关组件定义:"
ast-grep --pattern 'export class $_ extends Component {
  $$$
}'

# 使用 ripgrep 搜索导航相关组件的导出
echo -e "\n查找导航相关组件导出:"
rg "export.*(?:Nav|Tab|Back|Elevator|Fixed)" -g "*.{ts,tsx}" --type ts

Length of output: 13900

cypress/e2e/h5/utils.js (1)

1-17: 建议添加类型定义和文档注释

为了提高代码的可维护性和使用体验,建议添加 TypeScript 类型定义和详细的文档注释。

+/**
+ * 组件测试工具函数
+ * @param {string} comName - 组件名称
+ * @param {Function} fn - 测试函数
+ * @param {Object} options - 配置选项
+ * @param {number} [options.delay=800] - 延迟时间(毫秒)
+ * @param {('iPhone'|'iPad'|'Android')} [options.device='iPhone'] - 设备类型
+ * @returns {void}
+ */
cypress/e2e/h5/feedback.cy.js (1)

3-20: 验证组件的存在性

需要确认列出的所有组件是否都在项目中实际存在并且可以正常访问。

✅ Verification successful

所有组件均已验证存在且可访问

通过搜索结果可以确认,所有在测试文件中列出的组件都在 src/packages 目录下有对应的实现文件,包括:

  • 每个组件都有其主要实现文件(.tsx
  • 每个组件都有对应的入口文件(index.ts
  • 每个组件都有演示文件(demo.tsx
  • 每个组件都有 Taro 版本的实现

所有16个组件(ActionSheet、Badge、Dialog、Drag、Empty、ResultPage、InfiniteLoading、Loading、NoticeBar、Notify、Popover、Popup、PullToRefresh、Skeleton、Swipe、Toast)的文件结构完整,可以放心进行测试。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:验证所有被测试组件是否存在于项目中

# 搜索组件定义
echo "正在检查组件定义..."
components=(
  "ActionSheet" "Badge" "Dialog" "Drag" "Empty" 
  "ResultPage" "InfiniteLoading" "Loading" "NoticeBar" 
  "Notify" "Popover" "Popup" "PullToRefresh" 
  "Skeleton" "Swipe" "Toast"
)

for component in "${components[@]}"; do
  echo "检查组件: $component"
  rg -l "export.*${component}.*" src/packages
done

Length of output: 6879

cypress/e2e/taro/feedback.cy.js (1)

1-22: 验证测试覆盖率

需要确保测试覆盖了组件的关键功能和边界情况。

✅ Verification successful

Let me try to search for these components with a corrected regex pattern.


Let me try another search to find the component implementations and test files:


Let me check the content of some demo files to understand the test coverage:


测试覆盖率已经足够充分

根据对组件演示文件的分析,现有的测试已经覆盖了各个组件的主要功能和边界情况:

  • Empty: 测试了标题、描述、操作按钮等不同组合
  • InfiniteLoading: 验证了加载更多、滚动事件、自定义加载文案等功能
  • Notify: 测试了基础用法、不同类型的通知、点击和关闭事件
  • Popup: 验证了显示/隐藏、内容滚动等功能
  • PullToRefresh: 测试了下拉刷新、自定义图标、加载状态等
  • Skeleton: 验证了基础骨架屏和动画效果
  • Swipe: 测试了左滑删除等滑动操作
  • Toast: 验证了文字提示、标题提示、成功/失败/警告/加载等不同类型的提示

现有的测试用例已经很好地覆盖了各个组件的核心功能,不需要额外的测试用例。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查是否有其他测试文件可能测试了这些组件
echo "搜索相关组件的其他测试文件..."
rg -t js -t ts "describe.*('(Empty|ResultPage|InfiniteLoading|Notify|Popup|PullToRefresh|Skeleton|Swipe|Toast)'" ./cypress

# 检查组件源文件以了解需要测试的关键功能
echo "检查组件源文件..."
fd -e tsx -e ts "^(Empty|ResultPage|InfiniteLoading|Notify|Popup|PullToRefresh|Skeleton|Swipe|Toast)\.(tsx|ts)$" ./src

Length of output: 704


Script:

#!/bin/bash
# Search for test files with fixed regex
echo "Searching for related component test files..."
rg -t js -t ts "describe.*['\"].*?(Empty|ResultPage|InfiniteLoading|Notify|Popup|PullToRefresh|Skeleton|Swipe|Toast)" ./cypress

# Search for component source files
echo "Searching for component implementations..."
rg -t tsx -t ts "export.*?(Empty|ResultPage|InfiniteLoading|Notify|Popup|PullToRefresh|Skeleton|Swipe|Toast)" ./src

# Look for component props and interfaces
echo "Searching for component interfaces..."
ast-grep --pattern 'interface $_ {
  $$$
}'

Length of output: 90232


Script:

#!/bin/bash
# Search for component implementations
echo "Searching for component files..."
fd -t f "^(Empty|ResultPage|InfiniteLoading|Notify|Popup|PullToRefresh|Skeleton|Swipe|Toast)\.(tsx|ts)$" ./src/packages

# Search for test files
echo "Searching for test files..."
fd -t f "^(Empty|ResultPage|InfiniteLoading|Notify|Popup|PullToRefresh|Skeleton|Swipe|Toast).*\.(spec|test)\.(tsx|ts|js)$" ./src/packages

# Search for demo files
echo "Searching for demo files..."
fd -t f "^demo.*\.(tsx|ts|js)$" ./src/packages/{empty,resultpage,infiniteloading,notify,popup,pulltorefresh,skeleton,swipe,toast}

Length of output: 5601


Script:

#!/bin/bash
# Check demo content for key components
echo "Checking Empty demos..."
cat ./src/packages/empty/demos/taro/demo1.tsx

echo "Checking InfiniteLoading demos..."
cat ./src/packages/infiniteloading/demos/taro/demo1.tsx

echo "Checking Notify demos..."
cat ./src/packages/notify/demos/taro/demo1.tsx

echo "Checking Popup demos..."
cat ./src/packages/popup/demos/taro/demo1.tsx

echo "Checking PullToRefresh demos..."
cat ./src/packages/pulltorefresh/demos/taro/demo1.tsx

echo "Checking Skeleton demos..."
cat ./src/packages/skeleton/demos/taro/demo1.tsx

echo "Checking Swipe demos..."
cat ./src/packages/swipe/demos/taro/demo1.tsx

echo "Checking Toast demos..."
cat ./src/packages/toast/demos/taro/demo1.tsx

Length of output: 10500

cypress/e2e/h5/dentry.cy.js (2)

3-25: 检查组件覆盖率是否完整

建议验证是否所有的表单类组件都已包含在测试中。例如:

  • 是否遗漏了 Password 组件?
  • 是否需要添加 Slider 组件?
  • 复合表单组件的测试是否完备?
#!/bin/bash
# 搜索可能遗漏的表单组件
echo "检查 src 目录下的表单相关组件:"
fd -e tsx -e ts --full-path "src/**/form" -x rg -l "export.*interface.*Props"

echo "检查文档中提到的表单组件:"
fd -e md --full-path "src/**/form" -x rg -l "## API"

1-1: 建议验证工具函数的导入路径

请确保 utils.js 文件中的 componentTest 函数已正确实现并导出。

✅ Verification successful

Let me try a different search pattern to locate the componentTest function.


componentTest 工具函数导入路径验证完成

utils.js 文件中已正确实现并导出了 componentTest 函数。该函数实现了以下功能:

  • 接收组件名称、测试函数和延迟时间作为参数
  • 访问指定组件的测试页面
  • 模拟移动设备环境
  • 执行测试用例

导入语句完全正确,无需修改。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 验证 utils.js 文件中的 componentTest 函数实现
rg -A 5 "export.*componentTest" ./cypress/e2e/h5/

Length of output: 362


Script:

#!/bin/bash
# Search for utils.js file and its content
fd utils.js ./cypress/e2e/h5/ -x cat {}

Length of output: 618

cypress/e2e/taro/dentry.cy.js (1)

14-14: 路径构建逻辑优化得当!

使用 Cypress.env('baseUrl') 来动态构建测试路径是一个很好的实践,这样可以轻松地在不同环境中运行测试。

.github/workflows/ci.yml (2)

Line range hint 1-82: 工作流程结构清晰,配置合理!

现有的 CI 工作流程包含了必要的检查步骤(lint、test、build),并且正确使用了 pnpm 作为包管理器。


Line range hint 83-109: 验证标签权限配置

需要确保 GITHUB_TOKEN 具有添加标签的权限,建议验证以下几点:

  1. 仓库的权限设置是否允许 GitHub Actions 管理标签
  2. 是否所有预期的标签都已在仓库中创建
✅ Verification successful

标签权限配置已验证完成,无需额外修改

验证结果显示:

  • 仓库中已存在所需的 2.x3.x 标签
  • 最近的工作流程运行记录显示 CI 工作流成功执行,没有权限相关的错误
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查仓库中是否存在所需的标签

echo "检查仓库中的现有标签..."
gh label list | grep -E "2\.x|3\.x"

echo "检查最近的工作流程运行记录中的标签添加情况..."
gh run list --workflow=ci.yml --limit 5 --json conclusion,event,headBranch

Length of output: 985

package.json (1)

165-165: 依赖配置合理,符合最佳实践

新添加的开发依赖配置恰当:

  • Cypress 作为端到端测试工具
  • simple-git 用于版本控制操作
  • start-server-and-test 用于管理测试服务器生命周期

版本控制策略允许次要版本更新,这有助于及时获取 bug 修复和新特性。

Also applies to: 220-221

cypress/e2e/h5/index.cy.js Show resolved Hide resolved
cypress/e2e/h5/layout.cy.js Show resolved Hide resolved
cypress/e2e/h5/bussiness.cy.js Show resolved Hide resolved
cypress/e2e/h5/base.cy.js Show resolved Hide resolved
cypress/e2e/h5/base.cy.js Show resolved Hide resolved
cypress/e2e/h5/exhibition.cy.js Show resolved Hide resolved
cypress/e2e/h5/exhibition.cy.js Show resolved Hide resolved
cypress/e2e/h5/dentry.cy.js Show resolved Hide resolved
cypress/e2e/taro/dentry.cy.js Show resolved Hide resolved
cypress/e2e/taro/dentry.cy.js Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (1)
package.json (1)

95-98: 建议优化 Cypress 测试脚本配置

建议对 Cypress 测试脚本进行以下优化:

  1. baseUrl 应该配置在 cypress.config.ts 中而不是命令行参数中,这样可以更好地管理环境配置
  2. spec 路径模式可以在配置文件中统一管理,避免在命令行中硬编码

建议将配置移至 cypress.config.ts:

// cypress.config.ts
export default {
  e2e: {
+   h5: {
+     baseUrl: 'http://localhost:5173/react/demo.html#/zh-CN/component/',
+     specPattern: 'cypress/e2e/h5/**/*.cy.js'
+   },
+   taro: {
+     baseUrl: 'http://localhost:10086/#/',
+     specPattern: 'cypress/e2e/taro/**/*.cy.js'
+   }
  }
}

然后简化命令:

-    "cypress:run": "cypress run --env baseUrl=http://localhost:5173/react/demo.html#/zh-CN/component/  --spec 'cypress/e2e/h5/index.cy.js'",
+    "cypress:run": "cypress run --config-file cypress.config.ts",
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 22cc2fe and 7fe0719.

📒 Files selected for processing (2)
  • .github/workflows/cypress.yml (1 hunks)
  • package.json (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/cypress.yml

package.json Outdated Show resolved Hide resolved
@Alex-huxiyang Alex-huxiyang changed the title chore: e2e test & ci test chore: e2e test & ci integration Nov 12, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (1)
.github/workflows/cypress.yml (1)

15-26: 建议固定 pnpm 版本

为了确保构建的一致性和可重现性,建议明确指定 pnpm 的版本。

建议修改如下:

 - name: Install pnpm
-  run: corepack enable pnpm
+  run: corepack enable && corepack prepare [email protected] --activate
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 75d817a and e821c24.

📒 Files selected for processing (1)
  • .github/workflows/cypress.yml (1 hunks)
🧰 Additional context used
🪛 actionlint
.github/workflows/cypress.yml

27-27: the runner of "actions/checkout@v2" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

🔇 Additional comments (2)
.github/workflows/cypress.yml (2)

1-10: 工作流触发配置正确!

工作流程的名称和触发条件配置合理,可以确保在适当的时机执行端到端测试。


11-14: 作业配置合理!

使用最新版本的 Ubuntu 运行器是一个好的选择,可以确保测试环境的稳定性和兼容性。

.github/workflows/cypress.yml Outdated Show resolved Hide resolved
.github/workflows/cypress.yml Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (2)
.github/workflows/cypress.yml (2)

1-10: 建议添加手动触发选项

建议添加 workflow_dispatch 事件以支持手动触发工作流,这对调试和按需运行测试很有帮助。

 on:
+  workflow_dispatch:
   push:
     branches:
       - V3.0

15-26: 建议优化依赖缓存策略

当前的缓存配置可以通过以下方式优化:

  1. 添加 Cypress 二进制文件的缓存
  2. 为 pnpm 存储添加哈希锁定
       - uses: actions/setup-node@v4
         with:
           node-version: '20'
-          cache: 'pnpm'
+          cache: 'pnpm'
+          cache-dependency-path: '**/pnpm-lock.yaml'
+
+      - name: Cache Cypress Binary
+        uses: actions/cache@v4
+        with:
+          path: ~/.cache/Cypress
+          key: cypress-binary-${{ hashFiles('**/cypress.json') }}
+          restore-keys: |
+            cypress-binary-
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between eeefcbc and 0cfaf5c.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (1)
  • .github/workflows/cypress.yml (1 hunks)
🧰 Additional context used
🪛 yamllint
.github/workflows/cypress.yml

[error] 31-31: trailing spaces

(trailing-spaces)

🔇 Additional comments (1)
.github/workflows/cypress.yml (1)

11-14: 配置正确

作业配置简洁明了,使用最新的 Ubuntu 运行器是个好选择。

.github/workflows/cypress.yml Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 6207bf7 and d508760.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (1)
  • package.json (3 hunks)
🔇 Additional comments (2)
package.json (2)

99-102: H5 测试启动策略问题仍然存在

之前的评审意见仍然有效,建议统一使用 start-server-and-test 来管理所有 E2E 测试。


165-165: 依赖项配置问题仍然存在

之前的评审意见仍然有效,建议:

  1. 将 Cypress 移至 devDependencies
  2. 锁定依赖版本号

Also applies to: 219-220

package.json Outdated
Comment on lines 95 to 98
"cypress:run": "cypress run --env baseUrl=http://localhost:5173/react/demo.html#/zh-CN/component/ --spec 'cypress/e2e/h5/index.cy.js'",
"cypress:open": "cypress open --env baseUrl=http://localhost:5173/react/demo.html#/zh-CN/component/ --spec 'cypress/e2e/h5/index.cy.js'",
"cypress:run:taro": "cypress run --env baseUrl=http://localhost:10086/#/ --spec 'cypress/e2e/taro/index.cy.js'",
"cypress:open:taro": "cypress open --env baseUrl=http://localhost:10086/#/ --spec 'cypress/e2e/taro/index.cy.js'",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

建议优化 Cypress 配置管理

建议将 baseUrl 和 spec 路径配置移至 cypress.config.ts 中,以提高可维护性:

- "cypress:run": "cypress run --env baseUrl=http://localhost:5173/react/demo.html#/zh-CN/component/  --spec 'cypress/e2e/h5/index.cy.js'",
- "cypress:open": "cypress open --env baseUrl=http://localhost:5173/react/demo.html#/zh-CN/component/  --spec 'cypress/e2e/h5/index.cy.js'",
- "cypress:run:taro": "cypress run --env baseUrl=http://localhost:10086/#/ --spec 'cypress/e2e/taro/index.cy.js'",
- "cypress:open:taro": "cypress open --env baseUrl=http://localhost:10086/#/ --spec 'cypress/e2e/taro/index.cy.js'",
+ "cypress:run": "cypress run --config-file cypress.h5.config.ts",
+ "cypress:open": "cypress open --config-file cypress.h5.config.ts",
+ "cypress:run:taro": "cypress run --config-file cypress.taro.config.ts",
+ "cypress:open:taro": "cypress open --config-file cypress.taro.config.ts",

Committable suggestion skipped: line range outside the PR's diff.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 051f657 and 72d467f.

📒 Files selected for processing (1)
  • package.json (3 hunks)
🔇 Additional comments (1)
package.json (1)

94-97: Cypress 配置需要优化

建议将配置移至 cypress.config.ts 文件中,以提高可维护性和配置的集中管理。

package.json Outdated
@@ -155,9 +161,9 @@
"@vitest/ui": "^2.0.4",
"autoprefixer": "^10.4.17",
"axios": "^1.6.7",
"cypress": "^13.15.2",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

依赖项配置需要调整

存在以下问题:

  1. Cypress 应该放在 devDependencies
  2. 依赖项版本应该严格锁定,避免意外升级

建议修改如下:

-  "dependencies": {
-    "cypress": "^13.15.2",
-  },
   "devDependencies": {
+    "cypress": "13.15.2",
-    "simple-git": "^3.25.0",
+    "simple-git": "3.25.0",
-    "start-server-and-test": "^2.0.4",
+    "start-server-and-test": "2.0.4",
   }

Also applies to: 218-219

package.json Outdated
Comment on lines 98 to 101
"e2e:run:h5": "pnpm dev & pnpm cypress:run",
"e2e:open:h5": "pnpm dev & pnpm cypress:open",
"e2e:run:taro": "start-server-and-test dev:taro:h5 http://localhost:10086 cypress:run:taro",
"e2e:open:taro": "start-server-and-test dev:taro:h5 http://localhost:10086 cypress:open:taro",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

E2E 测试启动策略需要统一

  1. H5 测试使用 & 运行服务器存在进程管理风险
  2. H5 和 Taro 平台使用了不同的启动策略,建议统一使用 start-server-and-test

建议修改如下:

-    "e2e:run:h5": "pnpm dev & pnpm cypress:run",
-    "e2e:open:h5": "pnpm dev & pnpm cypress:open",
+    "e2e:run:h5": "start-server-and-test dev http://localhost:5173 cypress:run",
+    "e2e:open:h5": "start-server-and-test dev http://localhost:5173 cypress:open",
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"e2e:run:h5": "pnpm dev & pnpm cypress:run",
"e2e:open:h5": "pnpm dev & pnpm cypress:open",
"e2e:run:taro": "start-server-and-test dev:taro:h5 http://localhost:10086 cypress:run:taro",
"e2e:open:taro": "start-server-and-test dev:taro:h5 http://localhost:10086 cypress:open:taro",
"e2e:run:h5": "start-server-and-test dev http://localhost:5173 cypress:run",
"e2e:open:h5": "start-server-and-test dev http://localhost:5173 cypress:open",
"e2e:run:taro": "start-server-and-test dev:taro:h5 http://localhost:10086 cypress:run:taro",
"e2e:open:taro": "start-server-and-test dev:taro:h5 http://localhost:10086 cypress:open:taro",

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 72d467f and 5667f45.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (1)
  • package.json (3 hunks)
🔇 Additional comments (2)
package.json (2)

98-101: ⚠️ Potential issue

统一 E2E 测试的启动策略

当前存在以下问题:

  1. H5 测试使用 & 运行服务器,可能导致进程管理问题
  2. H5 和 Taro 平台使用了不同的启动策略

建议统一使用 start-server-and-test

- "e2e:run:h5": "pnpm dev & pnpm cypress:run",
- "e2e:open:h5": "pnpm dev & pnpm cypress:open",
+ "e2e:run:h5": "start-server-and-test dev http://localhost:5173 cypress:run",
+ "e2e:open:h5": "start-server-and-test dev http://localhost:5173 cypress:open",

Likely invalid or redundant comment.


94-97: 🛠️ Refactor suggestion

建议将 Cypress 配置移至配置文件

建议将硬编码的配置项移至 cypress.config.ts 中:

- "cypress:run": "cypress run --env baseUrl=http://localhost:5173/react/demo.html#/zh-CN/component/  --spec 'cypress/e2e/h5/index.cy.js'",
- "cypress:open": "cypress open --env baseUrl=http://localhost:5173/react/demo.html#/zh-CN/component/  --spec 'cypress/e2e/h5/index.cy.js'",
- "cypress:run:taro": "cypress run --env baseUrl=http://localhost:10086/#/ --spec 'cypress/e2e/taro/index.cy.js'",
- "cypress:open:taro": "cypress open --env baseUrl=http://localhost:10086/#/ --spec 'cypress/e2e/taro/index.cy.js'",
+ "cypress:run": "cypress run --config-file cypress.h5.config.ts",
+ "cypress:open": "cypress open --config-file cypress.h5.config.ts",
+ "cypress:run:taro": "cypress run --config-file cypress.taro.config.ts",
+ "cypress:open:taro": "cypress open --config-file cypress.taro.config.ts"

这样可以:

  1. 提高配置的可维护性
  2. 避免重复配置
  3. 便于管理不同环境的配置

Likely invalid or redundant comment.

package.json Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant