You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

testcontainers

Package Overview
Maintainers
1
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Source code not available
We could not scan this package. Some page functionalities have been disabled

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

11.3.0
Source
npmnpm
Version published
Weekly downloads
921K
-5.99%
Maintainers
1
Weekly downloads
 
Created

What is testcontainers?

The testcontainers npm package is a library that provides lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container. It is primarily used for integration testing, allowing developers to run tests against real instances of services without the overhead of managing those services manually.

What are testcontainers's main functionalities?

Running a PostgreSQL container

This feature allows you to run a PostgreSQL container for testing purposes. The code sample demonstrates how to start a PostgreSQL container with a specified password and expose the default port.

const { GenericContainer } = require('testcontainers');
(async () => {
  const container = await new GenericContainer('postgres')
    .withEnv('POSTGRES_PASSWORD', 'password')
    .withExposedPorts(5432)
    .start();
  console.log(`PostgreSQL started on port ${container.getMappedPort(5432)}`);
})();

Running a Redis container

This feature allows you to run a Redis container for testing purposes. The code sample demonstrates how to start a Redis container and expose the default port.

const { GenericContainer } = require('testcontainers');
(async () => {
  const container = await new GenericContainer('redis')
    .withExposedPorts(6379)
    .start();
  console.log(`Redis started on port ${container.getMappedPort(6379)}`);
})();

Running a custom Docker container

This feature allows you to run any custom Docker container for testing purposes. The code sample demonstrates how to start a custom Docker container and expose a specified port.

const { GenericContainer } = require('testcontainers');
(async () => {
  const container = await new GenericContainer('your-custom-image')
    .withExposedPorts(8080)
    .start();
  console.log(`Custom container started on port ${container.getMappedPort(8080)}`);
})();

Other packages similar to testcontainers

Keywords

testcontainers

FAQs

Package last updated on 18 Jul 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts