import { defineConfig } from 'vitest/config'
import { resolve } from 'path'

export default defineConfig({
  test: {
    // 测试环境 - 使用happy-dom进行组件测试
    environment: 'happy-dom',

    // 测试文件匹配模式
    include: [
      'src/client/__integration_tests__/**/*.test.{js,ts,jsx,tsx}',
      'src/client/__tests__/**/*.test.{js,ts,jsx,tsx}',
      'src/client/**/__tests__/**/*.test.{js,ts,jsx,tsx}',
      'src/client/**/*.test.{js,ts,jsx,tsx}'
    ],

    // 排除模式
    exclude: [
      '**/node_modules/**',
      '**/dist/**',
      '**/build/**',
      '**/coverage/**',
      'tests/e2e/**',   // 排除e2e测试代码
      'src/server/**',
      'src/client/home/**',
      'src/client/components/ui/**',
      'src/client/__test_utils__/**',
    ],

    // 覆盖率配置
    coverage: {
      provider: 'v8',
      reporter: ['text', 'lcov', 'html'],
      reportsDirectory: './coverage/components',
      exclude: [
        '**/node_modules/**',
        '**/dist/**',
        '**/build/**',
        '**/coverage/**',
        '**/*.d.ts',
        'src/client/api.ts',
        'tests/e2e/**',   // 排除e2e测试代码
        'scripts/**',     // 排除脚本目录
        'src/test/**',    // 排除测试工具目录
        '**/__tests__/**',
        '**/__mocks__/**',
        '**/index.ts',
        '**/types.ts',
        'src/server/**',
        'src/client/home/**',
        'src/client/components/ui/**',
        'src/client/__test_utils__/**',
        'vitest.config.ts',
        'vitest.config.components.ts',
        'vite.config.ts',
        'server.js',
        'eslint.config.js',
        'debug-page.js',
      ],
      thresholds: {
        branches: 60,
        functions: 60,
        lines: 60,
        statements: 60
      }
    },

    // 全局设置
    globals: true,

    // 测试超时
    testTimeout: 10000,

    // 设置文件
    setupFiles: ['./src/test/setup.ts'],

    // 别名配置
    alias: {
      '@': resolve(__dirname, './src'),
      '@/client': resolve(__dirname, './src/client'),
      '@/server': resolve(__dirname, './src/server'),
      '@/share': resolve(__dirname, './src/share'),
      '@/test': resolve(__dirname, './test')
    }
  }
})