From 196875538d2f022758452a7e8ad685712fb25639 Mon Sep 17 00:00:00 2001 From: Tibo De Peuter Date: Mon, 21 Apr 2025 12:34:46 +0200 Subject: [PATCH] fix(frontend): Selectieve testen in IDE --- frontend/package.json | 3 +-- frontend/src/config.ts | 5 +++++ frontend/tests/setup-backend.ts | 8 ++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/frontend/package.json b/frontend/package.json index 52997cb9..b6bd5deb 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -12,8 +12,7 @@ "format": "prettier --write src/", "format-check": "prettier --check src/", "lint": "eslint . --fix", - "pretest:unit": "tsx ../docs/api/generate.ts && npm run build", - "test:unit": "VITE_API_BASE_URL='http://localhost:9876/api' vitest --run", + "test:unit": "vitest --run", "test:e2e": "playwright test" }, "dependencies": { diff --git a/frontend/src/config.ts b/frontend/src/config.ts index 76e7545c..cff1d771 100644 --- a/frontend/src/config.ts +++ b/frontend/src/config.ts @@ -1,5 +1,10 @@ export const apiConfig = { baseUrl: ((): string => { + if (import.meta.env.MODE === "test") { + // TODO Remove hardcoding + return "http://localhost:9876/api"; + } + if (import.meta.env.VITE_API_BASE_URL) { return import.meta.env.VITE_API_BASE_URL; } diff --git a/frontend/tests/setup-backend.ts b/frontend/tests/setup-backend.ts index 71cc1480..d093fd57 100644 --- a/frontend/tests/setup-backend.ts +++ b/frontend/tests/setup-backend.ts @@ -16,14 +16,14 @@ async function waitForEndpoint(url: string, delay = 1000, retries = 60): Promise export async function setup(): Promise { // Precompile needed packages - spawnSync("npm", ["run", "predev"], { - cwd: "../backend", + spawnSync("npx", ["tsc", "--build", "tsconfig.json"], { + cwd: `../common`, stdio: "inherit", }); // Spin up the backend - backendProcess = spawn("tsx", ["--env-file=.env.test", "tool/startTestApp.ts"], { - cwd: "../backend", + backendProcess = spawn("npx", ["tsx", "--env-file=.env.test", "tool/startTestApp.ts"], { + cwd: `../backend`, stdio: "inherit", env: { ...process.env,