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

/**
 * CuCu Note — Playwright E2E Config
 *
 * Chỉ chạy các file 01_*.spec.ts → 06_*.spec.ts (clean rewrite).
 * Các file cũ (auth.spec.ts, comments.spec.ts, ...) bị loại khỏi pattern này.
 *
 * Run: npx playwright test
 * Report: npx playwright show-report
 */
export default defineConfig({
  testDir: './tests/e2e',

  // Run all numbered specs: 01_*.spec.ts through 10_*.spec.ts and beyond
  testMatch: ['[0-9][0-9]_*.spec.ts'],

  timeout: 60000,

  // Run sequentially to avoid auth race conditions
  fullyParallel: false,
  workers: 1,

  forbidOnly: !!process.env.CI,
  retries: process.env.CI ? 2 : 1,

  reporter: [
    ['html', { open: 'never', outputFolder: 'playwright-report' }],
    ['list'],
  ],

  use: {
    baseURL: process.env.BASE_URL || 'http://127.0.0.1:3001',

    // Capture traces and screenshots on failure only
    trace: 'on-first-retry',
    screenshot: 'only-on-failure',
    video: 'retain-on-failure',

    actionTimeout: 15000,
    navigationTimeout: 30000,

    // Keep a single browser context across the test file (reuse session storage)
    // This is handled per-describe via ensureLoggedIn helper
  },

  projects: [
    {
      name: 'chromium',
      use: { ...devices['Desktop Chrome'] },
    },
  ],
});
