Files
arrr-erp-test-v2/fixtures/global-setup.js
T
2026-06-22 12:52:00 +05:30

26 lines
957 B
JavaScript

const { spawn } = require('child_process');
const fs = require('fs');
const path = require('path');
require('dotenv').config();
module.exports = async () => {
fs.mkdirSync(path.resolve('results'), { recursive: true });
if (process.env.START_ERP !== 'true') return;
const cwd = process.env.ERP_WORKDIR;
const cmd = process.env.ERP_COMMAND || 'uvicorn app.main:app --reload';
const child = spawn(cmd, { cwd, shell: true, env: process.env });
global.__ERP_PROCESS__ = child;
const logFile = path.resolve('results/erp-console.log');
fs.writeFileSync(logFile, '');
const append = (buf) => {
const text = buf.toString();
fs.appendFileSync(logFile, text);
const otp = text.match(/\[DEV OTP\].*?code=(\d{4,8})/i);
if (otp) fs.writeFileSync(path.resolve('results/current-otp.txt'), otp[1]);
};
child.stdout.on('data', append);
child.stderr.on('data', append);
await new Promise((resolve) => setTimeout(resolve, 5000));
};