Testing Overview

Comprehensive testing infrastructure for reliable FlagFlow development

Overview

FlagFlow includes a comprehensive testing infrastructure built on modern testing frameworks and tools. The testing system supports unit testing, integration testing, and end-to-end testing with isolated state management and in-memory mocking capabilities.

Testing Philosophy: FlagFlow's testing infrastructure emphasizes test isolation, comprehensive coverage, and developer-friendly testing utilities for reliable development workflows.

Testing Stack

Unit Testing

  • Vitest - Fast, modern testing framework with TypeScript support
  • @testing-library/svelte - Component testing utilities for Svelte
  • jsdom - DOM environment for headless testing
  • Coverage reporting - Built-in code coverage with detailed reports

Integration & E2E Testing

  • In-memory mocks - RPC testing with MockPersistentService
  • InMemoryPersistentEngine - Isolated state for test reliability
  • Real-time testing - Flag watching in test environments
  • Service isolation - Complete service layer testing

Test Architecture

The testing architecture provides multiple levels of testing with proper isolation and mocking:

Test Architecture Example
// Test setup with isolated environment
import { beforeEach, afterEach, describe, it, expect } from 'vitest';
import { render, cleanup } from '@testing-library/svelte';
import { MockPersistentService } from './mocks/MockPersistentService';
import { InMemoryPersistentEngine } from './engines/InMemoryPersistentEngine';

describe('FlagFlow Component Tests', () => {
  let mockService: MockPersistentService;
  
  beforeEach(() => {
    // Create isolated test environment
    mockService = new MockPersistentService(
      new InMemoryPersistentEngine()
    );
    
    // Setup test data
    mockService.setFlags({
      'feature.enabled': true,
      'config.maxRetries': 5
    });
  });
  
  afterEach(() => {
    cleanup();
    mockService.reset();
  });
  
  it('should render flag-dependent component correctly', () => {
    const { getByTestId } = render(MyComponent, {
      props: { flagService: mockService }
    });
    
    expect(getByTestId('feature-content')).toBeInTheDocument();
  });
});

Test Isolation

FlagFlow's testing infrastructure provides complete test isolation through in-memory state management, ensuring tests are independent and reliable:

InMemoryPersistentEngine

Provides isolated, in-memory storage for each test run, eliminating cross-test contamination and external dependencies.

  • Complete isolation between test runs
  • No external database dependencies
  • Fast setup and teardown
  • Predictable test state

MockPersistentService

Wraps the InMemoryPersistentEngine to provide a service-layer interface for testing with full API compatibility.

  • Full service API compatibility
  • Real-time flag watching support
  • Audit logging in test mode
  • Type-safe testing utilities

Running Tests

FlagFlow provides several commands for running different types of tests:

Test Commands
# Run all tests
npm test

# Run tests with UI interface
npm run test:ui

# Run tests with coverage report
npm run test:coverage

# Run tests in watch mode (development)
npm run test:watch

# Run specific test file
npm test -- flag-service.test.ts

# Run tests matching pattern
npm test -- --grep="flag validation"

Test Configuration

Tests are configured through vitest.config.ts with optimized settings for FlagFlow development:

Vitest Configuration
// vitest.config.ts
import { defineConfig } from 'vitest/config';
import { sveltekit } from '@sveltejs/kit/vite';

export default defineConfig({
  plugins: [sveltekit()],
  test: {
    environment: 'jsdom',
    setupFiles: ['tests/setup.ts'],
    coverage: {
      reporter: ['text', 'html', 'json'],
      exclude: [
        'node_modules/**',
        'tests/**',
        '**/*.d.ts',
        'build/**'
      ]
    },
    globals: true,
    alias: {
      '$lib': './src/lib',
      '$components': './src/components'
    }
  }
});

Testing Best Practices

Test Organization

  • Group related tests in describe blocks
  • Use descriptive test names that explain the expected behavior
  • Keep tests focused on single behaviors
  • Use setup and teardown hooks for common test preparation

Isolation & Mocking

  • Always use MockPersistentService for service-layer testing
  • Reset mock state between tests
  • Avoid real external dependencies in tests
  • Use InMemoryPersistentEngine for predictable state

Coverage & Quality

  • Aim for comprehensive test coverage of critical paths
  • Test both success and error scenarios
  • Include edge cases and boundary conditions
  • Use coverage reports to identify untested code
© 2025 FlagFlow All Rights Reserved. llms.txt