Skip to content

๐Ÿงช Testing โ€‹

KitchenAsty has three levels of testing: unit, integration, and end-to-end.

๐Ÿ“ Test Structure โ€‹

packages/server/src/__tests__/
โ”œโ”€โ”€ unit/           # Unit tests (no database)
โ””โ”€โ”€ integration/    # Integration tests (uses database)

e2e/                # Playwright E2E tests

โ–ถ๏ธ Running Tests โ€‹

bash
# All tests (unit + integration)
npm test

# Unit tests only
npm run test:unit

# Integration tests only
npm run test:integration

# E2E tests
npm run test:e2e

# Shared package tests
npm run test -w packages/shared

# Server unit tests
npm run test:unit -w packages/server

# Server integration tests
npm run test:integration -w packages/server

๐Ÿ”ง Test Frameworks โ€‹

LevelFrameworkLocation
๐Ÿงฉ UnitVitestpackages/server/src/__tests__/unit/
๐Ÿ”— IntegrationVitestpackages/server/src/__tests__/integration/
๐Ÿ“ฆ SharedVitestpackages/shared/src/__tests__/
๐ŸŒ E2EPlaywrighte2e/

โœ๏ธ Writing Tests โ€‹

๐Ÿงฉ Unit Tests โ€‹

Unit tests cover individual functions without external dependencies:

typescript
import { describe, it, expect } from 'vitest';
import { calculateTotal } from '../utils';

describe('calculateTotal', () => {
  it('sums items correctly', () => {
    const items = [
      { quantity: 2, unitPrice: 10.00 },
      { quantity: 1, unitPrice: 5.00 },
    ];
    expect(calculateTotal(items)).toBe(25.00);
  });
});

๐Ÿ”— Integration Tests โ€‹

Integration tests use a real PostgreSQL database:

typescript
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
import { createApp } from '../../app';
import request from 'supertest';

describe('POST /api/auth/customer/register', () => {
  const app = createApp();

  it('creates a new customer', async () => {
    const res = await request(app)
      .post('/api/auth/customer/register')
      .send({ name: 'Test', email: 'test@example.com', password: 'pass123' });

    expect(res.status).toBe(201);
    expect(res.body.success).toBe(true);
    expect(res.body.data.token).toBeDefined();
  });
});

๐ŸŒ E2E Tests โ€‹

Playwright tests exercise the full stack through the browser:

typescript
import { test, expect } from '@playwright/test';

test('customer can place an order', async ({ page }) => {
  await page.goto('http://localhost:5174');
  // Navigate, add items, checkout...
  await expect(page.locator('.order-confirmation')).toBeVisible();
});

๐Ÿ”„ CI Pipeline โ€‹

Tests run automatically on every push and pull request. See CI/CD for the pipeline configuration.

The CI runs:

  1. ๐Ÿ“ TypeScript type checking
  2. ๐Ÿงฉ Unit tests
  3. ๐Ÿ”— Integration tests
  4. ๐ŸŒ E2E tests (with a PostgreSQL service container)
  5. ๐Ÿ”’ Security audit