Skip to content

test(web): standardize frontend tests on Vitest - #6569

Merged
seefs001 merged 9 commits into
mainfrom
test/frontend-vitest-migration
Aug 15, 2026
Merged

seefs001 merged 9 commits into
mainfrom
test/frontend-vitest-migration

Conversation

@QuentinHsu

@QuentinHsu QuentinHsu commented Jul 31, 2026 •

Copy link
Copy Markdown
Collaborator

⚠️ 提交说明 / PR Notice

Important

  • 请提供人工撰写的简洁摘要,避免直接粘贴未经整理的 AI 输出。

📝 变更描述 / Description

(简述:做了什么?为什么这样改能生效?请基于你对代码逻辑的理解来写,避免粘贴未经整理的内容)

概述

  • 将前端测试运行器统一迁移至 Vitest。

改动说明

  • 新增 Vitest、jsdom 和 React Testing Library 配置及测试脚本。
  • 将现有 node:test 测试迁移至 Vitest。
  • 使用 React Testing Library 重写 JsonCodeEditor 组件测试,并移除 happy-dom 直接依赖。

测试说明

  • 更新测试环境初始化、TypeScript 配置与依赖锁文件。

🚀 变更类型 / Type of change

  • 🐛 Bug 修复 (Bug fix) - 请关联对应 Issue,避免将设计取舍、理解偏差或预期不一致直接归类为 bug
  • ✨ 新功能 (New feature) - 重大特性建议先通过 Issue 沟通
  • ⚡ 性能优化 / 重构 (Refactor)
  • 📝 文档更新 (Documentation)

🔗 关联任务 / Related Issue

  • Closes # (如有)

✅ 提交前检查项 / Checklist

  • 人工确认: 我已亲自整理并撰写此描述,没有直接粘贴未经处理的 AI 输出。
  • 非重复提交: 我已搜索现有的 Issues 与 PRs,确认不是重复提交。
  • Bug fix 说明: 若此 PR 标记为 Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。
  • 变更理解: 我已理解这些更改的工作原理及可能影响。
  • 范围聚焦: 本 PR 未包含任何与当前任务无关的代码改动。
  • 本地验证: 已在本地运行并通过测试或手动验证,维护者可以据此复核结果。
  • 安全合规: 代码中无敏感凭据,且符合项目代码规范。

📸 运行证明 / Proof of Work

(请在此粘贴截图、关键日志或测试报告,以证明变更生效)

Summary by CodeRabbit

  • Tests
    • Migrated the web test suite to Vitest and Testing Library.
    • Expanded coverage for JSON editing, form validation, accessibility, user interactions, authentication, payments, and dashboard behavior.
    • Added a browser-like test environment with automated cleanup and common browser API support.
  • Chores
    • Added test and watch commands for local development.
    • Standardized test configuration and execution across the web application.
    • Updated continuous integration to use the project’s test command.

- configure Vitest, jsdom, and React Testing Library with shared test scripts.
- migrate existing node:test suites to the Vitest runner.
- rewrite JsonCodeEditor component tests with RTL and remove the direct happy-dom dependency.
# Conflicts:
#	web/src/features/profile/components/login-session-utils.test.ts
@coderabbitai

coderabbitai Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8f6b7590-c60e-4464-bad6-9a877cf3d911

📥 Commits

Reviewing files that changed from the base of the PR and between 206d8fb and 874e9eb.

📒 Files selected for processing (1)
  • web/package.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • web/package.json

Walkthrough

The web test infrastructure now uses Vitest with jsdom and React Testing Library. Shared setup provides DOM matchers, cleanup, translations, and browser API polyfills. Existing tests now use Vitest APIs.

Changes

Vitest test infrastructure

