Analyzing test coverage

From diegosouzapw/awesome-omni-skill · View interactive version

Analyzing test coverage is an AI agent skill from the GitHub repository diegosouzapw/awesome-omni-skill. 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.

How to use this skill

Skill file

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

Table of Contents

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:

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:

Mock Functions

See references/patterns.md for examples. Common patterns:

Running Tests

# 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

For Test Suites

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:

beforeEach(() => {
  vi.clearAllMocks(); // Always reset!
});

Testing Implementation Details:

// BAD - tests internal structure
expect(service.internalMap.size).toBe(1);

// GOOD - tests behavior
expect(await service.findBySlug('test')).toBeDefined();

Flaky Async Tests:

// 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

Project Resources

External Documentation

Related Skills

Quick Reference Rule

For a condensed quick reference, see .claude/rules/testing-standards.md (automatically loaded when editing *.test.ts files).

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.