Testing
Run unit tests, end-to-end tests, static checks, coverage, and the same verification stages used by CI.
Testing
The project uses Jest for unit tests, Supertest for HTTP end-to-end tests, and Testcontainers support for isolated PostgreSQL workflows.
Unit tests
Run the serial unit suite:
pnpm testThe explicit alias is:
pnpm test:unitWatch mode and coverage:
pnpm test:watch
pnpm test:covTests matching *.e2e-spec.ts are excluded from the default unit configuration.
End-to-end tests
E2E tests use their own Jest configuration:
pnpm test:e2eThey exercise the NestJS application, HTTP contracts, authentication, authorization, persistence, and OpenAPI behavior.
Use a disposable database. The test data source prefers .env.test:
NODE_ENV=test
DATABASE_URL=postgresql://postgres:postgres@127.0.0.1:5432/nestjs_test
DATABASE_SSL=false
LOG_LEVEL=errorNever point E2E tests at development, staging, or production data. Ensure the database name, port, username, and password match the test PostgreSQL instance.
Apply migrations before running tests against a manually managed database:
NODE_ENV=test pnpm migration:run
pnpm test:e2eStatic checks
pnpm lint
pnpm typecheck
pnpm format:checkAutomatic fixes modify files:
pnpm lint:fix
pnpm formatAlways inspect the resulting diff.
Production build
pnpm buildThe Nest CLI builds the api application with webpack. A successful type check
does not replace a production build, and a successful build does not replace
tests.
CI workflow
GitHub Actions runs on pull requests and pushes to main. The verification job:
- Starts PostgreSQL 17.
- Installs the lockfile dependencies with Node.js 24 and pnpm.
- Checks formatting.
- Runs ESLint.
- Runs TypeScript checks.
- Applies test migrations.
- Runs coverage tests.
- Runs E2E tests.
- Builds the API.
- Audits production dependencies at high severity.
The workflow cancels older runs for the same branch or pull request.
Before opening a change
Run:
pnpm format:check
pnpm lint
pnpm typecheck
pnpm test
pnpm test:e2e
pnpm buildAlso verify:
- New schema behavior has a reviewed migration.
- Trust-boundary validation is represented in DTOs.
- New endpoints include OpenAPI metadata and expected error responses.
- Authentication and permission requirements are covered by E2E tests.
- Logs and errors do not expose secrets, raw tokens, or passwords.
See Database and Migrations for safe test database handling.