cognitedata/builder-skills/test-coverage
Claude Code and agent skill by cognitedata/builder-skills
- community
- ext:[{"type":"context","description":"Custom context provider definitions"}]
Checking that the SKILL.md file is still in the repository.
MUST be used whenever fixing test coverage for a Flows app to meet the 80% line coverage hard gate. This skill finds AND fixes coverage gaps — it configures tooling, writes missing tests, covers untested paths, and refactors code for testability. It does not just report. Triggers: test coverage, fix tests, write tests, add tests, coverage fix, 80% coverage, coverage gate, missing tests, testability, vitest coverage, jest coverage.
Install
npx vskill@latest install cognitedata/builder-skills/test-coverageSemi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard
SKILL.md
The same SKILL.md was published earlier as cognitedata/builder-skills/test-coverage.
Test Coverage Fix
Fix test coverage for $ARGUMENTS (or the whole app if no argument is given). This skill enforces the 80% line coverage hard gate required for Flows app approval by finding AND fixing coverage gaps. Work through every step in order.
Step 1 — Verify test framework and coverage tooling
Check that the project has a working test framework with coverage configured:
Verify:
- A test framework (Vitest or Jest) is installed and configured
- The config file has a
coveragesection (e.g.coverage: { provider: 'v8', ... }in vitest.config.ts) - A coverage reporter is configured (at least
textandlcovorjson-summary)
If coverage tooling is not configured, fix it now:
- Install the coverage provider:
- Add the coverage configuration to
vitest.config.ts. Read the existing config file, then add thecoveragesection insidetest:
Write the updated config file. If no vitest.config.ts exists at all, create one with the full defineConfig wrapper.
Step 2 — Validate coverage scope
The 80% threshold applies to all `.ts` and `.tsx` files under src/, excluding only:
- Test files (
*.test.ts,*.test.tsx,*.spec.ts,*.spec.tsx) - Type declaration files (
vite-env.d.ts) - The entry point (
main.tsx)
Apps must not exclude pages, components, hooks, or other production code from coverage measurement.
If the config excludes production files, fix it now:
Remove any exclusion that hides production code from coverage measurement. Only test files, type declarations, and the entry point should be excluded. Rewrite the exclude array to contain only:
Specifically remove any exclusions for:
src/pages/orsrc/components/orsrc/hooks/— NOT allowed- Specific feature files — NOT allowed unless they are generated code
src/**/*.tsx(all components) — NOT allowed, this hides the majority of the app
Write the corrected config file.
Step 3 — Run tests and collect coverage
Record the coverage summary:
- Statements: X%
- Branches: X%
- Functions: X%
- Lines: X%
Hard gate: Overall line coverage must be at least 80%. Apps below this threshold are listed as must fix.
If tests fail to run, fix them now:
Common fixes:
- Missing imports: Read the failing test file, add the missing import statement, write the fixed file.
- Broken mocks: Read the test to understand what is being mocked. Fix the mock to match the current API of the mocked module.
- Outdated snapshots: Run
npx vitest run --updateto update snapshots, then review the diff to ensure correctness. - Missing dependencies: Run
pnpm add -D <missing-package>for any test utilities not yet installed. - Config errors: Read the config file, fix syntax or option errors, write the corrected file.
Re-run tests after each fix until all tests pass. Then record the coverage summary.
Step 4 — Find and write missing test files
For every non-trivial .ts/.tsx file under src/, check whether a corresponding test file exists:
Categorize each file without a test:
- Services, hooks, utils, contexts, ViewModel hooks — Write the test file now (see below)
- Pure presentational components with no logic — Mark as N/A (no test required)
- Barrel exports (
index.tsthat only re-exports) — Mark as N/A - Type-only files (
.d.ts, files with only type/interface exports) — Mark as N/A
For each file missing a test, create a comprehensive test file. Use context injection for dependency mocking where the production code supports it. If the production code uses hard-coded imports, note this as a testability concern but still write the test using vi.mock with a justification comment. Follow this process for each:
- Read the source file to understand its exports, dependencies, and logic.
- Create a `.test.ts` or `.test.tsx` file in the same directory as the source file.
- Write tests covering: happy path, error path, empty state, and edge cases.
Use the right testing pattern for each file type:
For hooks:
- Test with
renderHookfrom@testing-library/react - Wrap with necessary providers (QueryClientProvider, custom context providers, etc.)
- Test initial state, loading state, success state, and error state
- Example structure:
For services/utils:
- Test with direct function calls
- Mock CDF SDK responses where needed
- Test return values, side effects, and thrown errors
- Example structure:
For components with logic:
- Test with
renderfrom@testing-library/react - Verify loading, error, and data states
- Test user interactions that trigger state changes
- Example structure:
Dependency mocking guidelines:
- Use context injection (not
vi.mock) where possible — provide test dependencies via the hook's context. - If the production code uses hard-coded imports that prevent context injection, use
vi.mockwith a justification comment explaining why (e.g.,// vi.mock required: useDataSource uses direct import, not context injection). - Ensure mocks are type-safe — no
as unknown as Tcasts. Define proper mock objects that satisfy the interface.
After writing each test file, run npx vitest run <test-file> to verify it passes.
Step 5 — Fix low-coverage files
If the coverage tool produces per-file metrics, list files below 80% line coverage:
For each file below 80% coverage, read the uncovered lines from the coverage report, then add test cases that exercise those specific code paths:
- Read the uncovered lines from the coverage report. Check the
coverage/directory for detailed per-file reports (lcov or html) that show which lines are uncovered. - Read the source file to understand what those uncovered lines do.
- Add test cases that exercise those specific code paths:
- Uncovered error paths: Add tests that trigger error conditions (network failures, invalid input, null values, permission errors). Force errors by providing bad input or mocking dependencies to throw.
- Uncovered branches: Add tests for each conditional branch. If an
if/elsehas only thetruebranch tested, write a test that triggers thefalsebranch. - Uncovered functions: Add tests that call each exported function that lacks coverage. Verify return values and side effects.
- Uncovered catch blocks: Mock the upstream call to reject/throw, verify the catch block behavior.
- Run coverage again after adding tests to verify the file now meets 80%:
Repeat until each file reaches at least 80% line coverage or you have covered all feasible paths.
Step 6 — Fix testability patterns
Assess and fix testability issues in the codebase:
For each testability issue found, refactor the production code to support better testing patterns. Then update the corresponding test to use the improved pattern.
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/test-coverage/SKILL.md
Popularity
- Repository stars
- 5
- Repository forks
- 1
- 7-day trend score
- 9
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 2 Aug 2026, 3 months ago.
Extension points
contextCustom context provider definitions
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/cognitedata/builder-skills/test-coverage)