Home

Awesome

ava-fixture-docker-db

acquire a fresh docker database container attached to your ava test context

JavaScript Style Guide semantic-release Greenkeeper badge CircleCI

usage

import ava, { TestInterface } from 'ava'
import { db, DbContext } from 'ava-fixture-docker-db'

const test = ava as TestInterface<DbContext>

test.beforeEach(t => db.setup(t.context)) // setup(context, dbOptions, dockerodeOptions)
test.afterEach(t => db.teardown(t.context))

test('some that needs a db!', async t => {
  t.is(t.context.dbConfig.username, 'postgres', 'has default postgres user')
  const containerData = await t.context.dbContainer.inspect()
  t.truthy(containerData.Image, 'has docker image')
  t.is(containerData.State.Status, 'running', 'db is running')
  t.is(Object.keys(containerData.HostConfig.PortBindings).length, 1, 'has host port exposed')
})

see the exported typescript typings or source for the simple additional APIs you can use in setup.