Files
back_end_oudelaa/scripts/run-isolated-e2e.js
boutmoun123 674fa77975
API Gateway CI / Build, lint, and test (push) Successful in 14m54s
API Gateway CI / Build API Gateway image (push) Successful in 6m31s
API Gateway CI / Build Notification Service image (push) Successful in 49s
feat: add Music World backend APIs for Flutter
2026-11-22 14:20:32 +03:00

52 lines
2.9 KiB
JavaScript

// Run HTTP smoke tests against a private MongoDB replica set, never the app database.
const { spawn } = require('node:child_process');
const { mkdtempSync } = require('node:fs');
const { tmpdir } = require('node:os');
const { join, resolve } = require('node:path');
const { createServer } = require('node:net');
const { createConnection } = require('mongoose');
async function main() {
const args = process.argv.slice(2);
const coverage = args[0] === '--coverage';
const server = createServer();
await new Promise((done) => server.listen(0, '127.0.0.1', done));
const port = server.address().port;
await new Promise((done, reject) => server.close((error) => error ? reject(error) : done()));
const directory = mkdtempSync(join(tmpdir(), 'oudelaa-full-e2e-'));
const mongo = spawn(process.env.MONGOD_BINARY || 'mongod', [
'--dbpath', directory, '--port', String(port), '--bind_ip', '127.0.0.1',
'--replSet', 'auditTest', '--logpath', join(directory, 'mongo.log'),
], { windowsHide: true, stdio: 'ignore' });
let bootstrap;
let child;
try {
await new Promise((done, reject) => { mongo.once('spawn', done); mongo.once('error', reject); });
const uri = `mongodb://127.0.0.1:${port}/oudelaa_isolated_e2e`;
bootstrap = createConnection(`${uri}?directConnection=true`, { serverSelectionTimeoutMS: 30000 });
await bootstrap.asPromise();
await bootstrap.db.admin().command({ replSetInitiate: { _id: 'auditTest', members: [{ _id: 0, host: `127.0.0.1:${port}` }] } });
await bootstrap.close();
const runner = coverage ? ['--coverage', ...args.slice(1)] : ['--config', 'test/jest-e2e.json', ...args];
child = spawn(process.execPath, [resolve('node_modules/jest/bin/jest.js'), '--runInBand', ...runner], {
windowsHide: true, stdio: 'inherit',
env: coverage ? { ...process.env, E2E_MONGODB_URI: `${uri}?replicaSet=auditTest`, MUSIC_WORLD_COVERAGE: '1' } :
{ ...process.env, E2E_MONGODB_URI: `${uri}?replicaSet=auditTest`,
MARKETPLACE_INTEGRATION: '1',
NOTIFICATION_SERVICE_ENABLED: 'false', OUTBOX_DISPATCHER_ENABLED: 'false', AI_MUSIC_ENABLED: 'false', FCM_ENABLED: 'false',
SEARCH_ENGINE: 'regex', RESPONSE_ENVELOPE_ENABLED: 'false', IMAGE_PROCESSING_ENABLED: 'false',
VIDEO_PROCESSING_ENABLED: 'false', AUDIO_PROCESSING_ENABLED: 'false' },
});
process.exitCode = await new Promise((done, reject) => { child.once('exit', (code) => done(code ?? 1)); child.once('error', reject); });
} finally {
if (child && child.exitCode === null && child.signalCode === null) child.kill();
if (bootstrap) await bootstrap.close();
if (mongo.pid && mongo.exitCode === null && mongo.signalCode === null) {
const stopped = new Promise((done) => mongo.once('exit', done));
mongo.kill();
await stopped;
}
}
}
main().catch((error) => { console.error(error.message); process.exitCode = 1; });