import { defineConfig } from 'vitest/config'; import { playwright } from '@vitest/browser-playwright'; import adapter from '@sveltejs/adapter-node'; import { sveltekit } from '@sveltejs/kit/vite'; import { realtimeDevWsPlugin } from './src/lib/server/core/dev-plugin.js'; import { toolRegistry } from './src/lib/server/project/tools/index.js'; import { SESSION_PERSONA } from './src/lib/project/persona.js'; export default defineConfig({ plugins: [ sveltekit({ compilerOptions: { // Force runes mode for the project, except for libraries. Can be removed in svelte 6. runes: ({ filename }) => filename.split(/[/\\]/).includes('node_modules') ? undefined : true }, // adapter-node: the realtime WS relay needs a persistent Node process // (see src/lib/server/core/ws-handler.ts) — no serverless adapter can // hold an upgraded WebSocket connection the way this can. adapter: adapter() }), // Attaches the same WS upgrade handling used in production (server.js) // to Vite's dev server, so `npm run dev` supports it without a build. // Passes only raw, env-independent pieces (persona + tool registry) — // NOT a fully-resolved `defaults` object — because this plugin's config // gets evaluated under `npm run test:unit` too (see the VITEST guard in // dev-plugin.ts's configureServer); resolving env-driven config here at // module scope would run it there as well, with no env vars available. realtimeDevWsPlugin({ persona: SESSION_PERSONA, toolRegistry }) ], test: { expect: { requireAssertions: true }, projects: [ { extends: './vite.config.ts', test: { name: 'client', browser: { enabled: true, provider: playwright(), instances: [{ browser: 'chromium', headless: true }] }, include: ['src/**/*.svelte.{test,spec}.{js,ts}'], exclude: ['src/lib/server/**'] } }, { extends: './vite.config.ts', test: { name: 'server', environment: 'node', include: ['src/**/*.{test,spec}.{js,ts}'], exclude: ['src/**/*.svelte.{test,spec}.{js,ts}'] } } ] } });