Skip to content

feat(e2e): add Playwright configuration and initial tests#675

Merged
zds-s merged 1 commit into
mineadmin:masterfrom
people-sea:feature/web/e2e/init
Aug 2, 2025
Merged

feat(e2e): add Playwright configuration and initial tests#675
zds-s merged 1 commit into
mineadmin:masterfrom
people-sea:feature/web/e2e/init

Conversation

@people-sea

@people-sea people-sea commented Aug 2, 2025

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • 新功能
    • 集成了 Playwright 端到端测试框架,新增了相关配置和示例测试用例。
    • 新增 npm 脚本支持一键运行端到端测试。
  • 杂项
    • 更新 .gitignore,忽略端到端测试输出目录。
    • 更新 TypeScript 配置,完善对 Node.js 类型和测试配置文件的支持。

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Aug 2, 2025
@coderabbitai

coderabbitai Bot commented Aug 2, 2025

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

本次变更为 web 项目引入了 Playwright 端到端测试支持。主要包括添加 Playwright 配置文件、测试样例、相关依赖与脚本,以及相应的 TypeScript 配置和 .gitignore 规则调整。

Changes

Cohort / File(s) Change Summary
Playwright 测试配置与样例
web/playwright.config.ts, web/tests/e2e/example.spec.ts
新增 Playwright 测试配置文件和端到端测试样例,配置测试目录、输出、并实现基础页面导航与内容断言。
依赖与脚本配置
web/package.json
增加 Playwright 及 Node 类型依赖,新增 test:e2e 脚本,格式化脚本部分。
TypeScript 配置
web/tsconfig.node.json
增加 Node 类型定义,确保 Playwright 配置文件被包含在编译范围内。
Git 忽略规则
web/.gitignore
忽略 tests/e2e/.output/ 目录下所有内容,避免测试输出被纳入版本控制。

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant Playwright CLI
    participant Local Dev Server
    participant Browser

    Developer->>Playwright CLI: 运行 npm run test:e2e
    Playwright CLI->>Local Dev Server: 启动本地开发服务器
    Playwright CLI->>Browser: 启动浏览器实例
    Browser->>Playwright CLI: 执行测试用例
    Playwright CLI->>Local Dev Server: 关闭服务器(测试结束)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested labels

lgtm

Suggested reviewers

  • kanyxmo
  • zds-s

Poem

小兔子敲代码,
Playwright 新登场。
测试脚本齐上阵,
浏览器中跳一场。
端到端全覆盖,
项目质量更闪亮! 🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this 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 or PR title anywhere in the PR title to generate the title automatically.

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.

@dosubot dosubot Bot added the enhancement label Aug 2, 2025
@people-sea
people-sea requested a review from zds-s August 2, 2025 11:06
Comment thread web/package.json

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
web/tests/e2e/example.spec.ts (2)

1-8: 测试结构正确,但建议测试实际应用。

测试使用了正确的 Playwright API 和最佳实践,包括角色选择器和适当的断言。但建议将测试目标从外部网站改为实际的应用程序,以避免外部依赖导致的不稳定性。

考虑将测试修改为:

-  await page.goto('https://playwright.dev/')
+  await page.goto('/')
-  await expect(page).toHaveTitle(/Playwright/)
+  await expect(page).toHaveTitle(/MineAdmin/)

10-18: 导航测试实现良好,建议调整为实际应用场景。

使用角色选择器进行导航测试是很好的做法,但建议将测试场景调整为实际应用的功能点。

建议修改为测试实际应用的导航:

-  await page.goto('https://playwright.dev/')
-  await page.getByRole('link', { name: 'Get started' }).click()
-  await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible()
+  await page.goto('/')
+  await page.getByRole('link', { name: '实际的导航链接' }).click()
+  await expect(page.getByRole('heading', { name: '实际的页面标题' })).toBeVisible()
web/playwright.config.ts (2)

