Complete testing strategy covering unit tests, integration tests, and end-to-end testing with real-world examples from the SaaS boilerplate.
The boilerplate implements a layered testing strategy that mirrors the application architecture:
6 Testing Layers: From general testing patterns to specific E2E workflows, each layer has its own purpose and tooling.
1. General Testing Patterns
2. Unit Testing
3. UI Component Testing
4. Repository Testing
5. Service Testing
6. End-to-End Testing
Core testing technologies and configuration patterns:
Multi-Project Setup:
// vitest.config.ts
import { defineConfig } from 'vitest/config'
import react from '@vitejs/plugin-react'
import tsconfigPaths from 'vite-tsconfig-paths'
export default defineConfig({
plugins: [react(), tsconfigPaths()],
test: {
projects: [
// Client-side tests (jsdom environment)
{
name: 'client',
environment: 'jsdom',
include: ['src/**/*.test.{ts,tsx}'],
exclude: ['src/services/**/*.test.{ts,tsx}'],
setupFiles: ['./src/__tests__/setup-test.ts'],
globals: true,
},
// Server-side tests (node environment)
{
name: 'server',
environment: 'node',
include: ['src/services/**/*.test.{ts,tsx}'],
setupFiles: ['./src/services/__tests__/setup-mocks.ts'],
globals: true,
},
],
},
})Key Features:
Get started with testing in minutes:
Daily Testing Commands:
# Run all tests
pnpm test # Run unit tests
pnpm test:e2e # Run E2E tests
# Development workflow
pnpm test:watch # Watch mode for unit tests
pnpm test:ui # Open Vitest UI
pnpm test:e2e:ui # Open Playwright UI
# Coverage and debugging
pnpm test:coverage # Generate coverage report
pnpm test:e2e:headed # E2E with visible browser
# Specific tests
pnpm test user-service # Run matching pattern
pnpm test src/services/__tests__/user-service.test.tsComprehensive guides for each testing layer:
# Unit testing
pnpm test # Run all unit tests
pnpm test:watch # Run tests in watch mode
pnpm test:coverage # Generate coverage report
pnpm test:ui # Open Vitest UI interface
# Specific test files
pnpm test user-service # Run tests matching pattern
pnpm test src/services/__tests__/user-service.test.ts
# End-to-end testing
pnpm test:e2e # Run all E2E tests
pnpm test:e2e:headed # Run with visible browser
pnpm test:e2e:ui # Open Playwright UITesting Philosophy: Write tests that document behavior, catch regressions, and give confidence when refactoring. Focus on testing behavior, not implementation details.
Key Principles:
Performance Tips:
vi.clearAllMocks() in beforeEach to prevent test pollutionFoundational patterns, mocking strategies, and testing philosophy
Service functions, utilities, and isolated component logic
React components, user interactions, and UI behavior
Database operations, Drizzle queries, and data access patterns
Business logic, authorization, and service layer integration
Full application flows, user journeys, and Playwright automation
Testing ready! The boilerplate includes comprehensive testing strategies that ensure code quality, catch regressions, and provide confidence when shipping new features.