pickstack

Next.js + Vitest

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

Packages it adds

PackageVersionType
@vitejs/plugin-react^6.3.0dev
jsdom^31.0.1dev
vitest^5.1.1dev

New files

components/Counter.test.tsx
import { act } from "react";
import { createRoot } from "react-dom/client";
import { describe, expect, it } from "vitest";
import Counter from "./Counter";

describe("Counter", () => {
  it("increments when +1 is clicked", () => {
    const container = document.createElement("div");
    document.body.append(container);
    const root = createRoot(container);
    act(() => root.render(<Counter />));

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

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

    act(() => root.unmount());
    container.remove();
  });
});
vitest.config.mts
import react from "@vitejs/plugin-react";
import { defineConfig } from "vitest/config";

export default defineConfig({
  plugins: [react()],
  resolve: {
    tsconfigPaths: true,
  },
  test: {
    environment: "jsdom",
    setupFiles: ["./vitest.setup.ts"],
  },
});
vitest.setup.ts
// Lets React know this environment wraps updates in act().
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });

Changes to existing files

app/about/page.tsx (changed)
⋯ 2 unchanged lines     <section className="page">       <h1 className="title">About</h1>       <p className="text">+        Built with Next.js (App Router), React 19, TypeScript, Vitest.−        Built with Next.js (App Router), React 19, TypeScript.       </p>     </section>   );⋯ 2 unchanged lines

Project files

Related templates