mirror of
https://seed.radicle.dev/rad:z4D5UCArafTzTQpDZNQRuqswh3ury.git
synced 2026-10-18 19:10:45 +08:00
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.
59 lines
1.4 KiB
TypeScript
59 lines
1.4 KiB
TypeScript
import type { PlaywrightTestConfig } from "@playwright/test";
|
|
|
|
import * as net from "node:net";
|
|
|
|
import { devices } from "@playwright/test";
|
|
|
|
function getFreePort(): Promise<number> {
|
|
return new Promise((resolve, reject) => {
|
|
const server = net.createServer();
|
|
server.listen(0, "127.0.0.1", () => {
|
|
const port = (server.address() as net.AddressInfo).port;
|
|
server.close(err => (err ? reject(err) : resolve(port)));
|
|
});
|
|
server.on("error", reject);
|
|
});
|
|
}
|
|
|
|
const testHttpApiPort = await getFreePort();
|
|
process.env.VITE_TEST_HTTP_API_PORT = String(testHttpApiPort);
|
|
|
|
const config: PlaywrightTestConfig = {
|
|
outputDir: "./tests/artifacts",
|
|
testDir: "./tests/e2e",
|
|
globalSetup: "./tests/support/globalSetup.ts",
|
|
timeout: 30_000,
|
|
expect: {
|
|
timeout: 8000,
|
|
},
|
|
fullyParallel: true,
|
|
workers: process.env.CI ? 1 : undefined,
|
|
forbidOnly: !!process.env.CI,
|
|
retries: process.env.CI ? 2 : 0,
|
|
reporter: "list",
|
|
use: {
|
|
colorScheme: "dark",
|
|
actionTimeout: 5000,
|
|
baseURL: "http://localhost:3001",
|
|
trace: "retain-on-failure",
|
|
},
|
|
|
|
projects: [
|
|
{
|
|
name: "webkit",
|
|
use: {
|
|
...devices["Desktop Safari"],
|
|
},
|
|
},
|
|
],
|
|
|
|
webServer: [
|
|
{
|
|
command: `VITE_AUTH_LONG_DELAY=1000 VITE_TEST_HTTP_API_PORT=${testHttpApiPort} npm run start -- --strictPort --port 3001`,
|
|
port: 3001,
|
|
},
|
|
],
|
|
};
|
|
|
|
export default config;
|