๐งช 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 โ
| Level | Framework | Location |
|---|---|---|
| ๐งฉ Unit | Vitest | packages/server/src/__tests__/unit/ |
| ๐ Integration | Vitest | packages/server/src/__tests__/integration/ |
| ๐ฆ Shared | Vitest | packages/shared/src/__tests__/ |
| ๐ E2E | Playwright | e2e/ |
โ๏ธ 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:
- ๐ TypeScript type checking
- ๐งฉ Unit tests
- ๐ Integration tests
- ๐ E2E tests (with a PostgreSQL service container)
- ๐ Security audit