vitest-testing

Configure Vitest unit and integration tests for JavaScript and TypeScript projects.

59|12|Updated Feb 26, 2026
One-click install
npx skills add https://github.com/etylsarin/opencastle --skill vitest-testing-etylsarin
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: vitest-testing
Source: https://github.com/etylsarin/opencastle/tree/main/src/orchestrator/plugins/vitest
Command: npx skills add https://github.com/etylsarin/opencastle --skill vitest-testing-etylsarin

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Provides clear, project-aligned guidance for writing, configuring, and running Vitest unit and integration tests so teams can write reliable tests faster and avoid flaky CI runs.

Core Features & Use Cases

  • Configuration: Example vitest.config.ts settings for globals, environment, include patterns, setup files, and coverage provider configuration.
  • Testing Patterns & Mocking: Recommendations for co-located tests, module mocking, spies, stubs, and timer control to make tests deterministic and maintainable.
  • Coverage & CI: Coverage reporter and threshold guidance plus CI-friendly reporter suggestions for enforcing quality gates.
  • Use Case: Convert a loosely-tested TypeScript codebase into a suite of deterministic unit and component tests with coverage thresholds to prevent regressions.

Quick Start

Run the project's tests with coverage by executing npx vitest run --coverage.

Frequently Asked Questions about vitest-testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I configure Vitest for TypeScript unit and integration tests?

Configure Vitest by defining globals, environment, include patterns, and setup files in a vitest.config.ts file. This provides project-aligned settings for deterministic unit and integration tests in JavaScript and TypeScript codebases using Vite.

What's the best way to mock modules and control timers in Vitest?

The best way to mock modules and control timers in Vitest is using built-in spies, stubs, and timer mocking utilities. These strategies ensure tests remain deterministic and maintainable by isolating the code under test from external dependencies.

How do I enforce code coverage thresholds in a Vitest CI pipeline?

Enforce code coverage thresholds in a Vitest CI pipeline by configuring the coverage provider and reporters in vitest.config.ts. Running tests with npx vitest run --coverage generates CI-friendly reports to act as quality gates and prevent regressions.

Can I run component tests with Vitest in a Vite project?

Yes, you can run component tests with Vitest in a Vite project. Vitest natively supports Vite configurations, allowing you to write and execute component tests alongside unit tests while sharing the same fast build pipeline.

Why are my Vitest unit tests flaky in CI and how do I fix it?

Flaky Vitest unit tests in CI often stem from uncontrolled asynchronous operations or missing mocks. Fix them by applying module mocking, using timer control, and configuring CI-friendly reporters to ensure deterministic execution across pipeline runs.