import { defineConfig } from 'vitest/config';
import { svelte } from '@sveltejs/vite-plugin-svelte';
import path from 'path';

export default defineConfig({
  plugins: [
    svelte()
  ],
  test: {
    globals: true,
    environment: 'jsdom',
    include: [
      'src/**/*.{test,spec}.{js,ts}',
      'src/lib/**/*.test.{js,ts}',
      'src/lib/**/__tests__/*.{test,spec}.{js,ts}',
      'src/lib/**/__tests__/test_*.{js,ts}'
    ],
    exclude: [
      'node_modules/**',
      'dist/**'
    ],
    coverage: {
      provider: 'v8',
      reporter: ['text', 'json', 'html'],
      include: [
        'src/lib/stores/**/*.js',
        'src/lib/components/**/*.svelte'
      ]
    },
    setupFiles: ['./src/lib/stores/__tests__/setupTests.js'],
    alias: [
      { find: '$app/environment', replacement: path.resolve(__dirname, './src/lib/stores/__tests__/mocks/environment.js') },
      { find: '$app/stores', replacement: path.resolve(__dirname, './src/lib/stores/__tests__/mocks/stores.js') },
      { find: '$app/navigation', replacement: path.resolve(__dirname, './src/lib/stores/__tests__/mocks/navigation.js') },
      { find: '$env/static/public', replacement: path.resolve(__dirname, './src/lib/stores/__tests__/mocks/env_public.js') },
      { find: '$components', replacement: path.resolve(__dirname, './src/components') }
    ]
  },
  resolve: {
    conditions: ['mode=browser', 'browser'],
    alias: {
      '$lib': path.resolve(__dirname, './src/lib'),
      '$app': path.resolve(__dirname, './src'),
      '$components': path.resolve(__dirname, './src/components')
    }
  }
});