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 --yesCustomize in the configurator
Packages it adds
| Package | Version | Type |
|---|---|---|
vitest | ^5.1.1 | dev |
New files
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"');
});
});
/// <reference types="vitest/config" />
import { getViteConfig } from "astro/config";
export default getViteConfig({
test: {},
});
Changes to existing files
⋯ 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
.gitignoreREADME.mdastro.config.mjspackage.jsonsrc/components/Counter.astrosrc/components/Counter.test.tssrc/layouts/Layout.astrosrc/pages/about.astrosrc/pages/index.astrosrc/styles/global.csstsconfig.jsonvitest.config.ts