test(frontend): Start backend automatisch op

This commit is contained in:
Tibo De Peuter 2025-04-16 22:03:35 +02:00
parent cbd214c445
commit 37be342137
Signed by: tdpeuter
GPG key ID: 38297DE43F75FFE2
2 changed files with 41 additions and 0 deletions

View file

@ -0,0 +1,39 @@
import { spawn } from 'child_process';
import { ChildProcess } from 'node:child_process';
let backendProcess: ChildProcess;
export async function setup(): Promise<void> {
// Spin up the database
spawn('docker', ['compose', 'up', 'db', '--detach'], {
cwd: '..',
stdio: "pipe",
});
backendProcess = spawn('npm', ['run', 'dev'], {
cwd: '../backend',
stdio: "pipe",
});
// Wait until you can curl the backend
let backendReady = false;
while (!backendReady) {
try {
await fetch('http://localhost:3000/api')
backendReady = true;
} catch (_) {
// Ignore the error
}
}
}
export async function teardown(): Promise<void> {
if (backendProcess) {
backendProcess.kill();
}
spawn('docker', ['compose', 'down'], {
cwd: '..',
stdio: "pipe"
});
}

View file

@ -9,6 +9,8 @@ export default mergeConfig(
environment: "jsdom",
exclude: [...configDefaults.exclude, "e2e/**"],
root: fileURLToPath(new URL("./", import.meta.url)),
// Startup the backend server, because it is needed for some tests
globalSetup: [ "./tests/setup-backend.ts" ]
},
}),
);