This repository demonstrates the use of Testcontainers with Node.js for integration testing. Testcontainers is a library that provides throwaway, lightweight instances of databases, message brokers, web browsers, or just about anything that can run in a Docker container.
Before you begin, ensure you have the following installed on your system:
The tests are located in the src/test
directory and include:
-
- Tests the initialization and connection to a generic container.
- Demonstrates the use of the
GenericContainer
class for running basic container operations.
-
- Tests various wait strategies to ensure containers are ready before running tests.
- Demonstrates the use of waiting mechanisms like
forLogMessage
andforListeningPorts
.
-
- Demonstrates how to set up a custom network and ensure communication between containers.
-
postgres-customer-repository.test.js:
- Demonstrates the use of the
PostgreSqlContainer
module for database interactions.
- Demonstrates the use of the
-
mysql-customer-repository.test.js:
- Demonstrates the use of the
MySQLContainer
module for database interactions.
- Demonstrates the use of the
-
- Demonstrates the use of the
SeleniumContainer
module for web testing.
- Demonstrates the use of the
To get started with this project, follow these steps:
-
Clone the repository:
git clone https://github.com/GannaChernyshova/testcontainers-node-demo.git cd testcontainers-node-demo
-
Install dependencies:
npm install
To run all tests or a single test using Jest, use the following commands:
-
Run all tests:
npm test
-
Run a single test:
npx jest src/test/generic-connection.test.js
This will execute the specified test file using Jest.