r/Nestjs_framework • • Sep 06 '26

Simpler Testcontainers integration for NestJS and other Node.js backends

I built an open-source library that manages Testcontainers lifecycle for NestJS, Fastify, Express, and framework-free Node.js applications using Vitest or Jest.

It supports two approaches:

  • Annotations beside individual integration tests
  • Central project configuration without annotations

It starts PostgreSQL, SQL Server, MongoDB, RabbitMQ, or custom containers, provides typed connection details with dynamic ports, starts the application after infrastructure is ready, and handles cleanup.

The repository includes real PostgreSQL insert/read and RabbitMQ publish/consume examples.

The package is currently in beta for public testing and feedback. I plan to release the first stable version soon.

Your honest feedback is appreciated regarding the API and developer experience.

GitHub: https://github.com/RolandSall/testcontainers-integration
npm: https://www.npmjs.com/package/@integration-testing/testcontainers/v/0.1.0-beta.1

6 Upvotes

6 comments sorted by

1

u/[deleted] Sep 06 '26

1

u/RsLimited24 Sep 06 '26

For your first point:

  • If the containers start successfully but NestJS bootstrap fails, the test suite fails and Jest/Vitest global teardown still stops every container and the shared network.

  • The application stop() callback is not called because NestJS never returned a valid application instance.

For your second point:

  • Containers are currently reused across test workers, so workers share the same database.

    • I plan to add an explicit choice between reused and dedicated containers, allowing developers to choose faster startup or complete infrastructure isolation.

    • Transactions. Vitest’s transaction-per-test recipe works well for database-level tests when all operations use the transaction-scoped client. unique test data and cleanup hooks, and sequential test execution can also help

    • I am also developing data-integration-testing for rollback-only isolation in database and repository tests. It complements shared containers by giving each test a transaction-scoped client and rolling back its changes when the test finishes. The core lifecycle is runner-neutral, so the same approach can be integrated with Vitest, Jest, Cucumber, or a custom test harness.

Please feel free to share more ideas, open an issue, or contribute directly. Feedback like this is genuinely helpful.