import { defineConfig, devices } from "@playwright/test";
import { FIXTURE_PUBLIC_KEY_RAW_BASE64 } from "./tests/e2e/fixtures/gateway-key";

// The service worker only precaches a real production build (the
// `$service-worker` `build` list is empty under `vite dev`), so the PWA
// spec runs against `vite preview` of an actual build — a separate config
// from the dev-server e2e suite. Chromium only: service-worker + Cache
// Storage + offline emulation are the surface under test, and WebKit's
// SW support in headless CI is unreliable.
export default defineConfig({
	testDir: "tests/pwa",
	fullyParallel: false,
	workers: 1,
	forbidOnly: !!process.env.CI,
	retries: process.env.CI ? 2 : 0,
	reporter: [["list"]],
	use: {
		baseURL: "http://localhost:4173",
		trace: "retain-on-failure",
	},
	projects: [{ name: "chromium", use: { ...devices["Desktop Chrome"] } }],
	webServer: {
		command: "pnpm build && pnpm preview --port 4173",
		url: "http://localhost:4173",
		reuseExistingServer: !process.env.CI,
		timeout: 180_000,
		env: {
			VITE_GATEWAY_RESPONSE_PUBLIC_KEY: FIXTURE_PUBLIC_KEY_RAW_BASE64,
		},
	},
});
