Files
open-design/scripts/resolve-dev-ports.mjs
shangxinyu1andGitHub 751c9de56d Add UI e2e automation suite and reporting (#64)
* test: add e2e ui automation suite

* fix review feedback for ui e2e suite
Resolved the FileWorkspace.tsx merge-marker issue and kept the intended combination of multiple, accept="image/*", and data-testid.
Updated the e2e port handling so the test config no longer relies on a single hardcoded app port. It now resolves an available port first and passes the same port selection through the dev server and Playwright base URL. Since main has moved to the Next.js dev stack, this was also adapted from the old Vite-based flow to NEXT_PORT.
Kept test:ui serialized so cleanup completes before Playwright starts.
Updated reset-e2e-artifacts.mjs so cleanup failures are surfaced with a warning instead of being silently swallowed, except for the expected ENOENT case.
2026-04-29 23:31:17 +08:00

48 lines
1.1 KiB
JavaScript

import net from 'node:net';
const HOST = '127.0.0.1';
const DEFAULT_PORT_SEARCH_RANGE = 50;
export function isPortFree(port, host = HOST) {
return new Promise((resolve) => {
const server = net.createServer();
server.unref();
server.once('error', () => resolve(false));
server.listen({ port, host, exclusive: true }, () => {
server.close(() => resolve(true));
});
});
}
export async function findFreePort(
start,
label,
{ host = HOST, searchRange = DEFAULT_PORT_SEARCH_RANGE } = {},
) {
for (let port = start; port < start + searchRange; port++) {
if (await isPortFree(port, host)) return port;
}
throw new Error(
`[dev:all] could not find a free ${label} port near ${start} (tried ${searchRange})`,
);
}
export async function resolveDevPorts({
daemonStart = 7456,
appStart = 5173,
appLabel = 'app',
host = HOST,
searchRange = DEFAULT_PORT_SEARCH_RANGE,
} = {}) {
const daemonPort = await findFreePort(daemonStart, 'daemon', {
host,
searchRange,
});
const appPort = await findFreePort(appStart, appLabel, {
host,
searchRange,
});
return { daemonPort, appPort };
}