import { defineConfig, devices } from "@playwright/test";

const externalBaseUrl = process.env.HEARBOOKS_E2E_URL;

export default defineConfig({
  testDir: "./tests/e2e",
  outputDir: "./test-results",
  timeout: 60_000,
  expect: { timeout: 10_000 },
  fullyParallel: false,
  workers: 1,
  reporter: "line",
  use: {
    baseURL: externalBaseUrl ?? "http://127.0.0.1:3000",
    locale: "zh-CN",
    trace: "retain-on-failure",
    screenshot: "only-on-failure",
  },
  webServer: externalBaseUrl ? undefined : {
    command: "npm run dev",
    url: "http://127.0.0.1:3000",
    reuseExistingServer: true,
    timeout: 120_000,
  },
  projects: [
    {
      name: "edge-desktop",
      testMatch: /(?:import-listen|proofread)\.spec\.ts/,
      use: {
        channel: "msedge",
        viewport: { width: 1440, height: 900 },
      },
    },
    {
      name: "edge-mobile",
      testMatch: /responsive\.spec\.ts/,
      use: {
        ...devices["Pixel 7"],
        channel: "msedge",
      },
    },
  ],
});
