Testing
ElyOS uses three testing layers to ensure code quality.
Testing Layers
Section titled “Testing Layers”| Tool | Type | Run command | Documentation |
|---|---|---|---|
| Vitest | Unit tests | bun test | Vitest → |
| fast-check | Property-based tests | bun test:pbt | Property-based → |
| Playwright | E2E tests | bunx playwright test | E2E → |
Important: Tests must be run from the apps/web directory.
When to Use Which?
Section titled “When to Use Which?”Vitest (Unit Tests)
Section titled “Vitest (Unit Tests)”Purpose: Testing individual functions, classes, and components in isolation.
Examples:
- Utility functions (formatting, validation, calculations)
- Store state management
- Server action logic
- Database repository functions
Advantages:
- Fast execution
- Simple debugging
- Precise error reporting
fast-check (Property-based Tests)
Section titled “fast-check (Property-based Tests)”Purpose: Checking invariants with random inputs.
Examples:
- Mathematical properties (commutative, associative)
- Data structure invariants
- Validation logic
- Pagination calculations
Advantages:
- Automatic testing of many edge cases
- Discovering hidden bugs
- Documenting specifications
Playwright (E2E Tests)
Section titled “Playwright (E2E Tests)”Purpose: Testing complete user flows in a browser.
Examples:
- Login flow
- Opening and using applications
- Form filling and saving
- Navigation and routing
Advantages:
- Testing real user experience
- Browser compatibility
- Detecting visual regressions
Testing Pyramid
Section titled “Testing Pyramid” /\ / \ E2E (Playwright) / \ - Few, slow, brittle /------\ / \ Property-based (fast-check) / \ - Medium quantity, invariants /------------\/ \ Unit (Vitest)\______________/ - Many, fast, stableQuick Commands
Section titled “Quick Commands”# Unit testscd apps/web && bun test
# Property-based testscd apps/web && bun test:pbt
# E2E testscd apps/web && bunx playwright test
# Watch mode (during development)cd apps/web && bunx vitestDetailed commands: Scripts reference →
Testing Conventions
Section titled “Testing Conventions”- Filename:
[filename].test.tsor[filename].spec.ts - Location: Next to the tested file
- Describe block: Name of the tested unit
- It block: Description of specific behavior
- Pattern: Arrange-Act-Assert
- Coverage: At least one test for every public function
- Edge cases: Test empty input, null, boundary values
Faker – Test Data
Section titled “Faker – Test Data”Generating random but realistic test data:
import { faker } from '@faker-js/faker';
const testUser = { name: faker.person.fullName(), email: faker.internet.email(), password: faker.internet.password({ length: 12 })};