Testing Documentation
Complete testing guide for SveltyCMS including Bun unit tests, Playwright E2E tests, GitHub Actions automation, and local testing workflows.
Last updated: 11/21/2025
SveltyCMS Testing Documentation
Last Updated: November 21, 2025 Total Tests: ~615 Pass Rate: ~65% (403 passing, 172 failing, 40 skipped)
Why Multiple Test Documentation Files?
This testing documentation is organized into 12 specialized files for easy navigation and maintenance:
- By Test Type: Unit, Integration, E2E
- By Coverage Area: APIs, Hooks, Stores, Widgets, Utilities
- By Purpose: Status reports, workflow guides, coverage reports
This structure allows developers to quickly find relevant testing information without wading through a single massive document.
Test Frameworks Overview
SveltyCMS uses two complementary test frameworks to ensure comprehensive quality coverage:
π§ͺ Bun Test - Unit & Integration Tests
- Purpose: Fast, lightweight testing for business logic, services, and API endpoints
- Location:
tests/bun/ - Test Count: ~575 tests
- Execution Time: ~2-15 seconds
What It Tests:
- β Services (auth, security, caching)
- β Utilities (validation, formatting, crypto)
- β Stores (system state, UI state, loading)
- β Widgets (validation, rendering, security)
- β Middleware Hooks (all 11 hooks)
- β API Endpoints (integration tests)
- β Database Operations (MongoDB currently)
Why Bun?
- 100x faster than Jest/Mocha
- Native TypeScript support (no transpilation)
- Built-in mocking
- Perfect for headless CMS architecture
π Playwright - End-to-End Tests
- Purpose: Browser automation for critical user journeys
- Location:
tests/playwright/ - Test Count: ~40 tests
- Execution Time: ~30-60 seconds
What It Tests:
- β Setup Wizard flow
- β Login/Authentication
- β Content CRUD operations
- β Admin dashboard
- β User management
Why Playwright?
- Cross-browser testing (Chromium, Firefox, WebKit)
- Reliable auto-waiting
- Screenshot/video recording on failure
- Parallel execution
GitHub Actions Automation
All tests run automatically in CI/CD via GitHub Actions:
Workflow: .github/workflows/playwright.yml
jobs:
unit-tests:
runs-on: ubuntu-latest
steps:
- Run Bun unit tests (~350 tests)
- Execution time: ~2 seconds
integration-tests:
runs-on: ubuntu-latest
services:
mongodb: # MongoDB service container
steps:
- Clean config directory
- Start dev server
- Seed test database
- Run Bun integration tests (~225 tests)
- Execution time: ~15 seconds
e2e-tests:
runs-on: ubuntu-latest
services:
mongodb:
steps:
- Clean config directory
- Install Playwright browsers
- Start dev server
- Seed test database
- Run Playwright E2E tests (~40 tests)
- Execution time: ~60 seconds
[!IMPORTANT] Security Note: All GitHub workflows use pinned commit SHAs for actions and enforce frozen lockfiles (
bun install --frozen-lockfile) to protect against supply chain attacks. Do not change these to version tags without verifying the commit SHA.
When Tests Run:
- On Pull Request: All tests must pass before merge
- On Push to main/next: Full test suite + release checks
- Manual Trigger: Via
workflow_dispatch
Future: Multi-Database Matrix Testing
[!NOTE] Coming Soon: Parallel testing against multiple databases
strategy: matrix: database: [mongodb, postgresql, mariadb, mysql]This will ensure SveltyCMS works correctly with all supported databases via Drizzle ORM.
Local Testing (Before Committing)
Quick Start
# Run ALL tests (unit + integration + E2E)
bun run test:all
# Run specific test types
bun run test:unit # Fast (~2s) - No server needed
bun run test:integration # Medium (~15s) - Requires server
bun run test:e2e # Slow (~60s) - Requires server + browser
Unit Tests Only (Fastest)
# All unit tests
bun run test:unit
# Specific test files
bun test tests/bun/services/SecurityResponseService.test.ts
bun test tests/bun/stores/system.test.ts
bun test tests/bun/widgets/richText.test.ts
# Watch mode (re-run on file changes)
bun test --watch tests/bun/services/
Integration Tests (Requires Server)
# Terminal 1: Start dev server
bun run dev
# Terminal 2: Run integration tests
bun test tests/bun/api/
bun test tests/bun/hooks/
bun test tests/bun/databases/
Or use the automated script:
# Automatically starts server, waits for ready, runs tests
bun run test:integration
E2E Tests (Requires Server + Browser)
# Automated (recommended)
bun run test:e2e # Starts server, seeds DB, runs Playwright
# Manual
# Terminal 1: Start server
bun run dev
# Terminal 2: Seed database
bun run scripts/seed-test-db.ts
# Terminal 3: Run Playwright
bun x playwright test tests/playwright/
Smart Testing (Local Development)
# Intelligent test runner
bun run scripts/test-smart.ts
This script:
- Checks if server is running (starts if needed)
- Detects if system is configured
- Runs appropriate tests (setup tests OR full suite)
- Cleans up after itself
Test Status & Coverage
Current Status (November 21, 2025)
| Category | Passing | Failing | Skipped | Total |
|---|---|---|---|---|
| Unit Tests | 350 | 0 | 0 | 350 |
| Integration Tests | 53 | 172 | 40 | 265 |
| E2E Tests | TBD | TBD | TBD | ~40 |
| TOTAL | 403 | 172 | 40 | 615 |
Recently Fixed β
tests/bun/hooks/authorization.test.ts(22 tests) - Fixed mock database adaptertests/bun/hooks/theme.test.ts(40 tests) - Fixed mockResolve signaturetests/bun/hooks/firewall.test.ts(27 tests) - Fixed logger import
Known Issues β οΈ
- 172 failing tests in API integration and Setup middleware
- Root cause: Server connection timeouts in test environment
- Fix in progress: Improving test environment setup
See Test Status Report for detailed breakdown.
Documentation Index
Core Testing Guides
- Test Status Report - Current pass/fail rates, known issues
- E2E Testing Guide - Playwright setup and best practices
- Git Workflow & CI/CD - GitHub Actions automation
Coverage Reports
- API Test Coverage - REST API endpoint testing (460+ tests)
- Hook Test Coverage - Middleware hooks (11 hooks, 485+ tests)
- Store Test Coverage - Svelte stores (system, UI, loading)
- Widget Test Coverage - Widget validation and security
- Utility Test Coverage - Helper functions and utilities
Specific Test Documentation
- API Test Summary - Quick API test overview
- User API Tests - User management endpoint tests
- Database Tests - Database adapter testing
Why Bun for Testing SveltyCMS?
SveltyCMS is an agnostic headless SvelteKit CMS - it works with multiple databases and focuses on API-first architecture. Bun is the perfect testing framework for this use case:
π Speed & Performance
Lightning-Fast Execution
- Up to 100x faster than Jest/Mocha
- Our 76-test utility suite completes in ~1.5 seconds
- Full API test suite (460+ tests) completes in ~15-20 seconds
- Instant feedback during development
Why Speed Matters for a Headless CMS:
- Rapid iteration on API endpoints
- Quick validation of database operations
- Immediate feedback on widget validation and security
- Faster CI/CD pipelines = faster releases
π― Perfect Match for Headless CMS Architecture
Database Agnostic Testing
- SveltyCMS supports MongoDB, PostgreSQL, MySQL, MariaDB
- Bunβs speed allows testing against multiple database adapters without painful wait times
- Future: Matrix testing across all databases in parallel
Headless CMS Requirements
- REST API testing (460+ endpoint tests)
- GraphQL API validation
- Widget system testing (security, validation, rendering)
- Multi-tenant isolation testing
- Cache layer verification (Redis operations)
- Authentication & authorization flows
Native TypeScript Support
- Zero configuration - Bun runs
.tsfiles directly - No transpilation overhead
- Perfect for SvelteKitβs TypeScript-first approach
- Type-safe test code matches production code
β‘ Built-in Features
// Just import and go - no jest.config.js, no babel setup
import { describe, it, expect, mock } from 'bun:test';
// Native mocking
const mockFn = mock(() => 'mocked value');
// Async/await support
it('should handle async operations', async () => {
const result = await fetchData();
expect(result).toBeDefined();
});
Test Organization
Directory Structure
tests/
βββ bun/ # Bun unit & integration tests
β βββ setup.ts # Global test setup
β βββ mocks/ # Mock implementations
β βββ api/ # API integration tests
β βββ databases/ # Database adapter tests
β βββ hooks/ # Middleware hook tests
β βββ services/ # Service layer tests
β βββ stores/ # Svelte store tests
β βββ utils/ # Utility function tests
β βββ widgets/ # Widget validation tests
β
βββ playwright/ # Playwright E2E tests
β βββ setup-wizard.spec.ts
β βββ login.spec.ts
β βββ helpers/ # Test helpers
β
βββ scripts/ # Test automation scripts
βββ seed-test-db.ts # Database seeding for tests
βββ test-smart.ts # Intelligent test runner
Test File Naming Convention
- Unit Tests:
*.test.ts(e.g.,SecurityResponseService.test.ts) - Integration Tests:
*.test.tsinapi/,hooks/,databases/ - E2E Tests:
*.spec.ts(e.g.,login.spec.ts)
Best Practices
For Developers
- Run tests locally before committing
bun run test:unit # Quick sanity check - Write tests for new features
- Unit tests for business logic
- Integration tests for API endpoints
- E2E tests for critical user flows (if needed)
- Use watch mode during development
bun test --watch tests/bun/services/MyNewService.test.ts - Check CI before merging
- All tests must pass in GitHub Actions
- Review test failures in PR checks
For Test Writers
- Follow existing patterns
- See Hook Test Coverage for examples
- Use descriptive test names
it('should return 401 for unauthenticated API requests', async () => { // Test implementation }); - Mock external dependencies
import { mock } from 'bun:test'; const mockDb = mock(() => ({ users: [] })); - Test edge cases
- Empty inputs
- Invalid data
- Error conditions
Troubleshooting
Common Issues
βServer did not start in timeβ
- Check if port 5173 is already in use
- Run
bun run devmanually to see errors - Increase timeout in
scripts/seed-test-db.ts
βCannot find module β@src/β¦ββ
- Ensure
bunfig.tomlhas correct path aliases - Run
bun installto refresh dependencies
βTest timeoutβ
- Integration tests need running server
- Use
bun run test:integration(auto-starts server) - Or start server manually in separate terminal
βDatabase connection failedβ
- Ensure MongoDB is running (for integration/E2E tests)
- Check
DB_HOST,DB_PORT,DB_NAMEenv vars - Run
bun run scripts/seed-test-db.tsmanually to debug
Contributing
When adding new tests:
- Choose the right test type:
- Unit test: Pure functions, no external dependencies
- Integration test: API endpoints, database operations
- E2E test: Critical user journeys only
- Update documentation:
- Add test count to relevant coverage report
- Update this index if adding new test category
- Verify in CI:
- Push to PR and check GitHub Actions
- All tests must pass before merge