Skip to content

✅ 添加 Playwright E2E 测试及 GM API 功能测试#1283

Merged
CodFrm merged 4 commits intomainfrom
e2e-tests
Mar 12, 2026
Merged

✅ 添加 Playwright E2E 测试及 GM API 功能测试#1283
CodFrm merged 4 commits intomainfrom
e2e-tests

Conversation

@CodFrm
Copy link
Member

@CodFrm CodFrm commented Mar 12, 2026

Summary

  • 添加 Playwright E2E 测试框架,覆盖 Options、Popup、Script Editor、Install、Settings、Script Management 等页面
  • 新增 GM API 功能测试:GM_ 同步 API (29项)、GM.* 异步 API (29项)、Content 注入测试 (11项)
  • 两阶段浏览器启动机制启用 chrome.userScripts API,自动审批权限确认弹窗

主要改动

  • e2e/gm-api.spec.ts: GM API 完整 E2E 测试,安装 example/tests 下的测试脚本并验证通过率
  • e2e/utils.ts: 工具函数,包含 installScriptByCode 通过 Monaco 编辑器安装脚本
  • e2e/fixtures.ts, e2e/options.spec.ts 等: 基础 E2E 测试
  • vitest.config.ts: 排除 e2e/ 目录避免 Vitest 误跑 Playwright 测试
  • eslint.config.mjs: 为 e2e/ 目录关闭 react-hooks/rules-of-hooks

Test plan

  • pnpm run test 37 files, 781 tests passed
  • pnpm run lint 0 errors
  • pnpm run typecheck passed
  • npx playwright test 25 tests passed (1.5m)

CodFrm added 4 commits March 12, 2026 11:33
- 新增 22 个 E2E 测试覆盖 Options、Popup、Install、Editor、Settings 页面
- 配置 Playwright 使用 --headless=new 模式加载扩展
- 在 CI workflow 中添加 E2E 测试 job
新增 gm-api.spec.ts 测试三类 GM API:
- GM_ 同步 API (gm_api_test.js): 29 项测试
- GM.* 异步 API (gm_api_async_test.js): 29 项测试
- Content 注入测试 (inject_content_test.js): 11 项测试

实现要点:
- 两阶段浏览器启动:Phase 1 启用 userScriptsAccess,Phase 2 重启运行测试
- 自动审批权限确认弹窗(cookie 等需要用户授权的 API)
- 通过剪贴板注入脚本代码到 Monaco 编辑器
- 替换 jsdelivr CDN 为 unpkg 提升资源加载速度
- 去除 @require/@resource 的 SRI hash 避免校验失败

更新 utils.ts 中 installScriptByCode 增加保存失败的 fallback 检测
- Phase 1 添加 --headless=new 参数,修复 CI 无 X server 环境
- 添加 eslint-disable 注释消除 Playwright use() 的误报
- prettier 格式化修正
- vitest.config.ts: 排除 e2e/ 目录避免 Vitest 误跑 Playwright 测试
- eslint.config.mjs: 为 e2e/ 目录关闭 react-hooks/rules-of-hooks 规则
- e2e/options.spec.ts: 菜单正则加 /i 标志修复英文环境大小写匹配
- prettier 格式化修正
@CodFrm CodFrm merged commit 5d5c3d9 into main Mar 12, 2026
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant