Gathering detailed insights and metrics for docker-compose-testkit
Gathering detailed insights and metrics for docker-compose-testkit
Gathering detailed insights and metrics for docker-compose-testkit
Gathering detailed insights and metrics for docker-compose-testkit
docker-compose
Manage docker-compose from Node.js
dockerode
Docker Remote API module.
sentry-testkit
Sentry Testkit enables Sentry to work natively in your application while running tests. The report is not really sent but rather logged locally into memory. In this way, the logged reports can be fetched for your own verification or any other purpose in y
@amplication/plugin-db-mongo
Use a Mongo database in a service generated by Amplication
npm install docker-compose-testkit
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
1 Stars
56 Commits
3 Forks
1 Watching
2 Branches
3 Contributors
Updated on 09 Oct 2024
TypeScript (97.99%)
JavaScript (2.01%)
Cumulative downloads
Total Downloads
Last day
-30.2%
88
Compared to previous day
Last week
-24.7%
1,266
Compared to previous week
Last month
55.4%
7,354
Compared to previous month
Last year
118.3%
69,786
Compared to previous year
19
A library designed for TDD while leveraging docker compose.
docker-compose-testkit
helps writing tests by automating the creation and deletions of docker compose environments via test code.
Each test suite (or test!), may create it's own isolated compose network to test against, helping create stronger tests.
The library can work with any test runner, or just via code, the only requirement is docker compose v2 installed on the machine.
1$ npm i --save-dev docker-compose-testkit
Or alternatively
1$ yarn add -D docker-compose-testkit
Given the following docker-compose.yml
file
1version: '3' 2services: 3 nginx: 4 image: nginx:latest 5 ports: 6 - 80
The following test will up the network before all the tests, and tear it down once the tests finish
1import path from 'path' 2import {fileURLToPath} from 'url' 3import dockerCompose from 'docker-compose-testkit' 4 5describe('testing using docker compose', () => { 6 const pathToCompose = path.join( 7 path.dirname(fileURLToPath(import.meta.url)), 8 'docker-compose.yml', 9 ) 10 const compose = dockerCompose(pathToCompose) 11 12 beforeAll(compose.setup) 13 afterAll(compose.teardown) 14 15 it('should send a request to nginx', async () => { 16 // translates the internal address (i.e. nginx:80) to host's (e.g. 0.0.0.0:23424) 17 const nginxAddress = await compose.getAddressForService('nginx', 80) 18 expect((await fetch(`http://${nginxAddress}/`)).ok).to.be.true() 19 }) 20})
Creates the compose object that will manage the network, once it is set up.
Specific options to set for the network and containers
servicesToStart: string[]
- A list of cherry-picked services to start with the network (default: everything).
tailServices: string
- Name of a service to start tailing its logs immediately, logs will be printed to stdout regardless of the original file descriptor.
projectName: string
- Can be used to reconnect to an existing network from a previous run.
env: object
- Key value object that will set the environment variables for the compose commands, by default containers will not have access to the host's env vars.
orphanCleanup: boolean
- Wether or not to perform cleanup for containers that might have been left by a previous run (default true
).
cleanup: boolean
- Wether or not to perform a cleanup of the network after the test complete (disables the teardown) (default: true
).
pullImages: boolean
- Attempt to pull the images prior to docker compose up
(default: false
).
forceKill: boolean
- Send a SIGKILL
to all containers before running docker compose down
, this can speed up the teardown significantly (default: true
).
containerRetentionInMinutes: number
- How long to keep this network from being picked up by the orphan cleanup, use alongside with cleanup: false
to retain a network for debugging purposes (default: 5 minutes).
Returns Promise<Compose>
.
A string representing the generated docker compose project name, pass it again to dockerCompose(pathToCompose, {projectName})
to reconnect to an existing network.
The path to the compose file as given to the dockerCompose(pathToCompose)
Runs cleanup for orphaned containers, networks and volumes. And then starts up the new network.
Returns Promise
.
Tears down the current network.
Returns Promise
.
Translates the internal address of a given service to the exposed one on the host's machine. For example nginx:80
to 0.0.0.0:52736
.
The function will attempt to contact the service (similarly to Kubernetes liveness probe), to gauge wether the service is ready to accept connections.
Returns Promise<string>
healthCheck: undefined | false | string | (address, AbortError) => Promise<void>
- A custom health check function that will be retried to gauge when the service is ready to be used.
undefined
is the default, will attempt to send a GET request to /
.false
disables the health check, the function will return with the address as normal.string
changes the path of the GET request, can be used for /healthz
.function
a custom function that defines the health check, it will be retried automatically, unless an AbortError
is sent. Functions arguments:
fiveHundedStatusIsOk: boolean
- Wether to consider >500
status codes as healthy (default: false
).
maxRetries: number
- How many times to retry the health check, the retries have exponential backoff (default: 10
).
Translates the inernal hostname (i.e. nginx
) to the internal network IP, for example 172.17.0.1
.
Returns Promise<string>
.
Gets a list of the containers in the network.
Returns Promise<Container[]>
.
Checks if a container exists for a specific service.
Returns Promise<boolean>
.
Returns all the logs by a given service name, stdout
and stderr
will be interleaved.
Returns Promise<string>
Waits for a running service to finish and exit.
Returns Promise
anyExitCode: boolean
- Wether to throw if the exit code is not 0
(default: false
).
timeout: number
- Total timeout to wait for in milliseconds (default: 5 minutes).
Runs a one-off command in a service (e.g. docker compose run
).
commandWithArgs
- An array of the command and arguments for it.
Returns Promise<ExecaReturnValue>
Starts a service in the network (e.g. docker compose start
).
Returns Promise
.
Stops a service in the network (e.g. docker compose stop
).
Returns Promise
.
Pauses a service in the network (e.g. docker compose pause
).
Returns Promise
.
Unpauses a service in the network (e.g. docker compose unpause
).
Returns Promise
.
No vulnerabilities found.
No security vulnerabilities found.