in src/jest/global_setup.ts [36:67]
export default async () => {
const name = `las_test_container_${Math.random()
.toString(36)
.substring(2, 5)}`;
logger.debug(`initializing container "${name}"`);
const container = await new GenericContainer('postgres')
.withName(name)
.withExposedPorts(5432)
.withEnv('POSTGRES_USER', 'postgres')
.withEnv('POSTGRES_PASSWORD', 'postgres')
.withEnv('POSTGRES_DB', 'postgres')
.start();
// We have to use global setup because it's the only way in Jest to run code once before suite.
// Unfortuantely Jest prevents us from writing globals that are read by the sutite.
// So, we are forced to write the connection info to the ENV.
process.env.PGUSER =
process.env.PGPASSWORD =
process.env.PGDATABASE =
'postgres';
process.env.PGHOST = container.getHost();
process.env.PGPORT = `${container.getMappedPort(5432)}`;
const conn = new Pool();
await awaitDbConnection(conn);
await runDbMigrations(conn);
conn.end();
dbGlobal.__POSTGRES__ = container;
};