Performance: Vitest setup
This affects the development environment's startup time and test execution speed, impacting developer feedback loops.
/// vitest.config.ts import { defineConfig } from 'vitest/config'; import { svelte } from '@sveltejs/vite-plugin-svelte'; export default defineConfig({ plugins: [svelte()], test: { environment: 'jsdom', cache: true, include: ['src/**/*.{test,spec}.{js,ts,svelte}'], deps: { inline: ['@testing-library/svelte'] } } });
import { describe, it, expect } from 'vitest'; import { render } from '@testing-library/svelte'; // No config file, default settings // Tests run with full Svelte compilation each time
| Pattern | Module Compilation | Caching | Test Startup Time | Verdict |
|---|---|---|---|---|
| Default Vitest setup | Full Svelte compilation every run | No caching | Slow (several seconds) | [X] Bad |
| Configured Vitest with svelte plugin and caching | Incremental compilation with caching | Enabled | Fast (under 1 second) | [OK] Good |
vite.config.js?import { render } from '@testing-library/svelte';
import Button from './Button.svelte';
test('shows button text', () => {
const { getByText } = render(Button, { props: { label: 'Click me' } });
getByText('Click me');
});import { defineConfig } from 'vite';
import svelte from '@sveltejs/vite-plugin-svelte';
export default defineConfig({
plugins: [svelte()],
test: {
environment: 'node'
}
});show is true. Which Vitest test code correctly checks that the message appears only when show is true?import { render } from '@testing-library/svelte';
import Message from './Message.svelte';
test('message visibility', () => {
// Fill in test code here
});Pass the test and this pattern moves unknown