Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.encoreos.io/llms.txt

Use this file to discover all available pages before exploring further.

This checklist helps track the migration from the old testing patterns to the new improved infrastructure.

Completed ✅

  • Created unified TestProviders wrapper (tests/utils/providers.tsx)
  • Created module-specific cleanup utilities (tests/utils/cleanup/)
  • Updated UNIT_TEST_TEMPLATE.ts to use new TestProviders wrapper
  • Fixed Playwright baseURL mismatch (8080 → 4173)
  • Created test organization standards documentation
  • Updated test generator agent with new patterns

Manual Configuration Updates Required ⚠️

These files are protected by security hooks and require manual updates:

1. package.json - Add E2E Test Scripts

Location: After "test:rls" line Add:
"test:e2e": "playwright test",
"test:e2e:ui": "playwright test --ui",
"test:quick": "vitest run tests/unit/ --changed",

2. vitest.config.ts - Enable Parallel Execution

Change:
maxConcurrency: 1,
fileParallelism: false,
To:
// Enable parallel execution for unit tests (they don't need database)
maxConcurrency: process.env.CI ? 1 : 4, // Sequential in CI, parallel locally
fileParallelism: true, // Allow files to run in parallel

3. vitest.config.ts - Increase Coverage Thresholds

Change:
thresholds: {
  statements: 20,
  branches: 15,
  functions: 20,
  lines: 20,
},
To:
thresholds: {
  statements: 40, // Increased from 20
  branches: 35,    // Increased from 15
  functions: 40,    // Increased from 20
  lines: 40,        // Increased from 20
},

Test Migration Tasks

Phase 1: Update Hook Tests (155+ tests)

  • Identify all hook tests using manual QueryClient setup
  • Update to use wrapper from @/tests/utils/providers
  • Verify tests still pass
  • Update test files in batches:
    • tests/unit/ directory
    • tests/integration/ directory
    • Co-located tests in src/__tests__/
Pattern to Find:
// Old pattern
const createWrapper = () => { ... };
const queryClient = new QueryClient({ ... });
<QueryClientProvider client={queryClient}>
Replace With:
// New pattern
import { wrapper } from '@/tests/utils/providers';
renderHook(() => useHook(), { wrapper });

Phase 2: Update Component Tests

  • Identify component tests using manual provider setup
  • Update to use TestProviders from @/tests/utils/providers
  • Verify tests still pass
Pattern to Find:
// Old pattern
<QueryClientProvider client={queryClient}>
  <MyComponent />
</QueryClientProvider>
Replace With:
// New pattern
import { TestProviders } from '@/tests/utils/providers';
<TestProviders>
  <MyComponent />
</TestProviders>

Phase 3: Refactor tests/setup.ts

  • Import cleanup utilities: import { cleanupAllTestData } from '@/tests/utils/cleanup';
  • Replace monolithic cleanup function with module-specific cleanup
  • Verify cleanup still works correctly
  • Reduce file size from 894 lines to <200 lines
Current:
// 894 lines of cleanup code
async function cleanupAllTestData() {
  // ... hundreds of lines
}
Target:
import { cleanupAllTestData } from '@/tests/utils/cleanup';

afterAll(async () => {
  if (isSupabaseConfigured) {
    await cleanupAllTestData(supabaseAdmin, testDataRegistry);
  }
});

Phase 4: Standardize Test Organization

  • Review RLS test organization (some in subdirectories, some flat)
  • Move all RLS tests to flat tests/rls/ structure
  • Ensure all RLS tests follow {core}-{table}.rls.test.ts naming
  • Verify module organization in tests/unit/, tests/integration/, tests/e2e/

Phase 5: Fix Failing Tests

  • Run full test suite: npm test
  • Identify and fix 479 currently failing tests
  • Address QueryClient provider failures (should be fixed by Phase 1)
  • Reduce skipped tests from 2,310 (43%) to <5%

Verification Steps

After each phase:
  1. Run Tests:
    npm test
    npm run test:unit
    npm run test:integration
    npm run test:rls
    npm run test:e2e  # After adding script
    
  2. Check Coverage:
    npm run test:coverage
    
  3. Verify No Regressions:
    • Compare pass rates before/after
    • Ensure no new failures introduced
    • Verify cleanup still works

Success Criteria

  • All hook tests use wrapper from @/tests/utils/providers
  • All component tests use TestProviders wrapper
  • tests/setup.ts is <200 lines
  • Test skip rate <5% (currently 43%)
  • Test pass rate >95% (currently 84.5%)
  • Coverage thresholds at 40% (currently 15-20%)
  • All tests follow naming conventions
  • Test organization is consistent across all types

Resources

Notes

  • Some files (package.json, vitest.config.ts) are protected by security hooks
  • Manual updates required for these files
  • Test migration can be done incrementally
  • Focus on high-impact changes first (QueryClient wrapper fixes)