diff --git a/backend/package.json b/backend/package.json index 07ef3a74..377f58f3 100644 --- a/backend/package.json +++ b/backend/package.json @@ -7,7 +7,7 @@ "main": "dist/app.js", "scripts": { "build": "cross-env NODE_ENV=production tsc --build", - "predev": "cross-env cd .. && npm run build && cd backend", + "predev": "tsc --build ../common/tsconfig.json", "dev": "cross-env NODE_ENV=development tsx tool/seed.ts && tsx watch --env-file=.env.development.local src/app.ts", "start": "cross-env NODE_ENV=production node --env-file=.env dist/app.js", "format": "prettier --write src/", diff --git a/frontend/tests/setup-backend.ts b/frontend/tests/setup-backend.ts index 36671088..722accb5 100644 --- a/frontend/tests/setup-backend.ts +++ b/frontend/tests/setup-backend.ts @@ -1,6 +1,7 @@ import { spawn } from "child_process"; -import { ChildProcess } from "node:child_process"; +import { ChildProcess, execSync } from 'node:child_process'; +let wasRunningBefore: boolean; let backendProcess: ChildProcess; async function waitForEndpoint(url: string, delay = 1000, retries = 60): Promise { @@ -15,12 +16,14 @@ async function waitForEndpoint(url: string, delay = 1000, retries = 60): Promise } export async function setup(): Promise { - // Spin up the database - spawn("docker", ["compose", "up", "db", "--detach"], { - cwd: "..", - stdio: "inherit", - }); + // Check if the database container is already running + const containerCheck = execSync("docker ps --filter 'name=db' --format '{{.Names}}'"); + wasRunningBefore = !(containerCheck.toString().includes("db")); + // Spin up the database + execSync("docker compose up db --detach"); + + // Spin up the backend backendProcess = spawn("npm", ["run", "dev"], { cwd: "../backend", stdio: "inherit", @@ -35,8 +38,10 @@ export async function teardown(): Promise { backendProcess.kill(); } - spawn("docker", ["compose", "down"], { - cwd: "..", - stdio: "inherit", - }); + if (wasRunningBefore) { + spawn("docker", ["compose", "down"], { + cwd: "..", + stdio: "inherit", + }); + } }