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
ormsw
, please check davipon/svelte-component-test-recipes
npx @preset/cli davipon/svelte-add-vitest
This is a preset to add Vitest to your SvelteKit project.
c8
@testing-library/svelte
@testing-library/jest-dom
and TypeScript supportYou must start with a fresh copy of the official SvelteKit template, which is currently created by running this command:
npm create svelte my-app
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
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;
Description | Flag | Default |
---|---|---|
Typescript Support | --ts |
False |
Setup msw |
--msw |
False |
Generate Example | --example |
False |
MIT