An example project showcasing how to use @trendyol/jest-testcontainers to write integration tests for your PostgreSQL queries.
Read the article describing this project in detail on Medium.
.
├── migrations # database migratioons
├── src # source code of your application
└── test
├── integration # integration tests that contain IO operations(e.g. DB, Queue)
└── unit # unit tests for pure business logic / interaction witout IO
- test/integration/ includes various files like jest.config.js, jest-testcontainers-config.js and preset.js for configuring jest-testcontainers to start a PostgreSQL instance.
- jest-testcontainers is used to start a PostgreSQL instance and wait for t to start.
- migrations/ folder stores database schema migrations that will be applied to the started PostgreSQL instance.
- postgresql.environment.ts uses node-pg-migrate to migrate PostgreSQL instance started by the jest-testcontainers.
- test/integration/ folder is scanned for files with
*.test.ts
prefix and tests are ran.
Watch mode is supported so you can start your integration tests in watch mode and refactor your code whilst your PostgreSQL Docker instance is up.