/// <reference types="vitest" />
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

export default defineConfig({
  plugins: [react()],
  test: {
    // Use jsdom environment for DOM testing
    environment: 'jsdom',
    
    // Global test setup
    setupFiles: ['./src/test/setup.ts'],
    
    // Include unit test files co-located with source AND integration tests
    include: [
      'src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}',
      'src/test/integration/**/*.integration.test.ts'
    ],
    
    // Exclude directories
    exclude: [
      'node_modules',
      'dist',
      '.git',
      '.cache',
      // Temporarily skip failing integration tests
      'src/test/integration/store/command-execution.integration.test.ts',
      'src/test/integration/store/project-store-sync.integration.test.ts'
    ],
    
    // Enable global test functions (describe, it, expect)
    globals: true,
    
    // Coverage configuration
    coverage: {
      provider: 'v8',
      reporter: ['text', 'json', 'html'],
      exclude: [
        'node_modules/',
        'src/test/',
        '**/*.d.ts',
        '**/*.config.ts',
        'src/main.tsx',
        'src/vite-env.d.ts'
      ],
      thresholds: {
        global: {
          branches: 70,
          functions: 70,
          lines: 70,
          statements: 70
        }
      }
    },
    
    // Test timeout
    testTimeout: 10000,
    
    // Retry failed tests once
    retry: 1
  }
});