import { defineConfig } from 'vitest/config';
import react from '@vitejs/plugin-react';
import path from 'node:path';
import { playwright } from '@vitest/browser-playwright';

export default defineConfig({
  plugins: [react()],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src'),
    },
  },
  test: {
    // Browser mode: tests run inside a real Chromium browser via Playwright
    browser: {
      enabled: true,
      name: 'chromium',
      provider: playwright(),
      instances: [{ browser: 'chromium' }],
      headless: true,
      // Slow down interactions slightly so UI animations settle
      slowHijackESM: false,
    },
    // Integration tests: match *.integration.test.{ts,tsx}
    include: ['src/**/*.integration.test.{ts,tsx}'],
    // Global timeout for browser operations
    testTimeout: 30_000,
    // Retry flaky browser tests once
    retry: 1,
    // Coverage
    coverage: {
      provider: 'v8',
      reporter: ['text', 'lcov'],
      include: ['src/**/*.{ts,tsx}'],
      exclude: ['src/**/*.test.*', 'src/**/*.spec.*'],
    },
    // Setup file for global test helpers
    setupFiles: ['./src/test/setup.ts'],
  },
});
