Skip to main content
This document outlines improvements made to the testing infrastructure.

Summary of Changes

P0: Critical Fixes (Completed)

  1. ✅ Fixed Playwright baseURL - Changed from http://localhost:8080 to http://localhost:4173 to match the preview server
  2. ✅ Created unified TestProviders wrapper - New tests/utils/providers.tsx provides a single wrapper for all React hook tests
  3. ✅ Added test:e2e / test:e2e:ui / test:quick scripts - 2026-04-18
  4. ✅ Repointed HR hook test imports to current subfolder paths - 2026-04-18 (Phase 1 of dev/test stability plan)
  5. ✅ Aliased Deno-only npm:@sentry/deno to a Node shim for Vitest - 2026-04-18 (tests/mocks/deno-sentry-shim.ts)
  6. ✅ TestProviders now wraps in MemoryRouter with noRouter opt-out for tests that wrap their own router
  7. ✅ Migrated 22+ failing component/hook tests to TestProviders + provider-wrapped renders - 2026-04-18
  8. ✅ Eliminated all Failed Suites (SKIP_SUPABASE_TESTS=true npm run test:unit shows 0 failed)

P1: High Priority Improvements (Completed)

  1. ✅ Module-specific cleanup utilities - Split cleanup logic into tests/utils/cleanup/
  2. ✅ Updated test templates - UNIT_TEST_TEMPLATE.ts uses new TestProviders wrapper
  3. ✅ Coverage thresholds raised to 40% statements/lines/functions, 35% branches
  4. ✅ Vitest pool switched to threads with bounded maxWorkers - 2026-04-18 (vitest.config.ts)
  5. ⏳ CI-safe test distinction - documentation present; per-project split (unit / integration / rls) deferred until shared-mock cleanup audit completes (an isolate: false trial revealed ~200 cross-test contamination failures)
  6. ⏳ Standardize test organization - documentation present; in-flight

P2: Medium Priority

  1. ✅ Module-specific test scripts - test:e2e:{auth,hr,fa,ce,fw,gr,platform}, test:e2e:smoke, test:rls:smoke, etc.
  2. ⏳ Vitest projects split (unit/integration/rls) - Deferred (see P1#5).
  3. ⏳ Supabase types split by schema - Tracked separately; the 100k-line generated types file is the dominant tsc cost.

New Files Created

Test Utilities

  1. tests/utils/providers.tsx
    • Unified wrapper component with QueryClientProvider and OrganizationProvider
    • Replaces manual QueryClient setup in every test
    • Usage: import { TestProviders, wrapper } from '@/tests/utils/providers';
  2. tests/utils/cleanup/ directory
    • pf-cleanup.ts - Platform Foundation cleanup
    • hr-cleanup.ts - Human Resources cleanup
    • fa-cleanup.ts - Finance & Accounting cleanup
    • fw-cleanup.ts - Forms & Workflow cleanup
    • index.ts - Unified export for all cleanup functions

Documentation

  1. docs/testing/TESTING_IMPROVEMENTS.md (this file)
  2. tests/utils/cleanup/README.md - Cleanup utilities documentation

Manual Changes Required

Due to security hooks protecting certain configuration files, the following changes need to be made manually:

1. Add E2E Test Scripts to package.json

Add these scripts after "test:rls":

2. Update vitest.config.ts

Enable Parallel Execution for Unit Tests

Change:
To:

Increase Coverage Thresholds

Change:
To:

Add Different Timeouts for Different Test Types

Consider adding test-specific timeouts:

Migration Guide

For Existing Tests

1. Update Hook Tests to Use TestProviders

Before:
After:

2. Update Component Tests to Use TestProviders

Before:
After:

3. Update Cleanup in tests/setup.ts

Before:
After:

Test Organization Standards

Naming Conventions

  • RLS Tests: {core}-{table}.rls.test.ts (e.g., hr-employees.rls.test.ts)
  • Unit Tests: {core}/{feature}.test.ts (e.g., hr/useEmployees.test.ts)
  • Integration Tests: {core}/{workflow}-workflow.test.ts (e.g., hr/onboarding-workflow.test.ts)
  • E2E Tests: {core}/{feature}.spec.ts (e.g., hr/employee-management.spec.ts)

Directory Structure


Next Steps

  1. Manual Configuration Updates
    • Update package.json with new test scripts
    • Update vitest.config.ts with parallel execution and higher coverage thresholds
  2. Migrate Existing Tests
    • Update all hook tests to use wrapper from @/tests/utils/providers
    • Update component tests to use TestProviders
    • Refactor tests/setup.ts to use module-specific cleanup utilities
  3. Fix Failing Tests
    • Address 155+ QueryClient provider failures
    • Fix 479 currently failing tests
    • Reduce 2,310 skipped tests (43% of suite)
  4. Documentation
    • Update docs/testing/index.md with new patterns
    • Update .cursor/agents/test-generator.md to use new patterns
    • Create migration checklist for team

Metrics to Track


References