Skip to content

TestContainers is a NodeJS library that supports tests, providing lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container.

License

Notifications You must be signed in to change notification settings

coblox/testcontainers-node

 
 

Repository files navigation

Testcontainers

Testcontainers is a NodeJS library that supports tests, providing lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container.

Build Status npm version npm version

Install

npm i -D testcontainers

Usage

Run your app with the DEBUG=testcontainers environment variable set to see debug output.

The following environment variables are supported:

Key Example value Behaviour
DOCKER_HOST tcp://docker:2375 Override the Docker host, useful for DIND in CI environments

Example

const redis = require("async-redis");
const { GenericContainer } = require("testcontainers");

(async () => {
  const container = await new GenericContainer("redis")
    .withEnv("KEY", "VALUE")
    .withExposedPorts(6379)
    .start();

  const redisClient = redis.createClient(
      container.getMappedPort(6379),
      container.getContainerIpAddress(),
  );
  await redisClient.quit();

  await container.stop();
})();

About

TestContainers is a NodeJS library that supports tests, providing lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 97.4%
  • JavaScript 1.5%
  • Dockerfile 1.1%