import { defineConfig } from "@playwright/test";
import path from "node:path";
import { fileURLToPath } from "node:url";

const __dirname = path.dirname(fileURLToPath(import.meta.url));

const webBaseURL = process.env.WEB_BASE_URL ?? "http://localhost:5173";
const apiBaseURL = process.env.API_BASE_URL ?? "http://localhost:3000";
const shouldStartWeb = process.env.E2E_START_WEB === "true";

export default defineConfig({
  testDir: "./specs",
  timeout: 60_000,
  workers: 1,
  expect: {
    timeout: 10_000,
  },
  use: {
    baseURL: webBaseURL,
    trace: "retain-on-failure",
  },
  projects: [
    {
      name: "chromium",
      use: { browserName: "chromium" },
    },
  ],
  reporter: [["list"], ["html", { open: "never" }]],
  webServer: {
    command: "npm run dev -- --host 127.0.0.1 --port 5173",
    url: webBaseURL,
    reuseExistingServer: true,
    cwd: path.resolve(__dirname, "..", "..", "rollerlogic-mobile"),
  },
  metadata: {
    apiBaseURL,
  },
});
