Automatically configure Vitest from your SvelteKit configuration.
This package is no longer necessary nor maintained given that SvelteKit is now exposed as a Vite plugin. To learn more about how to configure Vite – and subsequently Vitest – in SvelteKit, see here.
In an existing SvelteKit project, run the following.
npm install --save-dev vitest vitest-svelte-kit
Create a file called vitest.config.js
:
import { extractFromSvelteConfig } from "vitest-svelte-kit"
export default extractFromSvelteConfig()
This package aims to emulate SvelteKit-specific behavior in a unit testing context. It does not actually run SvelteKit, but rather configures Vite in a way similar to how SvelteKit would do so.
Importing .svelte
files into tests will work out of the box.
SvelteKit makes a number of modules available to your application.
This package will define those modules with reasonable defaults, but if you depend on their behavior its suggested you mock them using Vitest’s mocking capabilities.
Since SvelteKit is built on Vite, it allows you to pass a Vite configuration as part of your Svelte config file.
This package will use that configuration when running Vitest – meaning any custom Vite config, such as plugins, will be used in your tests.
An example usage of this package can be seen here.
Vitest and SvelteKit are both under active development and are subject to breaking changes. This package aims to stay up-to-date with any upstream changes, but may introduce breaking changes as a result.
When both of these projects become stable, this package aims to follow suit.
- Svelte Testing Library
- Vitest Environment
- Note:
jsdom
seems to work the best with Svelte Testing Library
- Note: