import { defineConfig } from 'vitest/config'
import { defineVitestProject } from '@nuxt/test-utils/config'
import { fileURLToPath } from 'node:url'
import { dirname } from 'node:path'

const rootDir = dirname(fileURLToPath(new URL('./', import.meta.url)))

export default defineConfig({
  test: {
    env: {
      // Load test environment variables
      NUXT_TEST_ENV: 'true', // Flag to detect test environment in plugins
      DATABASE_URL: 'postgresql://test:test@localhost:5432/test_db',
      GITHUB_CLIENT_ID: 'test_github_id',
      GITHUB_CLIENT_SECRET: 'test_github_secret',
      GOOGLE_CLIENT_ID: 'test_google_id',
      GOOGLE_CLIENT_SECRET: 'test_google_secret'
    },
    projects: [
      {
        test: {
          name: 'unit',
          include: ['test/{e2e,unit}/*.{test,spec}.ts'],
          environment: 'node'
        }
      },
      await defineVitestProject({
        // Set the Vitest/Vite root for this project
        root: rootDir,
        test: {
          name: 'nuxt',
          include: ['test/nuxt/*.{test,spec}.ts'],
          environment: 'nuxt'
        }
      })
    ]
  }
})