Layer / File(s) Summary
Vitest configuration and environment
web/package.json, web/vitest.config.ts, web/src/test-setup.ts, web/tsconfig.node.json, .github/workflows/ci.yml
Added Vitest scripts, dependencies, jsdom configuration, shared setup, browser API polyfills, TypeScript inclusion, and CI wiring.
Component test migration
web/src/components/json-code-editor/__tests__/*, web/src/features/system-settings/models/__tests__/tool-price-validation.test.tsx, web/src/features/usage-logs/components/__tests__/cost-display.test.tsx, web/src/features/keys/components/__tests__/*
Replaced manual DOM and React harnesses with Vitest and Testing Library. Preserved and expanded accessibility, form, validation, cost display, and Auto-group coverage.
Existing suite assertion migration
web/src/components/*, web/src/features/auth/*, web/src/features/channels/*, web/src/features/dashboard/*, web/src/features/playground/*, web/src/features/profile/*, web/src/features/usage-logs/lib/*, web/src/features/wallet/*, web/src/lib/*
Changed Node test and assertion APIs to Vitest APIs. Existing test behavior and coverage remain unchanged.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Merge Risk: ⚪ Minimal · up to 874e9

This PR standardizes frontend tests on Vitest without any supplied evidence of a concrete correctness, runtime, deployment, or production-impact risk, so it is merge-ready after normal checks and review.

Poem

A rabbit runs Vitest with care,
jsdom tests hop through the air.
Queries find each labeled role,
Matchers check the expected goal.
Green results fill the burrow.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: standardizing frontend tests on Vitest.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/frontend-vitest-migration

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

Comment @coderabbitai help to get the list of available commands.

- invoke the configured Vitest script so browser test setup loads in CI.
- migrate remaining node:test suites to Vitest lifecycle APIs.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@web/src/features/usage-logs/components/__tests__/cost-display.test.tsx`:
- Line 20: Remove the stale happy-dom Window imports and fixtures from
cost-display.test.tsx at lines 20-20 and 108-108, and from
tool-price-validation.test.tsx at lines 20-20 and 89-89; retain the existing
jsdom-based test behavior and cleanup.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3be0a2ad-0b5d-4b13-8b61-e1d1bb0a43bb

📥 Commits

Reviewing files that changed from the base of the PR and between 1eee799 and 6a137e0.

📒 Files selected for processing (7)
  • .github/workflows/ci.yml
  • web/src/features/auth/lib/__tests__/oauth-callback-mode.test.ts
  • web/src/features/channels/lib/__tests__/new-api-channel.test.ts
  • web/src/features/profile/components/__tests__/login-session-utils.test.ts
  • web/src/features/system-settings/models/__tests__/tool-price-validation.test.tsx
  • web/src/features/usage-logs/components/__tests__/cost-display.test.tsx
  • web/src/features/usage-logs/lib/__tests__/tool-surcharge.test.ts

@coderabbitai coderabbitai Bot mentioned this pull request Aug 2, 2026
8 of 11 tasks
- migrate usage cost and tool price tests to React Testing Library.
- remove duplicate happy-dom globals and rely on the configured Vitest setup.
- replace Node test assertions with Vitest expect across frontend suites.
- migrate Keys component tests to React Testing Library interactions.
- centralize jsdom browser mocks for consistent component execution.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
web/src/features/keys/components/__tests__/api-key-group-combobox.test.tsx (1)

22-36: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Restore window.matchMedia after each test.

These lines replace a global browser API. The replacement remains installed after this suite. A failed test can also leave shouldReduceMotion enabled.

Install the mock in beforeEach. Restore the original window.matchMedia and reset shouldReduceMotion in afterEach.

As per coding guidelines, “each test independently initializes and cleans global state, caches, localStorage, mock, and timers.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@web/src/features/keys/components/__tests__/api-key-group-combobox.test.tsx`
around lines 22 - 36, Update the reduced-motion test setup around
shouldReduceMotion and window.matchMedia so each test installs the mock in
beforeEach, while afterEach restores the original window.matchMedia and resets
shouldReduceMotion to false. Preserve the existing matchMedia behavior and
change-event dispatch.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@web/src/features/keys/components/__tests__/api-key-group-combobox.test.tsx`:
- Around line 22-36: Update the reduced-motion test setup around
shouldReduceMotion and window.matchMedia so each test installs the mock in
beforeEach, while afterEach restores the original window.matchMedia and resets
shouldReduceMotion to false. Preserve the existing matchMedia behavior and
change-event dispatch.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f7fac9c0-4deb-41d3-83ff-1bb6c29854d7

📥 Commits

Reviewing files that changed from the base of the PR and between 976fe5c and 206d8fb.

📒 Files selected for processing (28)
  • web/src/components/json-code-editor/__tests__/json-code-editor-utils.test.ts
  • web/src/components/model-group-selector/__tests__/layout.test.ts
  • web/src/components/ui/dropdown-menu.test.tsx
  • web/src/features/auth/api.test.ts
  • web/src/features/auth/lib/__tests__/oauth-callback-mode.test.ts
  • web/src/features/auth/lib/auth-redirect.test.ts
  • web/src/features/auth/lib/oauth-bind-window.test.ts
  • web/src/features/auth/lib/telegram-login.test.ts
  • web/src/features/channels/lib/__tests__/channel-field-update.test.ts
  • web/src/features/channels/lib/__tests__/channel-table-row-id.test.ts
  • web/src/features/channels/lib/__tests__/new-api-channel.test.ts
  • web/src/features/dashboard/lib/flow-selection.test.ts
  • web/src/features/dashboard/lib/flow.test.ts
  • web/src/features/keys/components/__tests__/api-key-group-cell.test.tsx
  • web/src/features/keys/components/__tests__/api-key-group-combobox.test.tsx
  • web/src/features/keys/components/__tests__/api-keys-mutate-drawer.test.tsx
  • web/src/features/keys/components/__tests__/auto-group-order-editor.test.tsx
  • web/src/features/keys/lib/__tests__/auto-group-form.test.ts
  • web/src/features/playground/hooks/use-stream-request.test.ts
  • web/src/features/profile/components/__tests__/login-session-utils.test.ts
  • web/src/features/system-settings/models/__tests__/group-auto-limit-validation.test.ts
  • web/src/features/usage-logs/lib/__tests__/tool-surcharge.test.ts
  • web/src/features/wallet/hooks/use-payment.test.ts
  • web/src/features/wallet/lib/payment.test.ts
  • web/src/lib/auth-session.test.ts
  • web/src/lib/legacy-route.test.ts
  • web/src/lib/server-error-message.test.ts
  • web/src/test-setup.ts
🚧 Files skipped from review as they are similar to previous changes (17)
  • web/src/lib/server-error-message.test.ts
  • web/src/features/wallet/hooks/use-payment.test.ts
  • web/src/test-setup.ts
  • web/src/components/json-code-editor/tests/json-code-editor-utils.test.ts
  • web/src/components/ui/dropdown-menu.test.tsx
  • web/src/features/playground/hooks/use-stream-request.test.ts
  • web/src/features/channels/lib/tests/channel-table-row-id.test.ts
  • web/src/features/channels/lib/tests/new-api-channel.test.ts
  • web/src/lib/legacy-route.test.ts
  • web/src/features/auth/api.test.ts
  • web/src/features/channels/lib/tests/channel-field-update.test.ts
  • web/src/lib/auth-session.test.ts
  • web/src/features/profile/components/tests/login-session-utils.test.ts
  • web/src/features/wallet/lib/payment.test.ts
  • web/src/features/auth/lib/auth-redirect.test.ts
  • web/src/features/auth/lib/tests/oauth-callback-mode.test.ts
  • web/src/components/model-group-selector/tests/layout.test.ts

- sync dompurify 3.4.13 metadata into the Bun lockfile.
- replace the bun:test and happy-dom redemption harness with Vitest and RTL.
- preserve quota conversion, error feedback, and stale-response coverage in jsdom.
@seefs001
seefs001 merged commit e2c7aa7 into main Aug 15, 2026
2 checks passed
@QuentinHsu
QuentinHsu deleted the test/frontend-vitest-migration branch August 15, 2026 06:19
0401lucky pushed a commit to 0401lucky/new-api that referenced this pull request Aug 16, 2026
* test(web): standardize frontend tests on Vitest

- configure Vitest, jsdom, and React Testing Library with shared test scripts.
- migrate existing node:test suites to the Vitest runner.
- rewrite JsonCodeEditor component tests with RTL and remove the direct happy-dom dependency.

* fix(ci): run frontend tests with Vitest

- invoke the configured Vitest script so browser test setup loads in CI.
- migrate remaining node:test suites to Vitest lifecycle APIs.

* test(web): use shared jsdom environment for component tests

- migrate usage cost and tool price tests to React Testing Library.
- remove duplicate happy-dom globals and rely on the configured Vitest setup.

* test(web): verify behavior with shared vitest setup

- replace Node test assertions with Vitest expect across frontend suites.
- migrate Keys component tests to React Testing Library interactions.
- centralize jsdom browser mocks for consistent component execution.

* fix(web): unblock frozen installs and Vitest CI

- sync dompurify 3.4.13 metadata into the Bun lockfile.
- replace the bun:test and happy-dom redemption harness with Vitest and RTL.
- preserve quota conversion, error feedback, and stale-response coverage in jsdom.
jerzygao pushed a commit to jerzygao/new-api that referenced this pull request Aug 18, 2026
Sync fork with upstream Calcium-Ion/new-api (6 commits):
- test(web): standardize frontend tests on Vitest (QuantumNous#6569)
- fix(oauth): align custom binding response fields in frontend (QuantumNous#6818)
- fix(relay): stop injecting empty tools into Claude requests
- feat: add field passthrough controls for gateway channels (QuantumNous#6847)
- fix: prompt_cache_key openai chat -> openai responses (QuantumNous#6861)
- fix(topup): guard wallet quota during recharge

Conflict resolved: web/bun.lock regenerated via 'bun install' to
reconcile the Vitest toolchain with fork dependencies.
330079598 pushed a commit to 330079598/new-api that referenced this pull request Aug 19, 2026
* test(web): standardize frontend tests on Vitest

- configure Vitest, jsdom, and React Testing Library with shared test scripts.
- migrate existing node:test suites to the Vitest runner.
- rewrite JsonCodeEditor component tests with RTL and remove the direct happy-dom dependency.

* fix(ci): run frontend tests with Vitest

- invoke the configured Vitest script so browser test setup loads in CI.
- migrate remaining node:test suites to Vitest lifecycle APIs.

* test(web): use shared jsdom environment for component tests

- migrate usage cost and tool price tests to React Testing Library.
- remove duplicate happy-dom globals and rely on the configured Vitest setup.

* test(web): verify behavior with shared vitest setup

- replace Node test assertions with Vitest expect across frontend suites.
- migrate Keys component tests to React Testing Library interactions.
- centralize jsdom browser mocks for consistent component execution.

* fix(web): unblock frozen installs and Vitest CI

- sync dompurify 3.4.13 metadata into the Bun lockfile.
- replace the bun:test and happy-dom redemption harness with Vitest and RTL.
- preserve quota conversion, error feedback, and stale-response coverage in jsdom.
Chloemlla added a commit to Chloemlla/new-api that referenced this pull request Aug 29, 2026
Upstream standardized the frontend suite on Vitest (QuantumNous#6569), but three test
files this fork added still imported node:test / node:assert/strict, which
the rsbuild-backed Vitest setup cannot bundle, so all three failed to load.
Convert them to Vitest describe/expect/test and move charts.test.ts into the
module's __tests__/ directory as web/AGENTS.md requires.

Also restore the api-key-group-cell expectation the upstream merge overwrote:
this fork renders the Auto group badge when the API omits the ratio, so the
cell keeps one frame carrying the badge effect instead of none.
biubiubiu125 pushed a commit to biubiubiu125/newapi that referenced this pull request Aug 29, 2026
* test(web): standardize frontend tests on Vitest

- configure Vitest, jsdom, and React Testing Library with shared test scripts.
- migrate existing node:test suites to the Vitest runner.
- rewrite JsonCodeEditor component tests with RTL and remove the direct happy-dom dependency.

* fix(ci): run frontend tests with Vitest

- invoke the configured Vitest script so browser test setup loads in CI.
- migrate remaining node:test suites to Vitest lifecycle APIs.

* test(web): use shared jsdom environment for component tests

- migrate usage cost and tool price tests to React Testing Library.
- remove duplicate happy-dom globals and rely on the configured Vitest setup.

* test(web): verify behavior with shared vitest setup

- replace Node test assertions with Vitest expect across frontend suites.
- migrate Keys component tests to React Testing Library interactions.
- centralize jsdom browser mocks for consistent component execution.

* fix(web): unblock frozen installs and Vitest CI

- sync dompurify 3.4.13 metadata into the Bun lockfile.
- replace the bun:test and happy-dom redemption harness with Vitest and RTL.
- preserve quota conversion, error feedback, and stale-response coverage in jsdom.
salem-2007 added a commit to salem-2007/new-api that referenced this pull request Sep 10, 2026
* test(web): standardize frontend tests on Vitest

- configure Vitest, jsdom, and React Testing Library with shared test scripts.
- migrate existing node:test suites to the Vitest runner.
- rewrite JsonCodeEditor component tests with RTL and remove the direct happy-dom dependency.

* fix(ci): run frontend tests with Vitest

- invoke the configured Vitest script so browser test setup loads in CI.
- migrate remaining node:test suites to Vitest lifecycle APIs.

* test(web): use shared jsdom environment for component tests

- migrate usage cost and tool price tests to React Testing Library.
- remove duplicate happy-dom globals and rely on the configured Vitest setup.

* test(web): verify behavior with shared vitest setup

- replace Node test assertions with Vitest expect across frontend suites.
- migrate Keys component tests to React Testing Library interactions.
- centralize jsdom browser mocks for consistent component execution.

* fix(web): unblock frozen installs and Vitest CI

- sync dompurify 3.4.13 metadata into the Bun lockfile.
- replace the bun:test and happy-dom redemption harness with Vitest and RTL.
- preserve quota conversion, error feedback, and stale-response coverage in jsdom.
timwenx pushed a commit to timwenx/new-api that referenced this pull request Nov 18, 2026
* test(web): standardize frontend tests on Vitest

- configure Vitest, jsdom, and React Testing Library with shared test scripts.
- migrate existing node:test suites to the Vitest runner.
- rewrite JsonCodeEditor component tests with RTL and remove the direct happy-dom dependency.

* fix(ci): run frontend tests with Vitest

- invoke the configured Vitest script so browser test setup loads in CI.
- migrate remaining node:test suites to Vitest lifecycle APIs.

* test(web): use shared jsdom environment for component tests

- migrate usage cost and tool price tests to React Testing Library.
- remove duplicate happy-dom globals and rely on the configured Vitest setup.

* test(web): verify behavior with shared vitest setup

- replace Node test assertions with Vitest expect across frontend suites.
- migrate Keys component tests to React Testing Library interactions.
- centralize jsdom browser mocks for consistent component execution.

* fix(web): unblock frozen installs and Vitest CI

- sync dompurify 3.4.13 metadata into the Bun lockfile.
- replace the bun:test and happy-dom redemption harness with Vitest and RTL.
- preserve quota conversion, error feedback, and stale-response coverage in jsdom.
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