import { defineConfig } from '@playwright/test';

export default defineConfig({
  testDir: './tests/e2e',
  fullyParallel: false,
  timeout: 30_000,
  reporter: [['list'], ['html', { open: 'never' }]],
  use: {
    baseURL: 'http://127.0.0.1:5173',
    viewport: { width: 1440, height: 900 },
    deviceScaleFactor: 1,
    screenshot: 'only-on-failure',
    launchOptions: {
      executablePath: process.env.PLAYWRIGHT_CHROMIUM_EXECUTABLE ?? '/usr/bin/google-chrome',
      args: ['--no-sandbox'],
    },
  },
  webServer: process.env.E2E_SERVERS_READY
    ? undefined
    : [
        {
          command: 'npm run dev:2d',
          port: 5173,
          reuseExistingServer: true,
          timeout: 30_000,
        },
        {
          command: 'npm run dev:3d',
          port: 3333,
          reuseExistingServer: true,
          timeout: 30_000,
        },
        {
          command: 'npm --workspace @hmwebviewer/viewer-2d-sample run serve:subpath:e2e',
          port: 45173,
          reuseExistingServer: true,
          timeout: 60_000,
        },
        {
          command: 'npm --workspace @hmwebviewer/viewer-3d run serve:subpath:e2e',
          port: 43174,
          reuseExistingServer: true,
          timeout: 60_000,
        },
      ],
});
