testing

Guides writing, fixing, and organizing Vitest tests for the LobeHub codebase.

74|11|Updated Jul 4, 2024
One-click install
npx skills add https://github.com/OpenSourceAGI/qwksearch-research-agent --skill testing-opensourceagi
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: testing
Source: https://github.com/OpenSourceAGI/qwksearch-research-agent/tree/main/apps/qwk-in-lobe/.agents/skills/testing
Command: npx skills add https://github.com/OpenSourceAGI/qwksearch-research-agent --skill testing-opensourceagi

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing and maintaining tests in a large monorepo is error-prone: tests break on refactors, mocks are misused, database tests behave differently across environments, and running the full suite wastes time. This Skill provides concrete Vitest conventions, mock patterns, and environment-specific guidance so tests are written correctly the first time. ## Core Features & Use Cases - Vitest conventions and commands: Run targeted test files instead of the full 3000+ test suite, with separate commands for client-db (PGlite) and server-db (Postgres) modes. - Mock patterns: Prefer vi.spyOn over vi.mock, compose UI stubs over importOriginal, and mock at boundaries like database, network, and Electron IPC. - Specialized reference guides: Detailed instructions for database model testing, Zustand store actions, Electron IPC, desktop controllers, and agent runtime E2E tests. - Use Case: After adding a new repository under packages/database/src/repositories/, use this Skill to generate a sibling integration test with getTestDB(), user-isolation checks, and BM25 guards via describe.skipIf(!isServerDB). ## Quick Start Ask the agent to write a Vitest test for a specific source file following the project's testing conventions.

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 without running the whole suite?

Run `bunx vitest run --silent='passed-only' '[file-path]'` to execute one test file. Never run `bun run test`, which executes all 3000+ tests and takes about 10 minutes.

How do I test database models with a real database in Vitest?

Use `getTestDB()` from the database package to get a real integration database, then create a sibling `__tests__/<name>.test.ts` file. By default it uses in-memory PGlite; set `TEST_SERVER_DB=1` to run against Postgres with pg_search and pgvector support.

Should I use vi.mock or vi.spyOn for mocking in Vitest?

Prefer `vi.spyOn` over `vi.mock` because it is more targeted and easier to maintain. Reserve `vi.mock` for module-level dependencies like Electron IPC clients, and mock at boundaries such as the database, network, or external services rather than between internal modules.

Why do BM25 full-text search tests fail or return empty results locally?

PGlite, the default client-db engine, does not support the ParadeDB BM25 `@@@` operator, so those queries throw or silently return empty arrays. Guard those blocks with `describe.skipIf(!isServerDB)` and run them with `TEST_SERVER_DB=1` against Postgres.

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

Delete tests that only verify internal wiring, such as exact parameter forwarding to internal functions, when a higher-level behavior test already covers the same outcome. Keep and update tests that verify externally observable behavior like API responses, database writes, or rendered output.