🔍 Exclude Generated Code and Mocks from Test Coverage #235

Open
opened 2025-08-08 07:15:28 +00:00 by goern · 0 comments
goern commented 2025-08-08 07:15:28 +00:00 (Migrated from codeberg.org)

🎯 Problem Statement

Currently, our test coverage includes generated code and mock implementations, which inflates coverage metrics and doesn't reflect the actual quality of our hand-written code.

📋 Requirements

Code Types to Exclude from Coverage:

1. Generated Code

  • Prisma generated files: src/lib/generated/**
  • Any codegen output: **/*.generated.{js,jsx,ts,tsx}
  • GraphQL codegen (if used in future)
  • Protobuf generated code (if used)

2. Mock Implementations

  • Test mocks: **/__mocks__/**
  • Development mocks: src/mocks/**
  • Jest setup mocks: tests/**/__mocks__/**

3. Framework Boilerplate

  • Next.js default files: layout.tsx, error.tsx, not-found.tsx
  • Page components: page.tsx (tested via E2E instead)
  • Type-only files: Pure TypeScript definition files

4. Third-party Integration Code

  • Vendor code: src/vendor/**
  • External integrations: src/external/**

🔧 Implementation Tasks

Phase 1: Update Jest Configuration

  • Update jest.config.base.ts with comprehensive exclusion patterns
  • Test exclusions work correctly
  • Verify coverage reports exclude specified files

Phase 2: Update CI/CD Pipeline

  • Update .forgejo/workflows/test-coverage.yml
  • Ensure consistent exclusions across environments
  • Validate coverage thresholds still meaningful

Phase 3: Documentation

  • Update testing strategy documentation
  • Create exclusion policy guidelines
  • Document rationale for each exclusion category

Success Criteria

  1. Coverage reports only include hand-written code
  2. Generated files have 0% coverage impact
  3. Mock files are excluded from coverage metrics
  4. Coverage thresholds remain achievable and meaningful
  5. CI/CD pipeline respects all exclusions

📊 Expected Impact

  • More accurate coverage metrics reflecting actual code quality
  • Reduced false positives in coverage reports
  • Clearer focus on testing business logic vs. generated code
  • Improved developer experience with realistic coverage targets
  • #234 - Increase Test Coverage to 80% Global Target
  • Related to overall testing strategy improvements

📝 Notes

This follows industry best practices where:

  • Generated code is assumed to be tested by the generator
  • Mock code is implementation detail, not business logic
  • Framework boilerplate is tested by the framework itself

Priority: High - Should be implemented before finalizing coverage targets

## 🎯 Problem Statement Currently, our test coverage includes generated code and mock implementations, which inflates coverage metrics and doesn't reflect the actual quality of our hand-written code. ## 📋 Requirements ### Code Types to Exclude from Coverage: #### 1. Generated Code - **Prisma generated files**: `src/lib/generated/**` - **Any codegen output**: `**/*.generated.{js,jsx,ts,tsx}` - **GraphQL codegen** (if used in future) - **Protobuf generated code** (if used) #### 2. Mock Implementations - **Test mocks**: `**/__mocks__/**` - **Development mocks**: `src/mocks/**` - **Jest setup mocks**: `tests/**/__mocks__/**` #### 3. Framework Boilerplate - **Next.js default files**: `layout.tsx`, `error.tsx`, `not-found.tsx` - **Page components**: `page.tsx` (tested via E2E instead) - **Type-only files**: Pure TypeScript definition files #### 4. Third-party Integration Code - **Vendor code**: `src/vendor/**` - **External integrations**: `src/external/**` ## 🔧 Implementation Tasks ### Phase 1: Update Jest Configuration - [ ] Update `jest.config.base.ts` with comprehensive exclusion patterns - [ ] Test exclusions work correctly - [ ] Verify coverage reports exclude specified files ### Phase 2: Update CI/CD Pipeline - [ ] Update `.forgejo/workflows/test-coverage.yml` - [ ] Ensure consistent exclusions across environments - [ ] Validate coverage thresholds still meaningful ### Phase 3: Documentation - [ ] Update testing strategy documentation - [ ] Create exclusion policy guidelines - [ ] Document rationale for each exclusion category ## ✅ Success Criteria 1. **Coverage reports only include hand-written code** 2. **Generated files have 0% coverage impact** 3. **Mock files are excluded from coverage metrics** 4. **Coverage thresholds remain achievable and meaningful** 5. **CI/CD pipeline respects all exclusions** ## 📊 Expected Impact - **More accurate coverage metrics** reflecting actual code quality - **Reduced false positives** in coverage reports - **Clearer focus** on testing business logic vs. generated code - **Improved developer experience** with realistic coverage targets ## 🔗 Related Issues - #234 - Increase Test Coverage to 80% Global Target - Related to overall testing strategy improvements ## 📝 Notes This follows industry best practices where: - Generated code is assumed to be tested by the generator - Mock code is implementation detail, not business logic - Framework boilerplate is tested by the framework itself **Priority**: High - Should be implemented before finalizing coverage targets
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
feeldata/feeldata.app#235
No description provided.