mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-01-30 06:12:03 +00:00
- Added `dev:test` script to package.json for streamlined testing without file watching. - Introduced `kill-test-servers` script to ensure no existing servers are running on test ports before executing tests. - Enhanced Playwright configuration to use mock agent for tests, ensuring consistent API responses and disabling rate limiting. - Updated various test files to include authentication steps and handle login screens, improving reliability and reducing flakiness in tests. - Added `global-setup` for e2e tests to ensure proper initialization before test execution.
45 lines
1.3 KiB
JavaScript
45 lines
1.3 KiB
JavaScript
/**
|
|
* Kill any existing servers on test ports before running tests
|
|
* This ensures the test server starts fresh with the correct API key
|
|
*/
|
|
|
|
import { exec } from 'child_process';
|
|
import { promisify } from 'util';
|
|
|
|
const execAsync = promisify(exec);
|
|
|
|
const SERVER_PORT = process.env.TEST_SERVER_PORT || 3008;
|
|
const UI_PORT = process.env.TEST_PORT || 3007;
|
|
|
|
async function killProcessOnPort(port) {
|
|
try {
|
|
const { stdout } = await execAsync(`lsof -ti:${port}`);
|
|
const pids = stdout.trim().split('\n').filter(Boolean);
|
|
|
|
if (pids.length > 0) {
|
|
console.log(`[KillTestServers] Found process(es) on port ${port}: ${pids.join(', ')}`);
|
|
for (const pid of pids) {
|
|
try {
|
|
await execAsync(`kill -9 ${pid}`);
|
|
console.log(`[KillTestServers] Killed process ${pid}`);
|
|
} catch (error) {
|
|
// Process might have already exited
|
|
}
|
|
}
|
|
// Wait a moment for the port to be released
|
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
}
|
|
} catch (error) {
|
|
// No process on port, which is fine
|
|
}
|
|
}
|
|
|
|
async function main() {
|
|
console.log('[KillTestServers] Checking for existing test servers...');
|
|
await killProcessOnPort(Number(SERVER_PORT));
|
|
await killProcessOnPort(Number(UI_PORT));
|
|
console.log('[KillTestServers] Done');
|
|
}
|
|
|
|
main().catch(console.error);
|