pickstack

Svelte + Vitest

Vite-native test runner, with a sample counter component test. This page shows exactly what pickstack adds to a Svelte project for Vitest: the packages, the new files and the changes to existing ones. Every combination is installed, built, linted and tested in CI.

$ npm create pickstack@latest my-app -- --framework svelte --modules vitest --yes
Customize in the configurator

Packages it adds

PackageVersionType
jsdom^31.0.1dev
vitest^5.1.1dev

New files

src/lib/Counter.test.ts
import { flushSync, mount, unmount } from "svelte";
import { describe, expect, it } from "vitest";
import Counter from "./Counter.svelte";

describe("Counter", () => {
  it("increments when +1 is clicked", () => {
    const component = mount(Counter, { target: document.body });

    const plus = [...document.querySelectorAll("button")].find(
      (b) => b.textContent?.trim() === "+1",
    );
    plus?.click();
    flushSync();

    expect(document.querySelector("p")?.textContent).toBe("1");

    unmount(component);
  });
});

Changes to existing files

vite.config.ts (changed)
+/// <reference types="vitest/config" /> import { svelte } from "@sveltejs/vite-plugin-svelte"; import { defineConfig } from "vite";   export default defineConfig({   plugins: [svelte()],+  resolve: process.env.VITEST ? { conditions: ["browser"] } : undefined,+  test: {+    environment: "jsdom",+  }, });  

Project files

Related templates