Skip to content

Testing Strategy โ€‹

Express Forge encourages a test-driven approach to development. We provide a pre-configured testing environment using either Vitest (recommended for speed) or Jest.

๐Ÿงช Types of Tests โ€‹

Unit Tests โ€‹

Focused on testing individual functions or services in isolation.

  • Location: src/modules/**/__tests__/*.unit.spec.ts
  • Focus: Business logic, utility functions, validation.

Integration Tests โ€‹

Testing the full API flow, including database interactions.

  • Location: tests/*.int.spec.ts
  • Focus: HTTP status codes, API responses, database persistence.

๐Ÿš€ Running Tests โ€‹

bash
# Run all tests
npm test

# Run tests in watch mode
npm run test:watch

# Generate coverage report
npm run test:coverage

๐Ÿ›  Testing Tools โ€‹

  • Supertest: Used for making HTTP requests to your app without starting a real server.
  • Prisma Mocking: (If using Prisma) We provide patterns for mocking the Prisma client for unit tests.
  • Test Database: Integration tests automatically use a separate test database defined in .env.test.

Example Integration Test โ€‹

typescript
import request from 'supertest';
import { app } from '../src/app';

describe('GET /health', () => {
  it('should return 200 OK', async () => {
    const response = await request(app).get('/health');
    expect(response.status).toBe(200);
    expect(response.body.status).toBe('ok');
  });
});

๐Ÿ›  Contributing: CLI Smoke Testing โ€‹

If you are contributing to the create-express-forge CLI itself, you should run the automated smoke test to verify your changes. This test scaffolds a project, runs a full TypeScript type-check, and builds the resulting app.

bash
cd packages/create-express-forge
pnpm run test:smoke

Released under the MIT License.