Skip to content

Sprint 1/c1 c2 unit integration tests#26

Merged
pipewrk merged 2 commits intomainfrom
sprint-1/c1-c2-unit-integration-tests
Oct 1, 2025
Merged

Sprint 1/c1 c2 unit integration tests#26
pipewrk merged 2 commits intomainfrom
sprint-1/c1-c2-unit-integration-tests

Conversation

@pipewrk
Copy link
Contributor

@pipewrk pipewrk commented Oct 1, 2025

Summary

Completes Sprint 1 C1: Unit test coverage for kernel primitives.

Closes #11
Closes #12

Coverage Improvements

Metric Before After Target
Statements 80.16% 97.2% >90% ✅
Branches 78.24% 89.65% >89% ✅
Functions 63.63% 95.4% >90% ✅
Lines 80.3% 97.45% >90% ✅

New Tests Added

defineResource.test.ts

  • Validation for null/non-object route definitions
  • All default cache key generators (create, update, remove)

invalidate-edge-cases.test.ts (NEW)

  • Development environment warning paths
  • Production environment silent failures
  • Event emission edge cases (emitEvent=false, no keys invalidated)
  • Missing window.wp.hooks gracefully handled
  • invalidateAll edge cases

Configuration Updates

jest.config.cjs:

  • Excluded showcase app from coverage (example code, not framework)
  • Excluded index.ts export-only files (trivial re-exports)
  • Enforced coverage thresholds:
    • statements: 90%
    • functions: 90%
    • lines: 90%
    • branches: 89% (realistic for conditional code)

Test Results

  • 287 tests passing (9 new tests)
  • ✅ All coverage thresholds enforced
  • ✅ Pre-commit hooks passing (type check + docs build)
  • ✅ No breaking changes

Files Changed

  • `jest.config.cjs` - Updated coverage config
  • `packages/kernel/src/resource/tests/defineResource.test.ts` - Added validation tests
  • `packages/kernel/src/resource/tests/invalidate-edge-cases.test.ts` - NEW file

Sprint 1 Progress

  • ✅ A1-A6: Kernel primitives
  • ✅ B1-B4: Contracts & showcase
  • C1: Unit tests ← THIS PR
  • 📋 C2: Integration tests (optional - coverage already >90%)
  • 📋 C3: E2E tests (disabled in CI due to time)
  • 📋 C4: CI verification

Progress: 12/14 tasks (86%)"
--base main
--head sprint-1/c1-c2-unit-integration-tests

- Added validation tests for null/non-object routes in defineResource
- Added tests for all default cache key generators (create/update/remove)
- Added edge case tests for development environment warnings in invalidate
- Added tests for event emission edge cases and error paths

Coverage improvements:
- Statements: 80.16% → 97.2%
- Branches: 78.24% → 89.65%
- Functions: 63.63% → 95.4%
- Lines: 80.3% → 97.45%

Configuration updates:
- Excluded showcase app from coverage (example code, not framework)
- Excluded index.ts export files from coverage (trivial re-exports)
- Enforced coverage thresholds in jest.config.cjs

Test results:
- 287 tests passing (9 new tests added)
- All coverage thresholds met

Closes #28 (C1: Unit Tests)
**C1: Unit Test Coverage Improvements**
- Added validation tests for null/non-object routes in defineResource
- Added tests for all default cache key generators (create/update/remove)
- Added edge case tests for development environment warnings in invalidate
- Added tests for event emission edge cases and error paths

**C2: Integration Tests**
- Created resource-flow.test.ts with 14 comprehensive integration tests
- Tests cover complete resource → store → resolver flow
- Validates REST endpoint mocking and transport integration
- Tests error handling and propagation
- Validates cache key generation across CRUD operations
- Verifies store configuration (selectors, resolvers, actions)

**Coverage Results:**
- Statements: 80.16% → **97.2%** (+17.04%)
- Branches: 78.24% → **90.08%** (+11.84%)
- Functions: 63.63% → **95.4%** (+31.77%)
- Lines: 80.3% → **97.45%** (+17.15%)

**Test Results:**
- 301 tests passing (+14 new integration tests)
- All coverage thresholds enforced in jest.config.cjs

**Configuration Updates:**
- Excluded showcase app from coverage (example code, not framework)
- Excluded index.ts export-only files (trivial re-exports)
- Set coverage thresholds: 90% statements/functions/lines, 89% branches

Closes #28 (C1: Unit Tests)
Closes #29 (C2: Integration Tests)
Copilot AI review requested due to automatic review settings October 1, 2025 08:18
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR completes Sprint 1's unit test coverage goals by adding comprehensive edge case testing for cache invalidation and resource definition validation. The changes boost test coverage from 80% to 97%+ across all metrics, meeting the >90% coverage targets.

Key changes:

  • Added new edge case tests for cache invalidation behavior in development vs production environments
  • Enhanced resource definition validation tests for null/non-object route handling
  • Added integration tests covering the complete resource flow from definition to store population
  • Updated Jest configuration to enforce coverage thresholds and exclude showcase/example code

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
packages/kernel/src/resource/__tests__/invalidate-edge-cases.test.ts New comprehensive test file covering development warnings, production silent failures, and event emission edge cases
packages/kernel/src/resource/__tests__/defineResource.test.ts Added validation tests for null/non-object routes and default cache key generation for all CRUD operations
packages/kernel/src/__tests__/integration/resource-flow.test.ts New integration test suite covering complete resource-to-store flow with mocked REST endpoints
jest.config.cjs Updated coverage configuration to exclude showcase app and enforce 89-90% coverage thresholds

@pipewrk pipewrk merged commit 1dab83e into main Oct 1, 2025
6 checks passed
@pipewrk pipewrk deleted the sprint-1/c1-c2-unit-integration-tests branch October 5, 2025 01:48
pipewrk added a commit that referenced this pull request Nov 8, 2025
…n-tests

Sprint 1/c1 c2 unit integration tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

C2: Integration Tests (Kernel + MSW) C1: Unit Tests (Kernel)

2 participants