From 18a6fb57ecd9314acf12e7de544c74cbdbcabe0a Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Sun, 4 Jan 2026 11:08:34 +0200 Subject: [PATCH] Allow configuring PORT (both server & E2E tests) --- app/utils/playwright.ts | 6 ++++-- e2e/global-setup.ts | 8 ++++---- vite.config.ts | 8 ++++++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/utils/playwright.ts b/app/utils/playwright.ts index 9da2d6327..1cfc060f6 100644 --- a/app/utils/playwright.ts +++ b/app/utils/playwright.ts @@ -4,11 +4,13 @@ import { type Locator, type Page, } from "@playwright/test"; +import dotenv from "dotenv"; import { ADMIN_ID } from "~/features/admin/admin-constants"; import type { SeedVariation } from "~/features/api-private/routes/seed"; import { tournamentBracketsPage } from "./urls"; -const BASE_PORT = 6173; +dotenv.config(); +export const E2E_BASE_PORT = Number(process.env.PORT || 5173) + 1000; type WorkerFixtures = { workerPort: number; @@ -19,7 +21,7 @@ export const test = base.extend({ workerPort: [ // biome-ignore lint/correctness/noEmptyPattern: Playwright requires object destructuring async ({}, use, workerInfo) => { - const port = BASE_PORT + workerInfo.parallelIndex; + const port = E2E_BASE_PORT + workerInfo.parallelIndex; await use(port); }, { scope: "worker" }, diff --git a/e2e/global-setup.ts b/e2e/global-setup.ts index 975913f6f..1bfe05960 100644 --- a/e2e/global-setup.ts +++ b/e2e/global-setup.ts @@ -1,8 +1,8 @@ import { type ChildProcess, execSync, spawn } from "node:child_process"; import fs from "node:fs"; import type { FullConfig } from "@playwright/test"; +import { E2E_BASE_PORT } from "~/utils/playwright"; -const BASE_PORT = 6173; const WORKER_COUNT = Number(process.env.E2E_WORKERS) || 4; const DEBUG = process.env.E2E_DEBUG === "true"; const SERVER_PROCESSES: ChildProcess[] = []; @@ -52,7 +52,7 @@ async function globalSetup(_config: FullConfig) { env: { ...process.env, VITE_E2E_TEST_RUN: "true", - VITE_SITE_DOMAIN: `http://localhost:${BASE_PORT}`, + VITE_SITE_DOMAIN: `http://localhost:${E2E_BASE_PORT}`, }, }); @@ -63,13 +63,13 @@ async function globalSetup(_config: FullConfig) { // biome-ignore lint/suspicious/noConsole: CLI script output console.log("Cleaning up any existing processes on e2e ports..."); for (let i = 0; i < WORKER_COUNT; i++) { - killProcessOnPort(BASE_PORT + i); + killProcessOnPort(E2E_BASE_PORT + i); } // Wait briefly for ports to be released await new Promise((resolve) => setTimeout(resolve, 500)); for (let i = 0; i < WORKER_COUNT; i++) { - const port = BASE_PORT + i; + const port = E2E_BASE_PORT + i; const dbPath = `db-test-e2e-${i}.sqlite3`; // Ensure database exists with migrations diff --git a/vite.config.ts b/vite.config.ts index ba2680c79..dc0d82b1f 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,11 +1,15 @@ import { reactRouter } from "@react-router/dev/vite"; -import { defineConfig } from "vite"; +import { defineConfig, loadEnv } from "vite"; import babel from "vite-plugin-babel"; import tsconfigPaths from "vite-tsconfig-paths"; import { configDefaults } from "vitest/config"; -export default defineConfig(() => { +export default defineConfig(({ mode }) => { + const env = loadEnv(mode, process.cwd(), ""); return { + server: { + port: Number(env.PORT) || 5173, + }, ssr: { noExternal: ["react-charts", "react-use"], },