37-37: 建议将端口配置设为可配置项。

硬编码的端口 2888 可能与其他服务冲突,建议使用环境变量或配置文件来管理。

-    baseURL: 'http://localhost:2888',
+    baseURL: process.env.BASE_URL || 'http://localhost:2888',

47-82: 考虑启用多浏览器测试以提高覆盖率。

当前仅启用了 Chromium 测试,建议至少启用 Firefox 以捕获跨浏览器兼容性问题。

考虑取消注释 Firefox 配置:

-    // {
-    //   name: 'firefox',
-    //   use: { ...devices['Desktop Firefox'] },
-    // },
+    {
+      name: 'firefox',
+      use: { ...devices['Desktop Firefox'] },
+    },
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 723c15c and cae7858.

📒 Files selected for processing (5)
  • web/.gitignore (1 hunks)
  • web/package.json (2 hunks)
  • web/playwright.config.ts (1 hunks)
  • web/tests/e2e/example.spec.ts (1 hunks)
  • web/tsconfig.node.json (1 hunks)
🔇 Additional comments (10)
web/.gitignore (1)

12-12: LGTM!正确添加了测试输出目录的忽略规则。

这个忽略规则与 playwright.config.ts 中的 OUTPUT_DIR 配置保持一致,遵循了不将测试报告和生成文件提交到版本控制的最佳实践。

web/tsconfig.node.json (2)

8-10: LGTM!正确添加了 Node.js 类型支持。

添加 Node.js 类型定义支持 Playwright 配置文件中使用的 Node.js API,与新增的 @types/node 依赖保持一致。


16-16: LGTM!正确包含了 Playwright 配置文件。

playwright.config.ts 添加到编译上下文中,确保配置文件获得适当的类型检查和 IntelliSense 支持。

web/package.json (2)

19-19: E2E 测试脚本配置正确。

脚本正确引用了 Playwright 配置文件,命令格式符合最佳实践。


62-62: 确认 Playwright 和 Node 类型依赖版本及安全性

  • web/package.json 第 62 行:@playwright/test 使用 ^1.54.2,与最新稳定版 1.54.2 一致
  • web/package.json 第 66 行:@types/node 与最新稳定版 24.1.0 一致
  • 运行 npm audit --only=dev 未报告与 Playwright 或 @types/node 相关的安全漏洞
web/playwright.config.ts (5)

12-13: LGTM!目录结构配置清晰。

输出目录的配置结构清晰,与 .gitignore 规则保持一致。


18-33: 测试配置遵循最佳实践。

配置正确处理了 CI 环境检测、并行执行、重试策略和报告生成,遵循了 Playwright 的最佳实践。


35-44: 调试和跟踪配置合理。

跟踪和截图配置有助于调试失败的测试,视频录制被注释掉是合理的选择以节省存储空间。


84-90: Web 服务器配置正确。

开发服务器配置与 baseURL 保持一致,CI 环境下禁用服务器重用是正确的做法。


86-87: 开发服务器命令和端口已验证一致

已确认:

  • pnpm run dev 会调用 vite 启动开发服务器;
  • web/.env.developmentweb/.env.production 中均有 VITE_APP_PORT = 2888
  • vite.config.ts 中通过 server.port = Number(env.VITE_APP_PORT …) 使用了该端口。

因此,Playwright 配置中的

command: 'pnpm run dev',
url: 'http://localhost:2888',

与实际启动端口完全匹配,无需修改。

@people-sea people-sea closed this Aug 2, 2025
@people-sea people-sea reopened this Aug 2, 2025
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Aug 2, 2025
@zds-s
zds-s enabled auto-merge (squash) August 2, 2025 11:32
@zds-s
zds-s disabled auto-merge August 2, 2025 11:32
@zds-s
zds-s merged commit a0694fd into mineadmin:master Aug 2, 2025
5 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Sep 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Frontend lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants