2025-12-25 22:35:27 +01:00
|
|
|
import { test } from "@playwright/test";
|
2025-12-26 19:21:34 +01:00
|
|
|
import { resetDatabase } from "./reset-db";
|
2025-12-25 22:06:39 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set language to English for e2e tests.
|
|
|
|
|
* E2E tests should only test in English according to requirements.
|
2025-12-25 22:35:27 +01:00
|
|
|
* This is applied globally via test.beforeEach in the setup file.
|
2025-12-26 19:21:34 +01:00
|
|
|
*
|
|
|
|
|
* Also sets NEXT_PUBLIC_API_URL based on worker index so each worker
|
|
|
|
|
* connects to its own backend instance, and resets the database before
|
|
|
|
|
* each test for isolation.
|
2025-12-25 22:06:39 +01:00
|
|
|
*/
|
2025-12-26 19:21:34 +01:00
|
|
|
test.beforeEach(async ({ context, request }, testInfo) => {
|
|
|
|
|
// Set API URL based on worker index
|
|
|
|
|
// Each worker gets its own backend (port 8001 + workerIndex)
|
|
|
|
|
const workerIndex = testInfo.workerIndex;
|
|
|
|
|
const basePort = parseInt(process.env.E2E_PORT_START || "8001", 10);
|
|
|
|
|
const backendPort = basePort + workerIndex;
|
|
|
|
|
const backendUrl = `http://localhost:${backendPort}`;
|
|
|
|
|
|
|
|
|
|
// Set environment variable for this test run
|
|
|
|
|
process.env.NEXT_PUBLIC_API_URL = backendUrl;
|
|
|
|
|
|
|
|
|
|
// Reset database before each test for isolation
|
2025-12-26 20:04:46 +01:00
|
|
|
// This must complete successfully before tests run to avoid race conditions
|
|
|
|
|
await resetDatabase(request);
|
|
|
|
|
|
|
|
|
|
// Small delay to ensure database transaction commits are visible
|
|
|
|
|
// This prevents race conditions where tests start before reset completes
|
|
|
|
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
2025-12-26 19:21:34 +01:00
|
|
|
|
2025-12-25 22:35:27 +01:00
|
|
|
// Add init script to set English language before any page loads
|
|
|
|
|
// This must be called before any page.goto() calls
|
|
|
|
|
await context.addInitScript(() => {
|
|
|
|
|
if (typeof window !== "undefined") {
|
|
|
|
|
window.localStorage.setItem("arbret-locale", "en");
|
|
|
|
|
}
|
2025-12-25 22:06:39 +01:00
|
|
|
});
|
2025-12-25 22:35:27 +01:00
|
|
|
});
|