vitest.config.ts Builder

Generate a Vitest configuration for Vite-based projects

Create a vitest.config.ts using defineConfig with the test environment, globals flag, coverage provider and reporters, include and exclude patterns, setup files, and test timeout — ready to drop into any Vite project.

What is the globals option?

With globals set to true you can use describe, it, expect, and vi without importing them, matching Jest behaviour. If you leave it off you must import from vitest in each file, which some teams prefer for explicitness.

Vitest configuration without the boilerplate

Vitest shares Vite’s transform pipeline, so its config is a defineConfig call with a test block. This tool assembles that block: the environment, coverage, matching patterns, setup files, and timeout, then emits a complete vitest.config.ts.

How it works

The environment value selects the global runtime each test file receives. node is a plain Node environment with no DOM, while jsdom and happy-dom install a simulated browser so document and window exist for component tests. globals: true injects describe, it, expect, and vi as globals so you do not import them, mirroring Jest.

include and exclude are glob arrays that decide which files Vitest treats as tests and which directories it skips. setupFiles lists modules run before every test file, the natural home for testing-library matchers or shared mocks. Coverage is delegated to a provider: v8 reads the engine’s built-in coverage with no instrumentation, while istanbul instruments the source for more detailed branch data. The reporters array controls output — text for the console, lcov for CI tools, and html for a browsable report under reportsDirectory.

Tips and example

Install the coverage package that matches your provider, for example @vitest/coverage-v8, or the run fails on first use. A typical DOM-test config:

import { defineConfig } from "vitest/config";

export default defineConfig({
  test: {
    globals: true,
    environment: "jsdom",
    include: ["src/**/*.{test,spec}.{ts,tsx}"],
    setupFiles: ["./test/setup.ts"],
    coverage: { provider: "v8", reporter: ["text", "lcov"] },
  },
});

Keep node as the environment for backend packages — jsdom adds noticeable startup cost you do not need when no test touches the DOM.