import { defineConfig } from 'vitest/config';
import { playwright } from '@vitest/browser-playwright';
import { sveltekit } from '@sveltejs/kit/vite';

export default defineConfig({
	plugins: [sveltekit()],
	server: { open: true },
	build: {
		rolldownOptions: {
			onLog(level, log, defaultHandler) {
				const message = typeof log === 'string' ? log : log.message;

				if (level === 'warn' && message.includes('[PLUGIN_TIMINGS]')) {
					return;
				}

				defaultHandler(level, log);
			}
		}
	},
	test: {
		expect: { requireAssertions: true },
		ui: false,
		projects: [
			{
				extends: './vite.config.ts',
				test: {
					name: 'client',
					browser: {
						headless: true,
						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}']
				}
			}
		]
	}
});
