import { exec } from 'child_process'; import * as path from 'path'; import { DockerComposeEnvironment, Wait } from 'testcontainers'; export default async () => { const composeFilePath = path.resolve(__dirname, '../environment/e2e'); const environment = await new DockerComposeEnvironment( composeFilePath, 'docker-compose.yaml', ) .withWaitStrategy('postgres_1', Wait.forHealthCheck()) .up(); // Store the environment details for teardown (global as any).__TESTCONTAINERS_ENVIRONMENT__ = environment; // Run migrations await new Promise((resolve, reject) => { console.info("running migration") exec( 'env && npm run migration:run', { env: { ...process.env, ...readEnvFile() } }, (err, stdout, stderr) => { if (err) { console.error(stderr); return reject(err); } console.log(stdout); resolve(); }, ); }); }; function readEnvFile() { const fs = require('fs'); const dotenv = require('dotenv'); const envConfig = dotenv.parse(fs.readFileSync('.env.e2e')); return envConfig; }