pickstack

Astro + Vitest

Vite-native test runner, with a sample counter component test. This page shows exactly what pickstack adds to a Astro 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 astro --modules vitest --yes
Customize in the configurator

Packages it adds

PackageVersionType
vitest^5.1.1dev

New files

src/components/Counter.test.ts
import { experimental_AstroContainer as AstroContainer } from "astro/container";
import { describe, expect, it } from "vitest";
import Counter from "./Counter.astro";

describe("Counter", () => {
  it("renders the count and both buttons", async () => {
    const container = await AstroContainer.create();
    const html = await container.renderToString(Counter);

    expect(html).toMatch(/data-count[^>]*>\s*0\s*</);
    expect(html).toContain('data-step="1"');
    expect(html).toContain('data-step="-1"');
  });
});
vitest.config.ts
/// <reference types="vitest/config" />
import { getViteConfig } from "astro/config";

export default getViteConfig({
  test: {},
});

Changes to existing files

src/pages/about.astro (changed)
⋯ 4 unchanged lines <Layout title="About">   <section class="page">     <h1 class="title">About</h1>+    <p class="text">Built with Astro, TypeScript, Vitest.</p>−    <p class="text">Built with Astro, TypeScript.</p>   </section> </Layout>  

Project files

Related templates