Files
test-assignment/scripts/test-database.mjs
T

23 lines
1.0 KiB
JavaScript

import { spawnSync } from 'node:child_process';
const mode = process.argv[2];
if (!['integration', 'browser'].includes(mode)) throw new Error('Choose integration or browser');
// This dedicated service is intentionally independent of the development database.
const env = {
...process.env,
DATABASE_URL: 'postgresql://merchantflow:merchantflow_local@localhost:55441/merchantflow_test',
API_PORT: '3002',
WEB_PORT: '5174',
APP_ORIGIN: 'http://127.0.0.1:5174',
};
function run(command, args) {
const result = spawnSync(command, args, { stdio: 'inherit', env });
if (result.error) throw result.error;
if (result.status !== 0) process.exit(result.status ?? 1);
}
run('docker', ['compose', '--profile', 'test', 'up', '-d', '--wait', 'db-test']);
run('pnpm', ['exec', 'turbo', 'run', 'build']);
run('pnpm', ['--filter', '@merchantflow/database', 'migrate']);
run('pnpm', ['--filter', '@merchantflow/database', 'seed']);
if (mode === 'integration') run('node', ['--test', 'apps/api/test/integration.test.mjs']);
else run('pnpm', ['exec', 'playwright', 'test']);