# Vitest Testing

Writes Vitest tests and mocks, measures coverage and diagnoses failing tests.

- Repository: https://github.com/lobehub/lobehub (83676 stars)
- Category: Testing
- License: see repository
- Last updated: 2026-11-01
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add lobehub/lobehub --skill testing -g -a claude-code -y`
Codex: `npx skills add lobehub/lobehub --skill testing -g -a codex -y`
Cursor: `npx skills add lobehub/lobehub --skill testing -g -a cursor -y`
Gemini CLI: `npx skills add lobehub/lobehub --skill testing -g -a gemini-cli -y`

## Description

Use for Vitest tests, mocks, coverage and failing-test diagnosis.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# LobeHub Testing Guide

## Quick Reference

**Commands:**

```bash
# Run specific test file
bunx vitest run --silent='passed-only' '[file-path]'

# Database package (client-db, PGlite, default, no pg_search; BM25 migrations skip themselves)
cd packages/database && bunx vitest run --silent='passed-only' '[file]'

# Database package (server-db, Postgres, BM25/pgvector parity, what CI measures coverage in)
cd packages/database && TEST_SERVER_DB=1 bunx vitest run --silent='passed-only' '[file]'
```

**Never run** `bun run test` - it runs all 3000+ tests (\~10 minutes).

> **Database models/repositories:** every new file under `packages/database/src/models/**`
> or `src/repositories/**` ships with a sibling `__tests__/<name>.test.ts` in the same PR.
> Use the real DB via `getTestDB()` (integration style), guard BM25/full-text-search blocks
> with `describe.skipIf(!isServerDB)`, and always test user-isolation. See
> `references/db-model-test.md` for setup, schema gotchas, and the client-vs-server-db split.

## Test Categories

| Category | Location                    | Config                          |
| -------- | --------------------------- | ------------------------------- |
| Webapp   | `src/**/*.test.ts(x)`       | `vitest.config.ts`              |
| Packages | `packages/*/**/*.test.ts`   | `packages/*/vitest.config.ts`   |
| Desktop  | `apps/desktop/**/*.test.ts` | `apps/desktop/vitest.config.ts` |

## Core Principles

The rest: https://github.com/lobehub/lobehub/blob/HEAD/.agents/skills/testing/SKILL.md
