54 lines
1.5 KiB
TypeScript
54 lines
1.5 KiB
TypeScript
import { spawn } from 'node:child_process';
|
|
import { mkdirSync } from 'node:fs';
|
|
import { prepareE2eDatabase, E2E_DATABASE_PATH, E2E_WORKFLOW_DATA_DIR } from './e2e-prepare';
|
|
|
|
const host = process.env.PLAYWRIGHT_HOST ?? '127.0.0.1';
|
|
const port = process.env.PLAYWRIGHT_PORT ?? '3400';
|
|
const baseURL = process.env.PLAYWRIGHT_BASE_URL ?? `http://${host}:${port}`;
|
|
const env: NodeJS.ProcessEnv = {
|
|
...process.env,
|
|
BETTER_AUTH_BASE_URL: baseURL,
|
|
BETTER_AUTH_SECRET: 'playwright-e2e-secret-playwright-e2e-secret',
|
|
BETTER_AUTH_TRUSTED_ORIGINS: baseURL,
|
|
DATABASE_URL: `file:${E2E_DATABASE_PATH}`,
|
|
HOSTNAME: host,
|
|
NEXT_PUBLIC_API_URL: '',
|
|
PORT: port,
|
|
SEC_USER_AGENT: 'Fiscal Clone Playwright <support@fiscal.local>',
|
|
WORKFLOW_LOCAL_DATA_DIR: E2E_WORKFLOW_DATA_DIR,
|
|
WORKFLOW_LOCAL_QUEUE_CONCURRENCY: '1',
|
|
WORKFLOW_TARGET_WORLD: 'local'
|
|
};
|
|
|
|
delete env.NO_COLOR;
|
|
|
|
prepareE2eDatabase();
|
|
mkdirSync(E2E_WORKFLOW_DATA_DIR, { recursive: true });
|
|
|
|
const child = spawn(
|
|
'bun',
|
|
['--bun', 'next', 'dev', '--turbopack', '--hostname', host, '--port', port],
|
|
{
|
|
stdio: 'inherit',
|
|
env
|
|
}
|
|
);
|
|
|
|
function forwardSignal(signal: NodeJS.Signals) {
|
|
if (!child.killed) {
|
|
child.kill(signal);
|
|
}
|
|
}
|
|
|
|
process.on('SIGINT', () => forwardSignal('SIGINT'));
|
|
process.on('SIGTERM', () => forwardSignal('SIGTERM'));
|
|
|
|
child.on('exit', (code, signal) => {
|
|
if (signal) {
|
|
process.exit(signal === 'SIGINT' || signal === 'SIGTERM' ? 0 : 1);
|
|
return;
|
|
}
|
|
|
|
process.exit(code ?? 0);
|
|
});
|