From 99486368b27a9fab90eb5f676ed1bb4246e8358b Mon Sep 17 00:00:00 2001 From: arsam Date: Fri, 18 Sep 2026 23:09:32 +0330 Subject: [PATCH] Import tests: backend/tests/e2e/globalSetup Import the existing local project snapshot. This commit organizes existing files; it does not represent newly developed functionality. --- backend/tests/e2e/globalSetup.ts | 53 ++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 backend/tests/e2e/globalSetup.ts diff --git a/backend/tests/e2e/globalSetup.ts b/backend/tests/e2e/globalSetup.ts new file mode 100644 index 0000000..849a2eb --- /dev/null +++ b/backend/tests/e2e/globalSetup.ts @@ -0,0 +1,53 @@ +import { startMockServer } from "./mock-server.js"; +import http from "http"; + +let server: http.Server | null = null; + +export default async function setup() { + const defaultUrl = process.env.API_URL || "http://localhost:3001"; + let useLocalMock = false; + + try { + // Send a health check request with a timeout + const controller = new AbortController(); + const timeoutId = setTimeout(() => controller.abort(), 1000); + + const res = await fetch(`${defaultUrl}/health`, { signal: controller.signal }); + clearTimeout(timeoutId); + + if (res.ok) { + const data = await res.json() as any; + // If port 3001 is running the Nova bot, or doesn't match coaxys panel body + if (data && data.agent === "Nova") { + useLocalMock = true; + } + } else { + useLocalMock = true; + } + } catch { + useLocalMock = true; + } + + if (useLocalMock) { + const mockPort = 3009; + server = startMockServer(mockPort); + process.env.API_URL = `http://localhost:${mockPort}`; + console.log(`[E2E Setup] CoaxysPanel mock backend server started on port ${mockPort}`); + } else { + process.env.API_URL = defaultUrl; + console.log(`[E2E Setup] Testing against existing API_URL: ${process.env.API_URL}`); + } + + // Teardown hook executed by Vitest after all tests complete + return async () => { + if (server) { + await new Promise((resolve, reject) => { + server!.close((err) => { + if (err) reject(err); + else resolve(); + }); + }); + console.log("[E2E Teardown] CoaxysPanel mock backend server stopped"); + } + }; +}