testing

Guides Vitest test writing, mocking, coverage, and failing-test diagnosis for LobeChat.

Updated Jan 27, 2026
One-click install
npx skills add https://github.com/SmallAi-API/smaihub --skill testing-smallai-api
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: testing
Source: https://github.com/SmallAi-API/smaihub/tree/main/.agents/skills/testing
Command: npx skills add https://github.com/SmallAi-API/smaihub --skill testing-smallai-api

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing and maintaining Vitest tests in a large monorepo is error-prone: developers run the full 3000+ test suite unnecessarily, mock the wrong layers, and waste time fixing over-specified tests that break on every refactor. This Skill provides the project's testing conventions, commands, and decision frameworks. ## Core Features & Use Cases - Targeted test execution: Run single test files with bunx vitest run for webapp, packages, database (client-db/server-db), and desktop targets instead of the full suite. - Mocking and coverage conventions: Prefer vi.spyOn over vi.mock, render real @lobehub/ui/base-ui components, and use real database integration via getTestDB() with user-isolation tests. - Failing-test triage: A decision checklist for whether to fix behavior tests or delete over-specified param-forwarding tests after refactors. - Use Case: When adding a new database model under packages/database/src/models/, follow the sibling __tests__ convention, guard BM25 blocks with describe.skipIf(!isServerDB), and verify ownership scoping. ## Quick Start Ask the assistant to write or fix a Vitest test for a specific file, such as a database model or Zustand store action, following the project testing guide.

Frequently Asked Questions about testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I run a single Vitest test file in LobeChat?

Run `bunx vitest run --silent='passed-only' '[file-path]'` from the appropriate package directory. Never run `bun run test`, which executes all 3000+ tests and takes about 10 minutes.

Should I use vi.mock or vi.spyOn in Vitest tests?

Prefer `vi.spyOn` over `vi.mock` because it is more targeted and easier to maintain. The root Vitest configs do not restore mocks automatically, so restore spies in cleanup with `vi.restoreAllMocks()`.

Why do BM25 full-text search tests fail under PGlite?

The ParadeDB BM25 `@@@` operator requires the pg_search extension, which PGlite does not provide. Guard those blocks with `describe.skipIf(!isServerDB)` and run them with `TEST_SERVER_DB=1` against Postgres.

How do I test database models in packages/database?

Use real database integration via `getTestDB()` rather than a mocked db, place tests in a sibling `__tests__/<name>.test.ts`, and always include a user-isolation test proving another user cannot modify the row.

When should I delete a failing test instead of fixing it?

Delete tests that only verify internal wiring or exact param forwarding, since they break on every refactor and duplicate behavior coverage. Keep tests that verify externally observable behavior like API responses, DB writes, or rendered output.

Do I need to mock @lobehub/ui/base-ui components in tests?

No, render the real components by default. The vitest config redirects the internal MotionProvider to a static stub, so base-ui components render without the app-level ConfigProvider.