README.md

Tests#

This directory contains all tests for the Jolly Whoppers project.

Structure#

tests/
├── unit/           # Unit tests for components, services, and utilities
├── integration/    # Integration tests for multiple components/modules
└── e2e/           # End-to-end tests for complete user workflows

Test Types#

Unit Tests (tests/unit/)#

  • Test individual components in isolation
  • Test utility functions and services
  • Fast execution, no external dependencies
  • Mock all external dependencies

Integration Tests (tests/integration/)#

  • Test multiple components working together
  • Test API integrations
  • Test page-level functionality
  • May use test databases or mock services

E2E Tests (tests/e2e/)#

  • Test complete user workflows in a real browser
  • Test the application as end users would use it
  • Slowest but most comprehensive
  • Use actual application environment

Setup#

To set up testing, install a test framework:

# Vitest (recommended for unit/integration tests)
pnpm add -D vitest @testing-library/svelte

# Playwright (recommended for e2e tests)
pnpm add -D @playwright/test

Running Tests#

Add these scripts to package.json:

{
  "scripts": {
    "test": "vitest",
    "test:unit": "vitest run tests/unit",
    "test:integration": "vitest run tests/integration",
    "test:e2e": "playwright test",
    "test:coverage": "vitest run --coverage"
  }
}

Then run:

# Run all tests
pnpm test

# Run specific test types
pnpm test:unit
pnpm test:integration
pnpm test:e2e

# Run with coverage
pnpm test:coverage

Best Practices#

  1. Write tests as you develop - Don't wait until the end
  2. Test behavior, not implementation - Focus on what the code does, not how
  3. Keep tests isolated - Each test should be independent
  4. Use descriptive names - Test names should explain what they test
  5. Maintain tests - Update tests when features change
  6. Aim for good coverage - But don't obsess over 100%

Resources#