import { defineConfig } from 'vite'
import { svelte } from '@sveltejs/vite-plugin-svelte'

// https://vite.dev/config/
export default defineConfig(({ mode }) => ({
  plugins: [svelte()],
  resolve: {
    // Use browser Svelte build in tests so mount() is available (avoid "lifecycle_function_unavailable")
    conditions: mode === 'test' ? ['browser'] : [],
  },
  test: {
    include: ['src/**/*.{test,spec}.{js,ts}'],
    environment: 'jsdom',
    globals: true,
    setupFiles: ['./src/test/setup.js'],
    coverage: {
      provider: 'v8',
      reporter: ['text', 'html'],
      include: ['src/**/*.{js,ts,svelte}'],
      exclude: ['src/test/**', '**/*.test.js', '**/*.spec.js'],
    },
  },
}))
