How sarathk06/resilient-integration-testing works
Purpose and entry points
This is a NestJS/TypeORM sample backend whose main product is a reliable API integration-test architecture: Playwright drives real HTTP requests against a per-run MySQL Docker container. Runtime entry points are src/main.ts for the application and Playwright global setup for test orchestration. A separate static presentation is served from demo/.
Application composition
The Nest root module configures dependency wiring and TypeORM persistence in src/app.module.ts. The user domain is intentionally small but exercises database semantics:
• Entity/schema and unique-email constraint: src/user.entity.ts
• HTTP resource boundary (POST, GET, DELETE /users): src/users.controller.ts
• Persistence operations and database-error-to-HTTP mapping: src/users.service.ts
Database boundary
TypeORM is the application’s ORM boundary; MySQL is the actual persistence engine rather than an in-memory substitute. The User entity drives synchronized test schema creation, including auto-increment IDs and unique email enforcement. Duplicate-key behavior crosses from MySQL/TypeORM into service-level conflict handling, then controller HTTP responses.
Disposable integration environment
The test lifecycle is owned outside the app:
• tests/global-setup.ts creates a MySQL 8 Testcontainers instance on a dynamic port, initializes Nest with that connection, and exposes the running server to tests.
• tests/global-teardown.ts closes the Nest server and destroys the container.
This creates isolated database and server state per run, avoiding shared staging resources or local MySQL dependencies.
API test execution flow
Playwright is the client-side test runner and communicates over actual network HTTP to the booted Nest process. Integration specs validate end-to-end transitions through controller, service, TypeORM, and MySQL:
• tests/integration/user-create.spec.ts
• tests/integration/user-duplicate.spec.ts
• tests/integration/user-delete.spec.ts
The essential flow is: provision container → synchronize schema/bootstrap Nest → issue HTTP requests → assert responses and persisted state → stop server/container.
Alternate external-service tests
A separate live-test mode targets the ReqRes.in public API, independent of Docker and the local Nest application:
• tests/live/live-website-api.spec.ts
• tests/live/live-browser-ui.spec.ts
• playwright.live.config.ts
This is a distinct external-network validation path, not part of the disposable MySQL environment.
Delivery and demonstration surfaces
GitHub Actions executes the Docker-backed integration workflow on hosted runners with Docker available: .github/workflows/integration-tests.yml. The project also includes a standalone browser-based presentation/demo, separate from backend runtime: demo/index.html, demo/app.js, and demo/serve.js.
Components 21
Nest backend
- Application bootstrap
src/main.ts - Root module · Wires users and TypeORM persistence.
src/app.module.ts - Users HTTP resource · Handles POST, GET, and DELETE /users.
src/users.controller.ts - Users service · Maps persistence errors to HTTP behavior.
src/users.service.ts - User schema · Defines generated IDs and unique email.
src/user.entity.ts - TypeORM
Disposable integration tests
- MySQL 8 · Real database used for synchronized test schema.
- Global setup · Starts container, initializes Nest, and exposes the server.
tests/global-setup.ts - Playwright runner
- Create-user spec
tests/integration/user-create.spec.ts - Duplicate-user spec · Validates unique-email conflict behavior.
tests/integration/user-duplicate.spec.ts - Delete-user spec
tests/integration/user-delete.spec.ts - Global teardown · Stops Nest and destroys the container.
tests/global-teardown.ts
External live tests
- Live-test config
playwright.live.config.ts - ReqRes API spec
tests/live/live-website-api.spec.ts - ReqRes browser UI spec
tests/live/live-browser-ui.spec.ts - ReqRes.in
Delivery and demo
- Integration workflow · Runs Docker-backed integration tests on hosted runners.
.github/workflows/integration-tests.yml - Demo server
demo/serve.js - Standalone demo
demo/index.html - Demo behavior
demo/app.js
Connections 23
- Application bootstrap → Root module: boots
- Root module → Users HTTP resource: wires
- Root module → Users service: provides
- Root module → TypeORM: configures
- Users HTTP resource → Users service: delegates
- Users service → TypeORM: persists through
- TypeORM → User schema: maps
- TypeORM → MySQL 8: connects to
- Global setup → MySQL 8: provisions container
- Global setup → Application bootstrap: initializes server
- Playwright runner → Create-user spec: runs
- Playwright runner → Duplicate-user spec: runs
- Playwright runner → Delete-user spec: runs
- Playwright runner → Users HTTP resource: real HTTP
- Global teardown → Application bootstrap: closes
- Global teardown → MySQL 8: destroys container
- Live-test config → ReqRes API spec: selects
- Live-test config → ReqRes browser UI spec: selects
- ReqRes API spec → ReqRes.in: calls
- ReqRes browser UI spec → ReqRes.in: drives
- Integration workflow → Playwright runner: executes
- Demo server → Standalone demo: serves
- Standalone demo → Demo behavior: loads