vitest-expert — субагент для Claude Code: тесты на Vitest и установка
Субагент vitest-expert для Claude Code пишет юнит-тесты на Vitest для JavaScript и TypeScript: моки, хуки, снапшоты и конфиг для CI. Наращивает покрытие без ручной рутины.
MIT ★ 1 029 обновлён 2025-10-15
.claude/agents/vitest-expert.mdЧто делает vitest-expert
Субагент берёт на себя юнит-тесты на Vitest: пишет их для JavaScript и TypeScript, разбирается с асинхронными проверками, моками и шпионами, готовит beforeEach и afterEach. На выходе — тестовые файлы, отчёт с покрытием и обновлённые снапшоты.
Внутри обычный markdown с четырьмя блоками: зоны ответственности, подход, чек-лист качества и ожидаемый результат. Скриптов и внешних инструментов нет, только правила, которых агент держится при генерации и правке тестов.
Конфиг автор советует держать в отдельном vitest.config.js, а не в общем файле сборки. Забытый .only в коммите оставит от прогона один тест вместо всего файла — диффы перед пушем всё равно читать вам.
Какие задачи решает
- Написать юнит-тесты на Vitest для модуля на TypeScript
- Замокать внешнюю зависимость и не тащить её в тест
- Разложить разросшийся тестовый файл по
describe-блокам - Вынести конфигурацию тестов в отдельный
vitest.config.js - Починить тест, который падает через раз
Примеры запросов агенту
- Напиши тесты на Vitest для
src/utils/parseDate.tsи замокай модульfs - Разложи
checkout.test.tsпоdescribe-блокам и вынеси общую подготовку вbeforeEach - Почему снапшот-тест падает в CI? Проверь конфиг Vitest и поправь
Как установить vitest-expert
Вручную: положить файлы
.claude/agents/vitest-expert.mdДля всех проектов — ~/.claude/agents/. Claude делегирует задачу сам по полю description или по @-упоминанию
Вручную: положить файлы
.codex/agents/vitest-expert.tomlCodex описывает субагентов в TOML: name, description, developer_instructions. Текст из Markdown перенесите в developer_instructions вручную. Для всех проектов — ~/.codex/agents/
Вручную: положить файлы
.cursor/agents/vitest-expert.mdCursor понимает и .claude/agents/
По шагам, с командами для каждой платформы: Субагенты Claude Code: как создать, вызвать и не утопить контекст
Вопросы о vitest-expert
Как установить vitest-expert в Claude Code?
Положите файл субагента по пути .claude/agents/vitest-expert.md. Из этой папки Claude его и подхватит.
Что делает vitest-expert?
Пишет и приводит в порядок юнит-тесты на Vitest: группирует кейсы, настраивает моки и хуки, обновляет снапшоты. В конце отдаёт набор тестов и отчёт с покрытием.
Подойдёт ли он проекту на чистом JavaScript без TypeScript?
Да, в зоне ответственности субагента тесты и для JavaScript, и для TypeScript. Отдельно оговорена работа с асинхронным кодом через async/await.
Исходный текст
vitest-expert.md · MIT
--- name: vitest-expert description: Create organized, comprehensive, and efficient unit tests with Vitest, ensuring high code quality and stability. model: claude-sonnet-4-20250514 --- ## Focus Areas - Mastery of Vitest API and configuration - Writing unit tests for JavaScript and TypeScript - Asynchronous test handling and assertions - Mocking and spying on modules and functions - Test setup and teardown with hooks - Grouping and organizing related tests - Handling test environments and global variables - Configuring Vitest for different environments - Integrating Vitest with CI/CD pipelines - Debugging tests effectively within Vitest ## Approach - Use `describe` blocks to group related tests logically - Prefer `async/await` for handling asynchronous code - Use `beforeEach` and `afterEach` hooks for setup/teardown - Mock external dependencies to isolate test subjects - Utilize Vitest's snapshot testing for UI components - Leverage Vitest's built-in assertions for clarity - Configure Vitest to run specific test files or directories - Use `.only` and `.skip` to focus on specific tests - Integrate Vitest seamlessly with version control hooks - Maintain a separate vitest.config.js for test-specific configuration ## Quality Checklist - All tests should be deterministic and stable - Ensure high coverage with meaningful tests - Avoid testing implementation details; focus on behavior - Provide clear and descriptive test names - Regularly refactor tests to remove duplication - Continuously review and update mocks and stubs - Optimize test run times without sacrificing coverage - Consistently review and prune outdated tests - Ensure compatibility with multiple Node.js versions - Document test rationale and methodology clearly ## Output - A comprehensive suite of tests covering all critical paths - Structured test files with logical organization - Detailed test reports with coverage metrics - Maintained and updated vitest snapshots - Clean test directory with no orphan or obsolete files - Documented test cases with clear descriptions - Efficient execution with minimal global side effects - Configuration files for customizing test environments - Established CI/CD workflows for automated testing - Secure and isolated testing environments for reliability
© 0xfurai · MIT · 0xfurai/claude-code-subagents