import { defineConfig } from 'vitest/config';
import path from 'path';
 
/**
 * E2E Test Configuration
 *
 * IMPORTANT: E2E tests run against real OS automation.
 * This configuration includes strict timeouts to prevent hanging.
 */
export default defineConfig({
  test: {
    globals: true,
    environment: 'node',
    include: ['tests/e2e/**/*.e2e.test.ts'],
    // E2E tests use real automation - set strict timeouts to prevent hanging
    // Individual tests: 30 seconds max
    testTimeout: 30000,
    // Hooks (beforeAll, afterAll, etc.): 30 seconds max
    hookTimeout: 30000,
    // Overall suite timeout: 2 minutes max to catch any hanging tests
    teardownTimeout: 5000,
    // Run tests sequentially to avoid port conflicts
    pool: 'forks',
    poolOptions: {
      forks: {
        singleFork: true,
      },
    },
    // Force exit after tests complete to prevent hanging from async operations
    forceRerunTriggers: [],
  },
  resolve: {
    alias: {
      // Mirror main Vitest config so E2E tests can resolve package paths
      '@gridpilot/shared-result': path.resolve(__dirname, 'core/shared/result/Result.ts'),
      '@gridpilot/automation': path.resolve(__dirname, 'core/automation'),
      '@gridpilot/automation/*': path.resolve(__dirname, 'core/automation/*'),
      '@gridpilot/testing-support': path.resolve(__dirname, 'core/testing-support'),
      '@gridpilot/media': path.resolve(__dirname, 'core/media'),
      '@': path.resolve(__dirname, 'apps/website'),
      '@/*': path.resolve(__dirname, 'apps/website/*'),
      packages: path.resolve(__dirname, 'packages'),
      'core/*': path.resolve(__dirname, 'core/*'),
    },
  },
});