All skills

Vitest 4+ testing with Vite. Use when configuring vitest.config.ts, writing unit/integration/browser tests, implementing mocks with vi.fn/vi.spyOn/vi.mock, setting up V8 or Istanbul coverage, or migrating from Jest or older Vitest workspace setups. Triggers on vitest, vitest.config.ts, vi.mock, browser mode, vitest/browser, projects, setupFiles, and toMatchScreenshot.

Use this Skill: https://skilld.dev/gh/nodnarbnitram/claude-code-extensions/vitest-v4

This session only. Nothing lands on disk.

referencescoverage-projects-reference.md

≈710 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Vitest 4 Coverage and Projects Reference

Vitest 4 tightened a few configuration details that commonly break older examples.

Coverage providers

Choose one:

  • @vitest/coverage-v8 - usually the fastest option
  • @vitest/coverage-istanbul - useful when Istanbul-specific behavior is needed

Vitest 4 improved V8 coverage accuracy with AST-based remapping, so V8 is now a strong default for most projects.

Important coverage change

coverage.all and coverage.extensions are removed in Vitest 4.

Vitest 4 also changed V8 coverage remapping to an AST-based approach, so coverage percentages can legitimately shift after upgrade even when your source code did not change.

Use coverage.include instead:

coverage: {
  provider: 'v8',
  include: ['src/**/*.{ts,tsx}'],
}

Keep include focused on real source files. Do not point it at node_modules, build output, or broad repo-root globs.

Projects replace workspace-style config

Vitest 4 uses projects as the stable term for multi-project setups. The rename started in Vitest 3.2, and older workspace-file usage is removed in Vitest 4.

The key gotcha is inheritance: treat project configs as explicit units. Shared concerns like reporters, coverage, or common setup should be intentionally factored into a base config via extends: true or mergeConfig, not assumed to flow in automatically.

import { defineConfig, defineProject } from 'vitest/config';
import { playwright } from '@vitest/browser-playwright';

export default defineConfig({
  test: {
    projects: [
      defineProject({
        test: {
          name: 'unit',
          include: ['src/**/*.test.ts'],
        },
      }),
      defineProject({
        test: {
          name: 'browser',
          include: ['src/**/*.browser.test.ts'],
          browser: {
            enabled: true,
            provider: playwright(),
            instances: [{ browser: 'chromium' }],
          },
        },
      }),
    ],
    maxWorkers: 4,
  },
});

Use projects when environments differ meaningfully, like Node vs Browser Mode, or app vs package-level tests in a monorepo.

Worker migration note

If an older config uses maxThreads, maxForks, singleThread, singleFork, or poolOptions, migrate those settings to Vitest 4 worker options such as maxWorkers.

AI-output optimization note

Vitest 4 includes agent-aware output behavior in some reporting flows. When optimizing for AI or CI summaries, prefer compact summary output over huge raw reports unless a human is actively diagnosing coverage deltas.

Reference pattern for shared base config

import { defineConfig, mergeConfig } from 'vitest/config';

const shared = defineConfig({
  test: {
    restoreMocks: true,
    coverage: {
      provider: 'v8',
    },
  },
});

Source: SKILL.md on GitHub

No alerts15d3 checks · Risk SAFE
  • Gen Agent Trust Hub15d

    The skill provides comprehensive and safe instructions for using Vitest 4. No malicious patterns, obfuscation, or security vulnerabilities were detected. It effectively guides users toward best practices, such as avoiding hanging processes in non-interactive environments and using official ecosystem packages.

  • Socket15d

    No alerts

  • Snyk15d

    Risk: LOW · No issues

Signed by skilld at ca1a51b. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 months ago.

Steadyupdated 6 months ago
version
1.0.0
metadata
{
  "author": "Brandon Martin"
}

README badge

README badge for nodnarbnitram/claude-code-extensions/vitest-v4