• Stars
    star
    122
  • Rank 292,031 (Top 6 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Jest preset for running docker containers with your tests

jest-testcontainers

Jest preset for running docker containers with your tests. Primary purpose is to make it possible to use any database in integration tests. Since it uses docker images, custom database images with different plugins/configurations can be used in the integration tests. Using testcontainers-node under the hood. Inspired by @shelf/jest-mongodb.

Build Status npm version

Usage

Install

Docker should be installed on your system. If running inside a CI pipeline, see FAQ.md.

npm install --save-dev @trendyol/jest-testcontainers

Edit Jest Config

On your jest.config.js add the project as the preset.

module.exports = {
  preset: '@trendyol/jest-testcontainers'
};

Declare Containers To Run

Create a file called jest-testcontainers-config.js and put it to root of your project, where you run npm test. If you would like to put this file somewhere else, you can use the JEST_TESTCONTAINERS_CONFIG_PATH environment variable to define a relative or absolute path. A sample configuration file;

module.exports = {
  redis: {
    image: 'redis',
    tag: 'alpine3.12',
    ports: [6379],
    env: {
      EXAMPLE: 'env',
    },
    wait: {
      type: 'text',
      text: 'Ready to accept connections'
    }
  },
//   more: {
//     image: 'any-docker-image', // postgresql, mongodb, neo4j etc.
//     ports: [1234, 4567], // ports to make accessible in tests
//   },
};

Connect To Containers

Every containers IP and Port info is registered to global variables to be used by your tests.

const redis = require('redis');
const { promisify } = require('util');

describe('testcontainers example suite', () => {
  let redisClient;

  beforeAll(() => {
    const redisConnectionURI = `redis://${global.__TESTCONTAINERS_REDIS_IP__}:${global.__TESTCONTAINERS_REDIS_PORT_6379__}`;
    redisClient = redis.createClient(redisConnectionURI);
    
    // if you have declared multiple containers, they will be available to access as well. e.g.
    // `global.__TESTCONTAINERS_${CONFIG_KEY}_IP__`
    // `global.__TESTCONTAINERS_${CONFIG_KEY}_PORT_${CONFIG_PORT}__`
  });

  afterAll(() => {
    redisClient.quit();
  });
  
  it('write should be ok', async () => {
    // Arrange
    const setAsync = promisify(redisClient.set).bind(redisClient);

    // Act
    const setResult = await setAsync('test', 73);

    // Assert
    expect(setResult).toEqual('OK');
  });
});

Documentation

Detailed documentation of the jest-testcontainers-config.js can be found at DOC.md.

Examples

  • examples/01-basic-redis showcases writing integration tests against Redis. You can use npm run build && npm run example:redis command to run this example locally.
  • examples/02-typescript-redis same test cases as in example #1. However using Typescript instead of JavaScript. You can use npm run build && npm run example:redis-typescript to run this example locally.
  • examples/03-docker-compose same test cases as examples #1 and #2, however using Docker Compose to build the container. You can use npm run build && npm run example:docker-compose to run this example locally.
  • Yengas/nodejs-postgresql-testcontainers showcases writing integration tests against PostgreSQL with schema migration and Typescript. You can check out the project page for more details.

Watch mode support

Starting with version 2.0.0 containers will not be stopped if Jest is started in watch mode. This greatly improves development productivity if your containers have a slow startup time (ex. Elasticsearch). This comes with the price that you have to be mindful that containers will be reused between watch test executions and you need to do proper cleanup in your after hooks.

If you want to disable this behavior you can set the JEST_TESTCONTAINERS_RESTART_ON_WATCH environment variable.

Wondering what will happen when those containers are not stopped when Jest is exited - testcontainer's ryuk will take care of them.

License

This project is licensed under the MIT License

More Repositories

1

baklava

Baklava is a design system provided by Trendyol to create a consistent UI/UX for app users.
TypeScript
1,250
star
2

mobile-app-automizer

You can automize iOS and Android app's build, upload and versioning processes via Mobile App Automizer CLI tool.
JavaScript
576
star
3

medusa

Android fragment stack controller
Kotlin
483
star
4

docker-shell

A simple interactive prompt for docker
Go
391
star
5

android-guidelines

Architecture and code guidelines at Trendyol when developing for Android.
FreeMarker
388
star
6

kink

KinK is a helper CLI that facilitates to manage KinD clusters as Kubernetes pods. Designed to ease clusters up for fast testing with batteries included in mind.
Go
375
star
7

react-carousel

Lightweight carousel component for react
TypeScript
293
star
8

gaos

HTTP mocking to test API services for chaos scenarios
Go
214
star
9

android-ui-components

Useful UI Components for Android Projects.
Kotlin
201
star
10

BubbleScrollBar

Kotlin
195
star
11

kediatR

Mediator implementation in Kotlin with native coroutine support
Kotlin
180
star
12

kafka-konsumer

Easy implementation of kafka consumer with built-in exception manager (kafka-cronsumer)
Go
147
star
13

stove

Stove: The easiest way of writing e2e tests for your JVM back-end API with Kotlin
Kotlin
146
star
14

mockingstar

Request mocking tool designed to simplify the process of http request mocking, network debugging, and UI tests for your applications.
Swift
144
star
15

four-key

four-key is a measurement tool written with golang for your repositories. This project inspired from Accelerate book.
Go
123
star
16

ios-components

Swift
112
star
17

kubectl-view-webhook

๐Ÿ‘€ โ€ผ๏ธ This projects aims to visualize critical parts of the admission webhook configuration resource
Go
108
star
18

android-dev-tools

Android QA/Debug tools to speed up and streamline the development progress.
Kotlin
104
star
19

ios-guidelines

95
star
20

kubectl-easy-rollback

โ™ป๏ธ Now you can easily rollback to previous deployed images whatever you want on k8s environment
Go
93
star
21

Jdempotent

Make your consumer, API, etc. idempotent easily.
Java
89
star
22

baklava-react-native

TypeScript
89
star
23

go-dcp

The Go implementation of the Couchbase DCP with various features
Go
85
star
24

quarkify

An awesome lightweight React UI Component library
TypeScript
83
star
25

perfanalytics

Web Performance Metrics
TypeScript
82
star
26

go-dcp-elasticsearch

The Go implementation of the Couchbase to Elasticsearch with DCP.
Go
74
star
27

kafka-cronsumer

Cron based Kafka exception consumer with the power of auto retry & concurrency
Go
68
star
28

go-dcp-kafka

The Go implementation of the Couchbase to Kafka with DCP.
Go
67
star
29

ios-architecture-decision-logs

62
star
30

gurubu

Simple, Fast, and Practical Task Estimation and Tech Grooming. Live demo below ๐Ÿ‘‡
TypeScript
59
star
31

Transporter

Transporter is an open-source data transferring tool developed by Trendyol with love ๐Ÿงก
C#
50
star
32

code-playground

CodePlayground is a playground tool for go and rust language.
Go
46
star
33

mockingstar-ios

Mocking Star SPM helper library for iOS applications.
Swift
46
star
34

dom-event-tracker

Dynamically tracks mutations and listens for click and seen events
JavaScript
45
star
35

overlog

Golang Logging with Mapped Diagnostic Context
Go
42
star
36

sidecache

Sidecar cache for kubernetes applications.
Go
42
star
37

boru

Boru is a pipeline solution
Kotlin
38
star
38

mockingstar-android

Mocking Star Kotlin helper library for Android applications.
Kotlin
38
star
39

go-dcp-couchbase

The Go implementation of the Couchbase to Couchbase with DCP.
Go
37
star
40

Loki

Loki provides an easy way to handle locking scenarios on distributed systems.
C#
35
star
41

kafka-shovel

Go
35
star
42

wolfichef

Secure image creator with wolfi packages.
Go
33
star
43

cbef

GitOps Capability Provider for Couchbase Eventing Functions ๐Ÿš€
Go
33
star
44

Trendyol.App

Application wrapper.
C#
30
star
45

supra

Circuit breaking http client for NodeJs. And it is fast...
JavaScript
30
star
46

k8s-webhook-certificator

๐Ÿ” ๐Ÿ—’๏ธ Creating K8S Secret which type is TLS that includes corresponding client certificates which are signed by K8S CA and private key
Go
30
star
47

MapsKit

Kotlin
28
star
48

trendyol.github.io

This repository contains the source of the http://trendyol.github.io
HTML
26
star
49

nodejs-logger

Generic NodeJs Logger for storefront applications
TypeScript
25
star
50

pollgroo

TypeScript
25
star
51

swagger-parser-burp-extension

Python
25
star
52

kafka2rabbit

Kafka to rabbit go application
Go
24
star
53

teg

Teg is a library for managing feature toggles. It aims to allow to create and access to feature toggles in Golang easily and quickly!
Go
22
star
54

Osiris

Osiris, lord of the dead and rebirth
Kotlin
20
star
55

AppSec

Java
19
star
56

smurfs

Easy way to build Micro-CLI Architecture for Developer Platform Teams
Go
18
star
57

trendyol-scheduler-service

Java
18
star
58

ios-tuist-remote-cache-example

๐Ÿ“ฆ๐Ÿ“ฑ Example of Vapor app built using the tuist remote cache feature.
Swift
18
star
59

kafka-wrapper

Go
18
star
60

kafka-retry-job

Kafka Retry Job is an open-source project for moving Kafka messages from error topics to retry topics, developed by Trendyol with love ๐Ÿงก
C#
16
star
61

kubernetes-operator-api

The Kubernetes API is a sample Kubernetes operator API using the Java Kubernetes Client. The API is designed for master-worker deployment to satisfy the requirements.
Java
16
star
62

stately

Stately is a library for managing different states of a content in Jetpack Compose.
Kotlin
16
star
63

dynamic-render

๐Ÿ’ธ Optimizes SEO by dynamically rendering javascript powered websites
TypeScript
15
star
64

Confluent.Kafka

C#
14
star
65

safe-redirect

library which resolves open-redirection vulnerability when we need to make redirection to a path taken from query string.
TypeScript
14
star
66

kafkathena-jakarta

Java
14
star
67

react-intersection-images

React lazy load images with IntersectionObserver.
TypeScript
13
star
68

redis-slack-bot

Redis Slack Bot
Java
13
star
69

vault-plugin-database-yugabytedb

Go
12
star
70

network-status

Get network status of device
TypeScript
12
star
71

trendyol-consul-template-injector

๐Ÿณ This project is impletation of "Admission Webhook Controller" of k8s , made possible to inject consul-template image as a init and sidecar container.
Go
12
star
72

react-webcomponent-poc

Using Web Components API with React. A POC and a case study.
TypeScript
11
star
73

micro-trendyol

A Micro Trendyol designed by using Hexagonal Architecture + DDD + CQRS + SAGA
11
star
74

metrics

Export four key metrics of your repositories in CSV format
Go
11
star
75

otel-kafka-konsumer

open telemetry wrapper for kafka-go and kafka-konsumer
Go
11
star
76

kube-port-finder

kube-pf is a command line tool that find available ports on kubernetes
Go
11
star
77

debezium-with-smt

Java
10
star
78

consul-template-demo

Shell
10
star
79

codex

TypeScript
9
star
80

sonar-stryker-net-plugin

Java
9
star
81

dynamic-config-listener

Dynamic Config Listener
TypeScript
9
star
82

AutoFac.Extras.NLog.DotNetCore

Autofac Logging Module for NLog. Ported to .NET Standard 2.0 for .NET Core.
C#
8
star
83

go-future

Go routines with wait ability.
Go
8
star
84

verg

Semantic versioning CLI
Go
8
star
85

Commander-AS-Plugin

Kotlin
7
star
86

gomapper

An auto mapping tool for Golang DTOs
Go
6
star
87

CorrelationId

CorrelationId middleware for Dotnet projects
C#
6
star
88

ty-cookie-helper

simple cookie helper that provides functions to CRUD cookies
TypeScript
6
star
89

nodejs-fixture-repository

TypeScript
6
star
90

rate-limiting-with-ksql

Async Rate Limiting with ksqlDB
Java
6
star
91

openstack-swift-sdk

Openstack Swift SDK
TypeScript
6
star
92

kafkathena-commons

Smart, Fast, Customizable Consumer Configurations Common Utility Library
Java
6
star
93

mlflow-operator

Kubernetes Operator for MLflow
Go
6
star
94

apisix-plugins

Our downstream plugins (or modifications) for Apache APISIX.
Lua
5
star
95

infobip-client

Go
5
star
96

goncolos

Goncolos is simple wrapper top of confluent-kafka-dotnet
C#
4
star
97

express-validate-decorator

Validate expressjs request body and query.
TypeScript
4
star
98

ratelimit-operator

Istio rate limit operator
Go
4
star
99

wolfichef-fe

Wolfichef front-end project
Vue
4
star
100

jwt-generator

Java
4
star