import { fileURLToPath, URL } from 'node:url'; import { svelte } from '@sveltejs/vite-plugin-svelte'; import { defineConfig } from 'vitest/config'; // Separate from vite.config.ts: SvelteKit warns about a `test` block there, and // `vite build`/`vite dev` must never pick up test-only config. Two projects: // - 'node': the pure-logic suite — no DOM, no svelte/tailwind plugins // (existing behavior preserved exactly). // - 'svelte-components': DOM-based tests for `*.svelte.test.ts` — happy-dom // + the svelte plugin + the `$lib` alias so real Svelte 5 components mount. // extends:true deep-merges array options (include/exclude concatenate across // projects), so include/exclude live ONLY in each project, never at the root. export default defineConfig({ test: { restoreMocks: true, unstubEnvs: true, projects: [ { extends: true, test: { name: 'node', environment: 'node', include: ['src/**/*.test.ts'], exclude: ['**/node_modules/**', '**/*.svelte.test.ts'] } }, { extends: true, plugins: [svelte()], resolve: { alias: { $lib: fileURLToPath(new URL('./src/lib', import.meta.url)) }, // Svelte 5's `mount()` lives in the client build (svelte's // `browser` export condition); vitest's default SSR // resolution would pick the server build and reject mount. conditions: ['browser'] }, test: { name: 'svelte-components', environment: 'happy-dom', include: ['src/**/*.svelte.test.ts'] } } ] } });