Skip to content

Instantly share code, notes, and snippets.

@timorthi
Last active October 22, 2020 18:31
Show Gist options
  • Save timorthi/13228a9ec10de4f9bbe486c0c864c7ba to your computer and use it in GitHub Desktop.
Save timorthi/13228a9ec10de4f9bbe486c0c864c7ba to your computer and use it in GitHub Desktop.
LeaseLock Engineering: Mocha Parallel Mode globalFixtures.js example
const path = require('path');
const dockerCompose = require('docker-compose');
const { getDbConnection } = require('../db_connections');
const PATH_TO_DOCKER_COMPOSE_YML = path.join(__dirname);
exports.mochaGlobalSetup = async () => {
// Bring up the Postgres container for testing
await dockerCompose.upAll({ cwd: PATH_TO_DOCKER_COMPOSE_YML });
// Fetch a DB connection to the Postgres container's leaselock_template database which was pre-configured in the docker-compose.yml
const dbConnection = await getDbConnection({
host: 'localhost',
port: 5432,
database: 'leaselock_template'
}); // Returns a knex instance
// Run all migrations on the `leaselock_template` database so its schema is up to date
await dbConnection.migrate.latest();
}
exports.mochaGlobalTeardown = async () => {
// Bring down the container once the tests finish running
await dockerCompose.down({ cwd: PATH_TO_DOCKER_COMPOSE_YML });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment