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

/**
 * Playwright config for visual regression against Storybook.
 *
 * Expectations:
 * - Storybook is served at http://localhost:6006 BEFORE running these tests.
 *   The pnpm test:visual script wraps the start + run + stop dance.
 * - Screenshot baselines live next to each test file in __snapshots__/.
 * - One browser (chromium) is enough for v1; multi-browser comes later.
 */
export default defineConfig({
  testDir: "./apps/storybook/tests",
  testMatch: /.*\.spec\.ts/,
  fullyParallel: false,
  reporter: process.env.CI ? "github" : "list",
  use: {
    baseURL: "http://localhost:6006",
    viewport: { width: 1280, height: 720 },
    screenshot: "only-on-failure",
  },
  expect: {
    toHaveScreenshot: {
      // Tolerate up to 1% pixel difference. Tune when first real component
      // lands and the noise floor is measurable.
      maxDiffPixelRatio: 0.01,
    },
  },
  projects: [{ name: "chromium", use: { ...devices["Desktop Chrome"] } }],
});
