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

export default defineConfig({
  test: {
    projects: [
      // Node.js 环境项目 - 后端测试
      {
        test: {
          // 共享配置
          globals: true,
          name: 'node',
          environment: 'node',
          include: [
            'tests/unit/server/**/*.test.{ts,js}',
            'tests/integration/server/**/*.test.{ts,js}'
          ],
          exclude: [
            '**/node_modules/**',
            '**/dist/**',
            '**/build/**',
            '**/coverage/**',
            'tests/e2e/**'
          ],

          alias: {
            '~': resolve(__dirname, './tests'),
            '@': resolve(__dirname, './src'),
          }
        }
      },
      // Happy DOM 环境项目 - 前端组件测试
      {
        test: {
          // 全局设置
          globals: true,
          name: 'happy-dom',
          environment: 'happy-dom',
          include: [
            'tests/unit/client/**/*.test.{ts,js,tsx,jsx}',
            'tests/integration/client/**/*.test.{ts,js,tsx,jsx}'
          ],
          exclude: [
            '**/node_modules/**',
            '**/dist/**',
            '**/build/**',
            '**/coverage/**',
            'tests/e2e/**',
            'src/client/home/**',
            'src/client/components/ui/**',
            'src/client/__test_utils__/**',
          ],
          alias: {
            '~': resolve(__dirname, './tests'),
            '@': resolve(__dirname, './src'),
          },
        },
      }
    ],
    testTimeout: 10000,
    setupFiles: ['./tests/utils/setup.ts'],
    // 覆盖率配置 - 放在根级别
    coverage: {
      provider: 'v8',
      reporter: ['text', 'lcov', 'html'],
      reportsDirectory: './coverage',
      exclude: [
        '**/node_modules/**',
        '**/dist/**',
        '**/build/**',
        '**/coverage/**',
        '**/*.d.ts',
        'tests/e2e/**',
        'scripts/**',
        'src/test/**',
        '**/__tests__/**',
        '**/__mocks__/**',
        '**/index.ts',
        '**/types.ts',
        'vitest.config.ts',
        'vitest.config.components.ts',
        'vite.config.ts',
        'server.js',
        'eslint.config.js',
        'debug-page.js',
        'src/server/__test_utils__/**',
        'src/client/__test_utils__/**',
      ],
      thresholds: {
        branches: 65,
        functions: 65,
        lines: 65,
        statements: 65
      }
    },
    // api测试关闭并行测试
    fileParallelism: false
  },

})