Add @vitest/coverage-v8 with 80% branch coverage threshold to frontend build #121

Closed
opened 2026-03-27 18:35:53 +01:00 by marcel · 1 comment
Owner

Problem

The frontend has no coverage measurement. vitest is configured and running but @vitest/coverage-v8 is not installed and no coverage thresholds are defined. We have no idea what percentage of frontend utility functions and component logic is actually tested.

Why This Matters

Frontend business logic — date formatting, filename parsing, sort utilities, error message mapping — is exactly the kind of code that breaks silently when refactored. Without a coverage gate, new utility functions can ship untested and the CI pipeline will never flag it.

What Needs To Be Done

  1. Install the coverage provider:

    npm install -D @vitest/coverage-v8
    
  2. Add coverage configuration to vite.config.ts:

    test: {
      coverage: {
        provider: 'v8',
        reporter: ['text', 'lcov'],
        thresholds: {
          branches: 80,
        },
        include: ['src/lib/**'],
        exclude: ['src/lib/api/**', 'src/**/*.spec.*'],
      }
    }
    
  3. Add a coverage script to package.json:

    "test:coverage": "vitest run --coverage"
    
  4. Upload the lcov report as a CI artifact in the unit test job

Acceptance Criteria

  • npm run test:coverage fails if branch coverage drops below 80%
  • Coverage report uploaded as CI artifact
  • Coverage measured over src/lib/** (utils, components, error handling)
## Problem The frontend has no coverage measurement. `vitest` is configured and running but `@vitest/coverage-v8` is not installed and no coverage thresholds are defined. We have no idea what percentage of frontend utility functions and component logic is actually tested. ## Why This Matters Frontend business logic — date formatting, filename parsing, sort utilities, error message mapping — is exactly the kind of code that breaks silently when refactored. Without a coverage gate, new utility functions can ship untested and the CI pipeline will never flag it. ## What Needs To Be Done 1. Install the coverage provider: ```bash npm install -D @vitest/coverage-v8 ``` 2. Add coverage configuration to `vite.config.ts`: ```typescript test: { coverage: { provider: 'v8', reporter: ['text', 'lcov'], thresholds: { branches: 80, }, include: ['src/lib/**'], exclude: ['src/lib/api/**', 'src/**/*.spec.*'], } } ``` 3. Add a coverage script to `package.json`: ```json "test:coverage": "vitest run --coverage" ``` 4. Upload the lcov report as a CI artifact in the unit test job ## Acceptance Criteria - [ ] `npm run test:coverage` fails if branch coverage drops below 80% - [ ] Coverage report uploaded as CI artifact - [ ] Coverage measured over `src/lib/**` (utils, components, error handling)
marcel added the test label 2026-03-27 18:45:07 +01:00
Author
Owner

Architect review (@mkeller): ⚠️ Right direction, two concerns before implementing.

Scope: src/lib/** as the include covers Svelte components. Branch coverage on compiled Svelte components is noisier than on plain TypeScript — the Svelte compiler emits branches you didn't write, which skews the numbers. Start with a narrower include: src/lib/utils/**, src/lib/errors.ts, and any explicit utility modules. Expand once the baseline is stable and you understand what the compiler noise looks like.

Sequencing: Same advice as #120 — measure the current baseline first, set the gate there, then ratchet up. Shipping an 80% gate you cannot currently meet will either break CI or get commented out. Neither outcome is useful.

**Architect review (@mkeller):** ⚠️ Right direction, two concerns before implementing. **Scope:** `src/lib/**` as the include covers Svelte components. Branch coverage on compiled Svelte components is noisier than on plain TypeScript — the Svelte compiler emits branches you didn't write, which skews the numbers. Start with a narrower include: `src/lib/utils/**`, `src/lib/errors.ts`, and any explicit utility modules. Expand once the baseline is stable and you understand what the compiler noise looks like. **Sequencing:** Same advice as #120 — measure the current baseline first, set the gate there, then ratchet up. Shipping an 80% gate you cannot currently meet will either break CI or get commented out. Neither outcome is useful.
Sign in to join this conversation.
No Label test
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: marcel/familienarchiv#121