import path from "node:path" import { fileURLToPath } from "node:url" import dotenv from "dotenv" const __filename = fileURLToPath(import.meta.url) const __dirname = path.dirname(__filename) dotenv.config({ path: path.join(__dirname, "../../.env") }) function getEnvVar(name: string): string { const value = process.env[name] if (!value) { throw new Error(`Environment variable ${name} is undefined`) } return value } export const firstSuperuser = getEnvVar("FIRST_SUPERUSER") export const firstSuperuserPassword = getEnvVar("FIRST_SUPERUSER_PASSWORD") /** * The two origins a run talks to: the app in the browser, and the API for the * setup and teardown around a spec. * * Deliberately *not* taken from `VITE_API_URL`, even though `../../.env` above * has one. That variable belongs to the app build, and in a checkout configured * for a deployment it names the deployment — so a suite reading it would drive * a browser at the local stack while sending its `DELETE`s to the live * instance. Both origins come from the same place instead: whatever the browser * is pointed at is what teardown may write to. */ export const appUrl = process.env.PLAYWRIGHT_BASE_URL || "http://app.localhost" export const apiUrl = process.env.PLAYWRIGHT_API_URL || apiOrigin(appUrl) /** `app.` serves the SPA, `api.` serves its API. */ function apiOrigin(app: string): string { const url = new URL(app) if (!url.hostname.startsWith("app.")) { throw new Error( `Cannot derive the API origin from PLAYWRIGHT_BASE_URL=${app}. ` + "Set PLAYWRIGHT_API_URL to name it.", ) } url.hostname = `api.${url.hostname.slice("app.".length)}` return url.origin }