mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-08-27 13:45:27 -05:00
Allow configuring PORT (both server & E2E tests)
This commit is contained in:
@@ -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<object, WorkerFixtures>({
|
||||
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" },
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"],
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user