Files
paseo/packages/desktop/scripts/dev-runner-readiness.test.mjs
Mohamed Boudra 836f1a9c23 fix(ci): consolidate E2E repairs and wait for Metro readiness (#4858)
* fix(desktop): wait for Metro HTTP readiness before launching Electron

Expo briefly listens while probing port availability. A successful TCP connection can therefore launch Electron before Metro starts and leave it exiting on connection refusal. Require the configured renderer origin to report the running packager status.

* test(ci): consolidate fixture and readiness corrections

Await the connection and UI states each journey owns, isolate Git fixture contents before observation, and hold real Markdown frames at asserted checkpoints. Keep creation completion diagnostics explicit without claiming the original Windows failure is fixed.

* test(desktop): describe Metro readiness through HTTP states

Keep protocol mechanics in the fixture and assert readiness only after a successful packager response. Cover non-success status and unrelated HTTP content without inline synchronization in the test body.
2026-09-14 21:25:38 +02:00

42 lines
1.3 KiB
JavaScript

import http from "node:http";
import { expect, test } from "vitest";
import { waitForMetro } from "./dev-runner-readiness.mjs";
async function startMetroStatusServer(responses) {
let lastResponse = null;
let nextResponse = 0;
const server = http.createServer((request, response) => {
const reply = responses[Math.min(nextResponse++, responses.length - 1)];
lastResponse = { path: request.url, ...reply };
response.writeHead(reply.status);
response.end(reply.body);
});
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
return {
url: `http://127.0.0.1:${server.address().port}`,
lastResponse: () => lastResponse,
async close() {
server.closeAllConnections();
await new Promise((resolve) => server.close(resolve));
},
};
}
test("Metro readiness rejects an unrelated listener before accepting the packager status", async () => {
const metro = await startMetroStatusServer([
{ status: 503, body: "packager-status:running" },
{ status: 200, body: "unrelated HTTP server" },
{ status: 200, body: "packager-status:running" },
]);
try {
await waitForMetro(metro.url, 2_000);
expect(metro.lastResponse()).toEqual({
path: "/status",
status: 200,
body: "packager-status:running",
});
} finally {
await metro.close();
}
});