Skip to content

Migrate tests from Jest + jest-electron to Playwright (Chromium only)#26

Closed
Copilot wants to merge 5 commits into
masterfrom
copilot/migrate-tests-to-playwright
Closed

Migrate tests from Jest + jest-electron to Playwright (Chromium only)#26
Copilot wants to merge 5 commits into
masterfrom
copilot/migrate-tests-to-playwright

Conversation

Copilot AI commented Jan 24, 2026

Copy link
Copy Markdown
Contributor

Migration Plan: Jest + jest-electron → Playwright (Chromium only)

Related Issue: #23

Checklist:

  • 1. Install Playwright dependencies
    • Add @playwright/test as devDependency
    • Remove jest, jest-electron, and babel-jest from package.json
  • 2. Update package.json scripts
    • Change test script to use Playwright
    • Remove debug script (Jest-specific)
    • Remove jest configuration block
  • 3. Create Playwright configuration
    • Add playwright.config.mjs with Chromium-only project
    • Configure testDir to use tests/ directory
    • Set up headless mode for CI
    • Use .mjs extension for ES module support
  • 4. Migrate test files from tests/ to tests/
  • 5. Update GitHub Actions workflow
    • Add Playwright browser installation step before tests
    • Keep existing workflow structure intact
  • 6. Verify everything works
    • Build process verified
    • Old tests directory removed
    • Fixed CI error (ES module support)
    • Added package-lock.json to .gitignore

Decision: Running Chromium only to keep the setup lightweight and fast, while still providing browser-based DOM testing that was previously done with jest-electron.

Technical Approach:

  • Tests load the pre-built UMD bundle (dist/size-sensor.min.js) into Playwright pages
  • DOM manipulation and assertions run in browser context via page.evaluate()
  • Tests maintain the same coverage as original Jest tests
  • Using .mjs extension for proper ES module support in Node.js
Original prompt

在仓库 hustcc/size-sensor 基于 master 创建一个 PR,将测试从 jest + jest-electron 迁移到 Playwright(只跑 Chromium),并尽量保持修改精准。

上下文:

需求与改动范围:

  1. 替换测试框架:移除 jestjest-electronbabel-jest,新增 @playwright/test
  2. 更新 package.json scripts:将 npm test 改为运行 Playwright(例如 playwright test),并确保 CI 继续使用 npm test 即可。
  3. 新增 Playwright 配置:
    • 配置只运行 Chromium(单 project),CI 模式下可使用 headless。
    • 选择合理的 testDir(例如 tests/),并匹配现有用例。
  4. 迁移测试用例:将 __tests__/ 下三个用例迁移到 Playwright:
    • 保留原测试意图与断言(export/ver、bind/clear/unbind、只调用 unbind 不调用 clear 的话存在内存泄漏 #17 memory leak)。
    • 在浏览器环境中执行 DOM 操作与 getComputedStyle(通过 page.setContent + page.evaluate 等方式)。
    • 尽量不改动库源码;如必须加载库代码到浏览器,可采用最小方案(例如直接在测试里注入 src 代码的 bundle,或在测试前构建 dist 并注入)。
  5. 更新 GitHub Actions(如必要):
    • 增加 Playwright 浏览器安装步骤(例如 npx playwright install --with-deps chromium),确保在 macOS runner 上能跑。
    • 尽量保持 workflow 其余部分不变。
  6. PR 说明:在 PR 描述中关联 issue #23,并说明只跑 Chromium 的决定。

验收标准:

  • npm test 在本地/CI 可运行并通过。
  • 不再依赖 jest/jest-electron。
  • Playwright 测试覆盖原 3 个 spec 的核心断言。
  • Playwright 配置只跑 Chromium。

This pull request was created from Copilot chat.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits January 24, 2026 12:35
Co-authored-by: hustcc <7856674+hustcc@users.noreply.github.com>
Co-authored-by: hustcc <7856674+hustcc@users.noreply.github.com>
Co-authored-by: hustcc <7856674+hustcc@users.noreply.github.com>
@hustcc

hustcc commented Jan 24, 2026

Copy link
Copy Markdown
Owner

@copilot ci 执行报错了处理一下。

另外把 lock 文件 git ignore

Copilot AI changed the title [WIP] Migrate tests from Jest to Playwright for Chromium Migrate tests from Jest + jest-electron to Playwright (Chromium only) Jan 24, 2026
Copilot AI requested a review from hustcc January 24, 2026 12:42
Co-authored-by: hustcc <7856674+hustcc@users.noreply.github.com>

Copilot AI commented Jan 24, 2026

Copy link
Copy Markdown
Contributor Author

@copilot ci 执行报错了处理一下。

另外把 lock 文件 git ignore

Fixed in commit a9d5bb1:

  1. CI Error: Renamed config and test files from .js to .mjs to properly support ES modules in Node.js
  2. package-lock.json: Added to .gitignore and removed from git tracking

The ES module error was caused by using import syntax in .js files without Node.js knowing they're ES modules. Using .mjs extension tells Node.js to treat them as ES modules directly.

@hustcc hustcc closed this Jan 24, 2026
@hustcc hustcc deleted the copilot/migrate-tests-to-playwright branch January 24, 2026 12:47
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.

2 participants