test-coverage-improve
Skill17 starsChanged 9 months agoMITView on GitHub
Analyze and improve test coverage for the codebase targeting 80%+. Use when coverage is low or after adding new untested code.
- Reads credentials
In this repository12 other files it gives its agents.
- commitSkill
- create-branchSkill
- create-prSkill
- create-skillSkill
- fix-ciSkill
- gh-issueSkill
- merge-to-stagingSkill
- review-pr-commentsSkill
- slack-pr-recapSkill
- start-working-on-issueSkill
- testing-guideSkill
- ui-patternsSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
19 rules. About 0 are common, 10 are distinctive, and 9 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈10
Distinctive · estimate
This author's own choices. Worth a look.
9
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 11
Use parallel subagents to run tests and improve coverage.
- Very specific: line 14
Run npm test -- --coverage to identify gaps in coverage
- Very specific: line 23
NEVER mock
@prisma/client: - if errors occur, mock the specific repository instead - Very specific: line 38
Place tests in __tests__/unit/ for utility functions and services
- Very specific: line 39
Place tests in __tests__/integration/ for components and API handlers
- Distinctive: line 59
Test request/response flow with different HTTP methods
- Distinctive: line 60
Verify error handling and proper status codes
- Very specific: line 64
Use @testing-library/react for user interactions
- Distinctive: line 65
Test via user actions and observable output
- Distinctive: line 67
Test accessibility and responsive behavior
- Distinctive: line 72
Use realistic Spanish business data matching the codebase:
- Distinctive: line 89
Test these scenarios comprehensively:
- Distinctive: line 119
Assert: Verify expected outcomes and side effects
- Very specific: line 122
Use clear describe blocks that explain the component/function context
- Very specific: line 123
Write it/test descriptions that read like specifications
- Very specific: line 127
Always restore spies and mocks in afterAll or afterEach
- Very specific: line 147
Run npm test -- --coverage to verify improvement
- Distinctive: line 148
Ensure coverage meets ≥80% threshold
- Distinctive: line 152
Start by analyzing current coverage, then systematically address gaps while strictly following the mocking strategy and using realistic …
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Test Coverage Enhancement Task
Please analyze and improve the test coverage for this codebase following the established testing strategy. Run npm test -- --coverage to get current coverage and target ≥80% coverage.
Use parallel subagents to run tests and improve coverage.
1. Coverage Analysis & Strategy
- Run
npm test -- --coverageto identify gaps in coverage - Focus on files in
src/lib/utils/,src/lib/services/,app/api/, andsrc/components/ - NEVER test repositories in
src/lib/repositories/- these should remain untested - Prioritize critical business logic and complex functions
2. Project-Specific Testing Rules
Mocking Strategy (CRUCIAL)
- NEVER import or use
@prisma/clientdirectly in test files - NEVER mock
@prisma/client- if errors occur, mock the specific repository instead - ALWAYS mock repository modules used by code under test:
// At top of test file:
jest.mock("@/lib/repositories/userRepository", () => ({
getById: jest.fn(),
updateName: jest.fn(),
}));
const mockUserRepository = require("@/lib/repositories/userRepository");
// In test:
mockUserRepository.getById.mockResolvedValue({ id: '1', name: 'Ana García' });File Structure & Placement
- Place tests in
__tests__/unit/for utility functions and services - Place tests in
__tests__/integration/for components and API handlers - Tests can also be co-located with source files (
*.test.tsx)
3. Testing Patterns by File Type
Utility Functions (src/lib/utils/, src/lib/services/)
// Mock external libraries at module level
jest.mock("langfuse", () => ({
Langfuse: jest.fn(),
TextPromptClient: jest.fn(),
}));
// Mock console methods and restore in cleanup
const consoleLogSpy = jest.spyOn(console, "log").mockImplementation(() => {});
afterAll(() => consoleLogSpy.mockRestore());API Route Handlers (app/api/)
- Mock repository dependencies (never Prisma directly)
- Test request/response flow with different HTTP methods
- Verify error handling and proper status codes
- Mock authentication/authorization where needed
React Components (src/components/, app/)
- Use
@testing-library/reactfor user interactions - Test via user actions and observable output
- Mock API calls and external services
- Test accessibility and responsive behavior
4. Test Data & Edge Cases
Spanish Business Context
Use realistic Spanish business data matching the codebase:
const testData = {
customers: [
{ name: "Ana García", phone: "+34611223344" },
{ name: "José María Fernández-Vázquez", phone: "+34612345678" },
],
businesses: [
{ name: "Salon Bella", address: "Calle Mayor 1, Madrid" },
{ name: "Peluquería Ñoña & Coiffeur", services: ["corte", "peinado"] },
],
specialChars: "¡Hola! ¿Cómo está usted?",
emojis: "💇♀️✂️🎨",
};Mandatory Edge Cases for All Functions
Test these scenarios comprehensively:
nullandundefinedvalues- Empty objects
{}and arrays[] - Complex nested objects with multiple levels
- Objects with special characters and emojis
- Circular references (for inspection utilities)
- Functions within objects
- Large data sets (performance considerations)
5. Environment & TypeScript Considerations
Environment Variables
- AVOID direct assignment to
process.env.NODE_ENV(TypeScript read-only) - USE
expect.any(Boolean)for environment-dependent behavior
// ✅ DO: Test actual behavior
expect(mockUtil.inspect).toHaveBeenCalledWith(testObj, {
depth: null,
colors: process.env.NODE_ENV === "development",
});
// ❌ DON'T: Mock NODE_ENV directly
// process.env.NODE_ENV = "development"; // TypeScript error6. Test Quality Standards
Arrange-Act-Assert Structure
- Arrange: Set up test data and mocks
- Act: Execute the function/behavior being tested
- Assert: Verify expected outcomes and side effects
Descriptive Naming
- Use clear
describeblocks that explain the component/function context - Write
it/testdescriptions that read like specifications - Group related tests logically
Mock Cleanup
- Always restore spies and mocks in
afterAllorafterEach - Isolate tests to avoid shared state
- Clear mocks between tests when needed
7. Implementation Checklist
For each file with coverage gaps:
- Check if it's a repository (skip if yes)
- Identify uncovered lines, branches, and functions
- Mock all external dependencies appropriately
- Write tests covering happy path and edge cases
- Use Spanish business context in test data
- Follow AAA pattern with clear descriptions
- Test error handling and boundary conditions
- Verify mock calls with expected parameters
- Clean up mocks and spies properly
8. Coverage Verification
After implementing tests:
- Run
npm test -- --coverageto verify improvement - Ensure coverage meets ≥80% threshold
- Focus on statement, branch, and function coverage
- Address any remaining critical gaps
Start by analyzing current coverage, then systematically address gaps while strictly following the mocking strategy and using realistic Spanish business data.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

