JCC Express

Testing

Testing Overview

JCC Express MVC ships with a Laravel-style testing layer that lets you test your application through real HTTP requests and database assertions — no mocking required.


How it works

Each feature test:

  1. Boots a full Application instance (your real routes, middleware, providers)
  2. Starts a temporary HTTP server on a random port
  3. Makes real fetch() requests against it
  4. Wraps the result in TestResponse so you can make fluent assertions
  5. Tears the server down after each request automatically

Database state is isolated using withTransaction, which rolls back after every test body.


Two test runners — important

RunnerCommandUsed for
vitestnpm run testUnit tests (tests/Unit/)
bun testbun test tests/FeatureFeature tests (tests/Feature/)

Feature tests import from bun:test and cannot run under Vitest. vitest.config.ts excludes tests/Feature/** for this reason. Always use bun test for feature tests.


Core classes

ClassRole
TestCaseBoots app, exposes HTTP + DB helpers
MakesHttpRequestsHTTP helper — get, post, put, patch, delete
TestResponseFluent response assertions
InteractsWithDatabaseDB assertions
Factory + FakerTest data generation

Project test structure

TypeScript
tests/
  TestCase.ts          ← your project's base test case (extends framework TestCase)
  Feature/HTTP / integration tests (bun test)
  Unit/                ← isolated logic tests (vitest)
Testing/
  Factory.ts           ← Factory + Faker helpers

Generate a test

Bash
bun artisanNode make:test UsersTest

Creates a starter file in tests/Feature/.