Repository navigation
test(web): standardize frontend tests on Vitest - #6569
Conversation
- 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
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThe 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. ChangesVitest test infrastructure
Estimated code review effort: 3 (Moderate) | ~25 minutes Merge Risk: ⚪ Minimal · up to 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
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
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. Comment |
- invoke the configured Vitest script so browser test setup loads in CI. - migrate remaining node:test suites to Vitest lifecycle APIs.
There was a problem hiding this comment.
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
📒 Files selected for processing (7)
.github/workflows/ci.ymlweb/src/features/auth/lib/__tests__/oauth-callback-mode.test.tsweb/src/features/channels/lib/__tests__/new-api-channel.test.tsweb/src/features/profile/components/__tests__/login-session-utils.test.tsweb/src/features/system-settings/models/__tests__/tool-price-validation.test.tsxweb/src/features/usage-logs/components/__tests__/cost-display.test.tsxweb/src/features/usage-logs/lib/__tests__/tool-surcharge.test.ts
- 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.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
web/src/features/keys/components/__tests__/api-key-group-combobox.test.tsx (1)
22-36: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winRestore
window.matchMediaafter each test.These lines replace a global browser API. The replacement remains installed after this suite. A failed test can also leave
shouldReduceMotionenabled.Install the mock in
beforeEach. Restore the originalwindow.matchMediaand resetshouldReduceMotioninafterEach.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
📒 Files selected for processing (28)
web/src/components/json-code-editor/__tests__/json-code-editor-utils.test.tsweb/src/components/model-group-selector/__tests__/layout.test.tsweb/src/components/ui/dropdown-menu.test.tsxweb/src/features/auth/api.test.tsweb/src/features/auth/lib/__tests__/oauth-callback-mode.test.tsweb/src/features/auth/lib/auth-redirect.test.tsweb/src/features/auth/lib/oauth-bind-window.test.tsweb/src/features/auth/lib/telegram-login.test.tsweb/src/features/channels/lib/__tests__/channel-field-update.test.tsweb/src/features/channels/lib/__tests__/channel-table-row-id.test.tsweb/src/features/channels/lib/__tests__/new-api-channel.test.tsweb/src/features/dashboard/lib/flow-selection.test.tsweb/src/features/dashboard/lib/flow.test.tsweb/src/features/keys/components/__tests__/api-key-group-cell.test.tsxweb/src/features/keys/components/__tests__/api-key-group-combobox.test.tsxweb/src/features/keys/components/__tests__/api-keys-mutate-drawer.test.tsxweb/src/features/keys/components/__tests__/auto-group-order-editor.test.tsxweb/src/features/keys/lib/__tests__/auto-group-form.test.tsweb/src/features/playground/hooks/use-stream-request.test.tsweb/src/features/profile/components/__tests__/login-session-utils.test.tsweb/src/features/system-settings/models/__tests__/group-auto-limit-validation.test.tsweb/src/features/usage-logs/lib/__tests__/tool-surcharge.test.tsweb/src/features/wallet/hooks/use-payment.test.tsweb/src/features/wallet/lib/payment.test.tsweb/src/lib/auth-session.test.tsweb/src/lib/legacy-route.test.tsweb/src/lib/server-error-message.test.tsweb/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.
* 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.
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.
* 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.
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.
* 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.
* 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.
* 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.
Important
📝 变更描述 / Description
(简述:做了什么?为什么这样改能生效?请基于你对代码逻辑的理解来写,避免粘贴未经整理的内容)
概述
改动说明
测试说明
🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。📸 运行证明 / Proof of Work
(请在此粘贴截图、关键日志或测试报告,以证明变更生效)
Summary by CodeRabbit