Warning This svelte adder is no longer maintained.

You can now create a new SvelteKit project with Vitest using npm create svelte@latest.

Features like adding @testing-library/svelte or msw, please check davipon/svelte-component-test-recipes

Logo of Svelte Logo of Svelte

svelte-add-vitest

npx @preset/cli davipon/svelte-add-vitest

❓ What is this?

This is a preset to add Vitest to your SvelteKit project.

🔋 Batteries-included

🛠 Usage

You must start with a fresh copy of the official SvelteKit template, which is currently created by running this command:

npm create svelte my-app

⚠️ Make sure to choose Skeleton Project

Once that is set up, run this command in your project directory to set up Vitest:

npx @preset/cli davipon/svelte-add-vitest --ts --msw --example

🎭 Playwright compatible

If you have playwright installed, make sure to configure it to only run tests using playwright annotations. For instance, the playwright test is placed under tests in SvelteKit skeleton project. You need to specify it after adding Vitest:

//playwright.config.js

/** @type {import('@playwright/test').PlaywrightTestConfig} */
const config = {
  webServer: {
    command: 'npm run build && npm run preview',
    port: 4173
  },
  // Add testMatch here
  testMatch: 'tests/**/*.js',
};

export default config;

⚙️ Options

Description Flag Default
Typescript Support --ts False
Setup msw --msw False
Generate Example --example False

📄 License

MIT

Top categories

Loading Svelte Themes