fix(frontend): Controller tests slagen
This commit is contained in:
parent
b90c326b5a
commit
e4945fac66
2 changed files with 16 additions and 11 deletions
|
@ -7,7 +7,7 @@
|
||||||
"main": "dist/app.js",
|
"main": "dist/app.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "cross-env NODE_ENV=production tsc --build",
|
"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",
|
"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",
|
"start": "cross-env NODE_ENV=production node --env-file=.env dist/app.js",
|
||||||
"format": "prettier --write src/",
|
"format": "prettier --write src/",
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { spawn } from "child_process";
|
import { spawn } from "child_process";
|
||||||
import { ChildProcess } from "node:child_process";
|
import { ChildProcess, execSync } from 'node:child_process';
|
||||||
|
|
||||||
|
let wasRunningBefore: boolean;
|
||||||
let backendProcess: ChildProcess;
|
let backendProcess: ChildProcess;
|
||||||
|
|
||||||
async function waitForEndpoint(url: string, delay = 1000, retries = 60): Promise<void> {
|
async function waitForEndpoint(url: string, delay = 1000, retries = 60): Promise<void> {
|
||||||
|
@ -15,12 +16,14 @@ async function waitForEndpoint(url: string, delay = 1000, retries = 60): Promise
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function setup(): Promise<void> {
|
export async function setup(): Promise<void> {
|
||||||
// Spin up the database
|
// Check if the database container is already running
|
||||||
spawn("docker", ["compose", "up", "db", "--detach"], {
|
const containerCheck = execSync("docker ps --filter 'name=db' --format '{{.Names}}'");
|
||||||
cwd: "..",
|
wasRunningBefore = !(containerCheck.toString().includes("db"));
|
||||||
stdio: "inherit",
|
|
||||||
});
|
|
||||||
|
|
||||||
|
// Spin up the database
|
||||||
|
execSync("docker compose up db --detach");
|
||||||
|
|
||||||
|
// Spin up the backend
|
||||||
backendProcess = spawn("npm", ["run", "dev"], {
|
backendProcess = spawn("npm", ["run", "dev"], {
|
||||||
cwd: "../backend",
|
cwd: "../backend",
|
||||||
stdio: "inherit",
|
stdio: "inherit",
|
||||||
|
@ -35,8 +38,10 @@ export async function teardown(): Promise<void> {
|
||||||
backendProcess.kill();
|
backendProcess.kill();
|
||||||
}
|
}
|
||||||
|
|
||||||
spawn("docker", ["compose", "down"], {
|
if (wasRunningBefore) {
|
||||||
cwd: "..",
|
spawn("docker", ["compose", "down"], {
|
||||||
stdio: "inherit",
|
cwd: "..",
|
||||||
});
|
stdio: "inherit",
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue