analyzing-test-coverage
Creates and analyzes tests using Vitest and MSW patterns. Generates test builders, mocks repositories, and configures integration tests. Triggers on: write tests, test coverage, Vitest, MSW mock, vi.fn, vi.mock, unit test, integration test, test builder, mock setup, test failure.
Best use case
analyzing-test-coverage is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Creates and analyzes tests using Vitest and MSW patterns. Generates test builders, mocks repositories, and configures integration tests. Triggers on: write tests, test coverage, Vitest, MSW mock, vi.fn, vi.mock, unit test, integration test, test builder, mock setup, test failure.
Teams using analyzing-test-coverage should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/analyzing-test-coverage/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How analyzing-test-coverage Compares
| Feature / Agent | analyzing-test-coverage | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Creates and analyzes tests using Vitest and MSW patterns. Generates test builders, mocks repositories, and configures integration tests. Triggers on: write tests, test coverage, Vitest, MSW mock, vi.fn, vi.mock, unit test, integration test, test builder, mock setup, test failure.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Testing Strategy Analyst
## Purpose
Guide the creation of comprehensive tests following project patterns for unit tests, integration tests, and E2E tests using Vitest, MSW, and project-specific test helpers.
## When to Use
- Writing new tests
- Analyzing test coverage gaps
- Setting up mocks for testing
- Organizing test files
- Debugging test failures
## Table of Contents
- [Testing Stack](#testing-stack)
- [Test Organization](#test-organization)
- [Quick Pattern Reference](#quick-pattern-reference)
- [Running Tests](#running-tests)
- [Test Quality Checklist](#test-quality-checklist)
- [Common Pitfalls](#common-pitfalls)
- [References](#references)
## Testing Stack
| Tool | Purpose |
|------|---------|
| **Vitest** | Test runner and assertion library |
| **MSW** | Mock Service Worker for network mocking |
| **vi** | Vitest mock utilities |
| **test-helpers/** | Project-specific test utilities |
## Test Organization
```
src/
├── modules/
│ └── category/
│ ├── category-service.ts
│ ├── category-service.test.ts # Unit tests
│ ├── repository.ts
│ ├── repository.test.ts # Repository tests
│ └── category.integration.test.ts # Integration tests
├── core/
│ └── diff/
│ └── comparators/
│ ├── category-comparator.ts
│ └── category-comparator.test.ts
├── test-helpers/
│ ├── config-file-builder.ts
│ ├── graphql-mocks.ts
│ ├── config-fixtures.ts
│ └── cli-runner.ts
└── lib/
└── test-setup.ts # Global test setup
e2e/
└── ... # End-to-end tests
```
## Quick Pattern Reference
### Service Tests
See `references/patterns.md` for full examples. Key structure:
- Declare dependencies at suite level
- Reset mocks in `beforeEach` with `vi.clearAllMocks()`
- Use describe blocks for method grouping
- Follow **Arrange-Act-Assert** pattern
### Repository Tests with MSW
See `references/patterns.md` for MSW setup. Key steps:
1. Define handlers with `graphql.query()` / `graphql.mutation()`
2. Setup server with `beforeAll` / `afterAll`
3. Override handlers for specific test cases with `server.use()`
### Test Data Builders
See `references/test-builders.md` for implementations. Pattern:
- Create builder class with fluent interface
- Validate with Zod schema in `build()`
- Provide factory functions for convenience
### Mock Functions
See `references/patterns.md` for examples. Common patterns:
- `vi.fn()` for simple mocks
- `vi.mocked()` for typed access
- `vi.mock()` for module mocking
## Running Tests
```bash
# Run all tests
pnpm test
# Run specific test file
pnpm test -- --filter=category-service
# Run tests matching pattern
pnpm test -- --grep="should create category"
# Watch mode
pnpm test -- --watch
# With coverage
pnpm test -- --coverage
```
See `references/commands-reference.md` for advanced options and coverage configuration.
## Test Quality Checklist
### For Every Test
- [ ] Follows Arrange-Act-Assert pattern
- [ ] Has descriptive test name
- [ ] Tests one thing per test
- [ ] Includes both positive and negative cases
- [ ] Uses typed mocks (not `any`)
- [ ] Cleans up after itself (beforeEach/afterEach)
### For Test Suites
- [ ] Covers all public methods
- [ ] Covers error scenarios
- [ ] Covers edge cases
- [ ] Uses schema-validated test data
- [ ] Has integration tests for complex flows
## Validation Checkpoints
| Phase | Validate | Command |
|-------|----------|---------|
| Test written | File exists | Check `*.test.ts` created |
| Tests pass | All green | `pnpm test <file>` |
| Coverage adequate | Key paths covered | `pnpm test --coverage` |
| Mocks typed | No `any` in mocks | `npx tsc --noEmit` |
## Common Pitfalls
**Not Resetting Mocks**:
```typescript
beforeEach(() => {
vi.clearAllMocks(); // Always reset!
});
```
**Testing Implementation Details**:
```typescript
// BAD - tests internal structure
expect(service.internalMap.size).toBe(1);
// GOOD - tests behavior
expect(await service.findBySlug('test')).toBeDefined();
```
**Flaky Async Tests**:
```typescript
// BAD - race condition
const result = service.process();
expect(result).toBe(expected);
// GOOD - await properly
const result = await service.process();
expect(result).toBe(expected);
```
## References
### Skill Reference Files
- `references/patterns.md` - Detailed test patterns with full code examples
- `references/test-builders.md` - Builder pattern implementations
- `references/commands-reference.md` - Complete command reference
### Project Resources
- `{baseDir}/src/test-helpers/` - Test utilities
- `{baseDir}/vitest.config.ts` - Test configuration
- `{baseDir}/docs/TESTING_PROTOCOLS.md` - Testing protocols
### External Documentation
- Vitest docs: https://vitest.dev
- MSW docs: https://mswjs.io
## Related Skills
- **Complete entity workflow**: See `adding-entity-types` for E2E implementation including tests
- **Zod test patterns**: See `designing-zod-schemas` for schema validation tests
- **GraphQL mocking**: See `writing-graphql-operations` for MSW handlers
## Quick Reference Rule
For a condensed quick reference, see `.claude/rules/testing-standards.md` (automatically loaded when editing `*.test.ts` files).Related Skills
minitest-testing
Write, review, and improve Minitest tests for Ruby on Rails applications. Covers model tests, controller tests, system tests, fixtures, and best practices from Rails Testing Guide.
inference-smoke-tests
Run repeatable inference smoke tests using geppetto/pinocchio example binaries (single-pass, streaming, tool-loop, OpenAI Responses thinking) including tmux-driven TUI tests. Use when refactors touch InferenceState/Session/EngineBuilder, tool calling loop, event sinks, provider request formatting, or when you need a quick 'does inference still work?' checklist.
analyzing-innovation-portfolio
Analyze the CustomGPT.ai Labs Innovation workbook and cost tracking data to surface portfolio-level insights, trends, and recommendations for where to focus Innovation efforts.
analyzing-data
Queries data warehouse and answers business questions about data. Handles questions requiring database/warehouse queries including "who uses X", "how many Y", "show me Z", "find customers", "what is the count", data lookups, metrics, trends, or SQL analysis.
analyzing-auto-insurance-data
Analyzes vehicle insurance daily reports and signing lists. Use when user asks to analyze insurance data, generate business reports, check institution performance, monitor policy trends, or detect business anomalies. Handles Excel/CSV files with fields like premium, institution, customer type, and renewal status.
ai-powered-pentesting
Guide for AI-powered penetration testing tools, red teaming frameworks, and autonomous security agents.
Advanced Testability Ai Ergonomic
Design code for testability and AI/LLM ergonomics with explicit contracts and observable patterns. Use when optimizing code for AI tools, improving testability, or making codebases LLM-friendly.
ab-testing-analyzer
全面的AB测试分析工具,支持实验设计、统计检验、用户分群分析和可视化报告生成。用于分析产品改版、营销活动、功能优化等AB测试结果,提供统计显著性检验和深度洞察。
ab-test-framework-ml
Эксперт A/B тестирования. Используй для статистических тестов, экспериментов и ML-оптимизации.
pytest-runner
Execute Python tests with pytest, supporting fixtures, markers, coverage, and parallel execution. Use for Python test automation.
cli-e2e-testing
CLI E2E testing patterns with BATS - parallelization, state sharing, and timeout management
bats-testing-patterns
Comprehensive guide for writing shell script tests using Bats (Bash Automated Testing System). Use when writing or improving tests for Bash/shell scripts, creating test fixtures, mocking commands, or setting up CI/CD for shell script testing. Includes patterns for assertions, setup/teardown, mocking, fixtures, and integration with GitHub Actions.