test-coverage
Skill6 starsChanged 8 days agoApache-2.0View on GitHub
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.
- Installs packages
20 other projects use a version of this.
Adopted by
Most recently taken up by
- luongnv89/skillstheir own version, first seen Nov 6, 2026
- drvoss/everything-copilot-clitheir own version, first seen Oct 26, 2026
- vhmarquez/argotheir own version, first seen Oct 15, 2026
- manastalukdar/ai-devstudiotheir own version, first seen Oct 13, 2026
- my-chiefmind/ai-maestrotheir own version, first seen Oct 13, 2026
- wso2/product-apimtheir own version, first seen Oct 8, 2026
Used with
Projects with it also use instinct-export, instinct-import and 10 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
TheKREATORSSkillinstinct-export
Export instincts from project/global scope to a file
Also in 3 projects that use this
TheKREATORSSkillinstinct-import
Import instincts from file or URL into project/global scope
Also in 3 projects that use this
diego-tobalinaSkillbuild-fix
Fix build and compilation errors systematically. Run when build fails.
Also in 3 projects that use this
qtzx06Skilleval
Evaluate trained YOLO model accuracy with mAP metrics and per-class error analysis. Identifies failure cases for targeted improvement. Use after training.
Also in 4 projects that use this
HABUBUSSSkilleval-harness
Also in 5 projects that use this
Microsoft AzureSkilliterative-retrieval
Max-3-cycle protocol for agent sub-tasks with WHY context and coordinator validation. Use when spawning sub-agents to complete scoped work.
Also in 3 projects that use this
- +1 more from TheKREATORS
Other versions20 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 20
- cloudposse/atmos★ 1.4ksame name
- wso2/product-apim★ 1ksame name
- LedgerHQ/ledger-live★ 627same name
- luongnv89/skills★ 145same name
- drvoss/everything-copilot-cli★ 48same name
- ariadoss/superskills★ 12same name
- Montimage/skills★ 9same name
- my-chiefmind/ai-maestro★ 6same name
- kartik-nighania/av_claude_code_workshop★ 4same name
- PatriotAgenticLLC/better_claude_skillz★ 3same name
10 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository34 other files it gives its agents.
- aura-reviewSkill
- call-cognite-functionSkill
- code-qualitySkill
- connect-atlas-mcpSkill
- correctness-and-error-handlingSkill
- create-agentSkill
- create-client-toolSkill
- dependencies-auditSkill
- designSkill
- dm-graph-traversalSkill
- dm-limits-and-best-practicesSkill
- flows-app-briefSkill
- flows-code-reviewSkill
- flows-design-reviewSkill
- flows-external-app-submitSkill
- flows-review-checksSkill
- graph-viewerSkill
- handle-startup-stateSkill
- hide-show-shellSkill
- integrate-atlas-chatSkill
- integrate-file-viewerSkill
- integrate-fusion-agentSkill
- integrate-todo-listSkill
- migrate-app-to-flowsSkill
- performanceSkill
- pull-changes-resolve-conflictsSkill
- reveal-3dSkill
- securitySkill
- setup-flows-authSkill
- setup-python-toolsSkill
- skill-creatorSkill
- start-flows-appSkill
- tygenSkill
- use-topbarSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
30 rules. 0 are common, 17 are distinctive, and 13 are very specific to this project.
0
Common
Most of the 19 edited versions we read keep these.
17
Distinctive
This author's own choices. Worth a look.
13
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 17
Check that the project has a working test framework with coverage configured:
- Very specific: line 39
Add the coverage configuration to vitest.config.ts.
- Very specific: line 58
Write the updated config file.
- Very specific: line 65
Test files (*.test.ts, *.test.tsx, *.spec.ts, *.spec.tsx)
- Very specific: line 81
Remove any exclusion that hides production code from coverage measurement.
- Distinctive: line 97
Write the corrected config file.
- Distinctive: line 119
Missing imports: Read the failing test file, add the missing import statement, write the fixed file.
- Distinctive: line 120
Broken mocks: Read the test to understand what is being mocked.
- Very specific: line 121
Outdated snapshots: Run npx vitest run --update to update snapshots, then review the diff to ensure correctness.
- Very specific: line 122
Missing dependencies: Run pnpm add -D <missing-package> for any test utilities not yet installed.
- Distinctive: line 123
Config errors: Read the config file, fix syntax or option errors, write the corrected file.
- Distinctive: line 168
Use the right testing pattern for each file type:
- Very specific: line 171
Test with renderHook from @testing-library/react
- Distinctive: line 173
Test initial state, loading state, success state, and error state
- Distinctive: line 204
Test with direct function calls
- Distinctive: line 206
Test return values, side effects, and thrown errors
- Distinctive: line 226
Verify loading, error, and data states
- Distinctive: line 227
Test user interactions that trigger state changes
- Very specific: line 250
Use context injection (not vi.mock) where possible — provide test dependencies via the hook's context.
- Very specific: line 251
If the production code uses hard-coded imports that prevent context injection, use vi.mock with a justification comment explaining why …
- Very specific: line 252
Ensure mocks are type-safe — no as unknown as T casts.
- Very specific: line 254
After writing each test file, run npx vitest run <test-file> to verify it passes.
- Distinctive: line 260
If the coverage tool produces per-file metrics, list files below 80% line coverage:
- Distinctive: line 280
Uncovered error paths: Add tests that trigger error conditions (network failures, invalid input, null values, permission errors).
- Very specific: line 281
Uncovered branches: Add tests for each conditional branch.
- Distinctive: line 282
Uncovered functions: Add tests that call each exported function that lacks coverage.
- Distinctive: line 285
Run coverage again: after adding tests to verify the file now meets 80%:
- Distinctive: line 323
Read the source file and its test file.
- Distinctive: line 325
Update the test to use the improved pattern.
- Very specific: line 326
Run npx vitest run <test-file> to verify the test still passes.
“Common” is measured: kept by at least 6 in 10 of the 19 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
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:
# Check for vitest or jest in package.json
grep -E "(vitest|jest)" package.json
# Check for coverage configuration
cat vitest.config.ts 2>/dev/null || cat vitest.config.js 2>/dev/null || cat jest.config.ts 2>/dev/null || cat jest.config.js 2>/dev/nullVerify:
- 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:
pnpm add -D @vitest/coverage-v8- Add the coverage configuration to
vitest.config.ts. Read the existing config file, then add thecoveragesection insidetest:
// vitest.config.ts — minimum coverage configuration to add
test: {
coverage: {
provider: 'v8',
reporter: ['text', 'text-summary', 'lcov'],
include: ['src/**/*.{ts,tsx}'],
exclude: [
'src/**/*.test.{ts,tsx}',
'src/**/*.spec.{ts,tsx}',
'src/**/vite-env.d.ts',
'src/main.tsx',
],
},
}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.
# Check what files are excluded from coverage in the config
grep -A 20 "exclude" vitest.config.ts 2>/dev/null || grep -A 20 "exclude" vitest.config.js 2>/dev/null
# Check for coveragePathIgnorePatterns in jest config
grep -A 10 "coveragePathIgnorePatterns\|collectCoverageFrom" jest.config.ts 2>/dev/nullIf 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:
exclude: [
'src/**/*.test.{ts,tsx}',
'src/**/*.spec.{ts,tsx}',
'src/**/vite-env.d.ts',
'src/main.tsx',
],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
# Try common coverage commands based on project setup
npx vitest run --coverage 2>/dev/null || npx jest --coverage 2>/dev/null || npm test -- --coverage 2>/dev/nullRecord 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:
# List all production files and check for test counterparts
for file in $(find src -name "*.ts" -o -name "*.tsx" | grep -v ".test." | grep -v ".spec." | grep -v "node_modules" | grep -v "vite-env" | sort); do
base="${file%.*}"
ext="${file##*.}"
dir=$(dirname "$file")
filename=$(basename "$base")
# Check for test file in same directory or __tests__ directory
test_exists="false"
for pattern in "${base}.test.${ext}" "${base}.spec.${ext}" "${base}.test.ts" "${base}.spec.ts" "${dir}/__tests__/${filename}.test.${ext}" "${dir}/__tests__/${filename}.spec.${ext}"; do
if [ -f "$pattern" ]; then
test_exists="true"
break
fi
done
if [ "$test_exists" = "false" ]; then
echo "NO TEST: $file"
fi
doneCategorize 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.tsor.test.tsxfile 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:
import { renderHook, waitFor } from '@testing-library/react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
// import the hook
const createWrapper = () => {
const queryClient = new QueryClient({
defaultOptions: { queries: { retry: false } },
});
return ({ children }: { children: React.ReactNode }) => (
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
);
};
describe('useMyHook', () => {
it('returns data on success', async () => {
const { result } = renderHook(() => useMyHook(), { wrapper: createWrapper() });
await waitFor(() => expect(result.current.data).toBeDefined());
});
it('handles errors', async () => {
// set up error condition
const { result } = renderHook(() => useMyHook(), { wrapper: createWrapper() });
await waitFor(() => expect(result.current.error).toBeDefined());
});
});For services/utils:
- Test with direct function calls
- Mock CDF SDK responses where needed
- Test return values, side effects, and thrown errors
- Example structure:
import { describe, it, expect, vi } from 'vitest';
// import the service/util functions
describe('myService', () => {
it('returns expected result for valid input', () => {
const result = myFunction(validInput);
expect(result).toEqual(expectedOutput);
});
it('throws on invalid input', () => {
expect(() => myFunction(invalidInput)).toThrow();
});
});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:
import { render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
// import the component and providers
describe('MyComponent', () => {
it('shows loading state initially', () => {
render(<MyComponent />, { wrapper: createWrapper() });
expect(screen.getByText(/loading/i)).toBeInTheDocument();
});
it('renders data after loading', async () => {
render(<MyComponent />, { wrapper: createWrapper() });
await waitFor(() => {
expect(screen.getByText('expected content')).toBeInTheDocument();
});
});
});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:
# Parse lcov or text output for per-file coverage
cat coverage/coverage-summary.json 2>/dev/null | node -e "
const data = JSON.parse(require('fs').readFileSync('/dev/stdin','utf8'));
Object.entries(data).forEach(([file, metrics]) => {
if (file === 'total') return;
const pct = metrics.lines?.pct ?? 0;
if (pct < 80) console.log(pct.toFixed(1) + '% — ' + file);
});
" 2>/dev/nullFor 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%:
npx vitest run --coverage <test-file>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:
# Check for dependency injection via context
grep -rn --include="*.ts" --include="*.tsx" "useContext\|createContext" src/hooks/ src/contexts/
# Check for vi.mock usage (red flag for testability)
grep -rn --include="*.ts" --include="*.tsx" "vi\.mock" src/
# Check for unsafe casts in tests
grep -rn --include="*.ts" --include="*.tsx" "as unknown as" src/ | grep -E "\.test\.|\.spec\."
# Check for interface-based services
grep -rn --include="*.ts" --include="*.tsx" -E "implements\s+\w+" src/For each testability issue found, refactor the production code to support better testing patterns. Then update the corresponding test to use the improved pattern.
| Issue | Fix |
| Hook imports dependencies directly instead of using context | Add a context type with default dependencies. Create a context with createContext, provide defaults that use the real implementation. In the hook, use useContext to get dependencies. Tests can then provide mock dependencies via the context provider without vi.mock. |
| Service has no interface | Extract a TypeScript interface describing the service's public API. Have the class/object implement the interface. Tests mock against the interface, not the concrete implementation. |
| Page component mixes data fetching with rendering | Extract data logic into a use*ViewModel hook. The page component calls the ViewModel hook and renders based on its return value. Test the ViewModel hook separately with renderHook, test the page component with a mocked ViewModel. |
Tests use vi.mock for modules that could use context injection | After refactoring the production code to use context injection (above), update the test to provide mock dependencies via the context provider. Remove the vi.mock call. Add a comment explaining the pattern. |
Tests use as unknown as T casts for mocks | Define a proper mock type or object that satisfies the required interface. Replace the cast with a properly typed mock. If the interface is large, create a helper function that returns a partial mock with only the methods used, typed correctly. |
For each refactored file:
- Read the source file and its test file.
- Refactor the production code (add context, extract interface, extract ViewModel hook).
- Update the test to use the improved pattern.
- Run
npx vitest run <test-file>to verify the test still passes.
Step 7 — Report remaining gaps
Re-run the full test suite with coverage to get final numbers:
npx vitest run --coverage 2>/dev/null || npx jest --coverage 2>/dev/nullProduce a summary of what was done and what remains:
### Test Coverage Summary (After Fixes)
| Metric | Before | After | Gate |
|--------|--------|-------|------|
| Lines | X% | Y% | ≥80% required |
| Branches | X% | Y% | — |
| Functions | X% | Y% | — |
| Statements | X% | Y% | — |
### Coverage verdict: PASS / FAIL
### What was fixed
- [ ] Coverage tooling configured/corrected
- [ ] Exclusions cleaned up (removed N production file exclusions)
- [ ] N failing tests fixed
- [ ] N new test files written (list them)
- [ ] N existing test files expanded for coverage
- [ ] N files refactored for testability
### Remaining gaps (needs human review)
Only list issues that could not be auto-fixed:
- Complex business logic where correct test assertions require domain knowledge
- Integration tests that need real API credentials or environment setup
- Files where coverage cannot reach 80% without major architectural changes (explain why)Done
Summarize:
- Overall coverage before and after fixes, vs the 80% gate (PASS or FAIL)
- Number of test files written and tests added
- Number of files refactored for testability
- Any remaining must fix items that need human review
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.

