Use a dynamic port for the test-http-api to avoid conflicts

Pick a free port at config load time using a TCP probe on port 0, inject
it into the Vite dev server via VITE_TEST_HTTP_API_PORT, and have
globalSetup start the test-http-api on the same port. The frontend
reads the env var at build time instead of the previously hardcoded 8081.
This commit is contained in:
Rūdolfs Ošiņš
2026-03-23 10:59:39 -06:00
parent 293f6adb52
commit cf40e86a8e
4 changed files with 27 additions and 11 deletions
+8 -5
View File
@@ -49,11 +49,14 @@ async function withTestBackend<T>(
}
});
} else {
return fetch(`http://127.0.0.1:8081/${cmd}`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(args),
}).then(async response => {
return fetch(
`http://127.0.0.1:${import.meta.env.VITE_TEST_HTTP_API_PORT ?? 8081}/${cmd}`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(args),
},
).then(async response => {
if (response.status === 404) {
console.log("Got a 404 response:", response);
return null;