Token导航 LogoToken导航TokenDH.com
研究检索操作浏览器github未标认证来源可访问许可证需确认审计通过

vitest-devVitest DEV 搜索

Agent Skill

用于辅助测试设计、自动化测试、用例整理和回归验证。它适合让 Agent 编写单元测试、端到端测试、测试计划或根据失败日志定位问题。使用时需要确认项目测试框架、运行命令和夹具数据,避免为了通过测试而改坏真实逻辑;涉及浏览器或外部服务时,应区分本地模拟、测试环境和生产环境。

总安装

196

周安装

8

GitHub Stars

2

下载量

63
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:vitest-dev(Vitest DEV 搜索)
来源仓库:https://github.com/bjornmelin/dev-skills
仓库路径:skills/vitest-dev
安装命令:
npx skills add https://github.com/bjornmelin/dev-skills --skill vitest-dev
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/bjornmelin/dev-skills --skill vitest-dev

简介

用于辅助测试设计、自动化测试、用例整理和回归验证。

  • 适合编写单元测试、端到端测试、测试计划或根据失败日志定位问题。
  • 使用时需确认项目测试框架、运行命令和夹具数据,避免误改真实逻辑。
  • 安装命令:npx skills add https://github.com/bjornmelin/dev-skills --skill vitest-dev。
  • 涉及浏览器或外部服务时应区分本地模拟、测试环境和生产环境。

SKILL.md

vitest-dev

A Claude Code skill for producing high-signal, low-flake, fast Vitest suites (TypeScript + Next.js 16) and for shaping Vitest configuration for optimal local DX and CI throughput.

Core outcomes

  1. Correctness first: tests encode business behavior (not implementation details).
  2. Deterministic: no network, no clocks, no global leakage, no order dependencies.
  3. Fast:

- fast feedback locally (watch mode + smart filtering) - scalable CI (parallel workers + sharding + cache + machine-readable reports)

  1. Actionable failures: failures localize root cause quickly.

Default operating procedure

When asked to add or improve tests:

  1. Map the unit under test

- Identify public API / observable behavior - Identify boundaries: I/O, time, randomness, network, database, filesystem, env, global state

  1. Choose the lightest test that gives confidence

- Pure unit test (no framework/runtime) → preferred - Component test in jsdom (React) when DOM behavior is essential - Integration test in Node when multiple modules must cooperate - Browser Mode (real browser) only when DOM fidelity matters (layout/visuals, real events)

  1. Design a minimal test matrix

- happy path(s) - boundary conditions - error paths - key invariants (idempotency, caching semantics, auth gates, etc.)

  1. Implement tests

- arrange/act/assert clarity - isolate side effects and restore mocks - prefer stable assertions (toHaveTextContent, role-based queries, etc.)

  1. Run locally and fix

- run smallest scope first (single file / name filtering)

  1. Harden

- remove flakiness vectors (timers, concurrency, random, hidden network) - ensure tests pass in “run mode” (CI-like)

  1. Optimize

- reduce expensive setup per test file - tune Vitest config: pool, isolate, workers, cache, deps optimization, sharding

  1. Deliver

- include config + scripts changes needed for local + CI - include README notes if non-obvious

Naming and structure conventions

  • Place tests next to code for discoverability:

- src/foo.tssrc/foo.test.ts - src/components/Button.tsxsrc/components/Button.test.tsx

  • Use __tests__ for framework-driven routes when colocation is awkward (Next example uses this convention).
  • Prefer describe('<unit>') with focused it('does X when Y').

Vitest execution modes and what to target

  • Local development: vitest (watch mode by default when TTY is detected).
  • CI: vitest run (forces a single run and is non-interactive).

From the Vitest CLI guide, Vitest defaults to watch mode when process.stdout.isTTY is true and falls back to run mode otherwise, while vitest run always runs once. (See: https://vitest.dev/guide/cli)

Configuration baseline

Recommended “default” config goals

  • Use TypeScript path aliases (monorepos and Next apps frequently need this).
  • Choose an environment per project:

- node for backend/unit tests - jsdom (or happy-dom) for React component tests

  • Keep setup lightweight.

Pool choice (speed vs compatibility)

Vitest runs test files using a pool (forks, threads, vmThreads, vmForks). By default (Vitest v4 docs) it uses forks. threads can be faster but may break libraries that use native bindings; forks uses child_process and supports process APIs like process.chdir(). (See: https://vitest.dev/config/pool)

Rule of thumb:

  • Prefer threads for “pure JS/TS” unit tests.
  • Use forks if you use:

- native addons (e.g. Prisma, bcrypt, canvas) - process.* APIs that are not available in threads

  • Avoid VM pools unless you have measured wins and understand the tradeoffs.

Isolation (speed vs global leakage)

test.isolate defaults to true. Disabling can improve performance when tests don’t rely on side effects (often true for Node-only units). (See: https://vitest.dev/config/isolate)

Rule of thumb:

  • Keep isolate: true for frontend/component tests (jsdom) and any suite that touches global state.
  • Consider isolate: false for Node-only pure units *after* you have strong isolation discipline.

File-level and test-level parallelism

- all available parallelism when watch is disabled - half when watch is enabled It also accepts a percentage string like "50%". (See: https://vitest.dev/config/maxworkers)

Cache (CI win)

Vitest caching is enabled by default and uses node_modules/.vite/vitest. (See: https://vitest.dev/config/cache)

For CI, persist this directory between runs (per branch key) for significant speedups.

Next.js 16 integration defaults

Use Next’s recommended baseline:

  • Install (TypeScript): vitest, @vitejs/plugin-react, jsdom, @testing-library/react, @testing-library/dom, vite-tsconfig-paths.
  • Configure test.environment = 'jsdom' with the React + tsconfigPaths plugins.

(See: https://nextjs.org/docs/app/guides/testing/vitest)

Important limitation noted by Next.js: Vitest currently does not support async Server Components; for async components, use E2E tests instead. (See the same Next.js guide above.)

Mocking & test doubles discipline

Preferred hierarchy (from most realistic to most isolated)

  1. Real pure functions (no mocking)
  2. In-memory fakes (e.g., fake repo with a Map)
  3. Contract-driven stubs (minimal, stable)
  4. Spies (vi.spyOn) for verifying interactions
  5. Module mocks (vi.mock) only when necessary

Mock reset policy

  • Default: clean up per test file:

- afterEach(() => vi.restoreAllMocks())

  • If you use global stubs (env/globals), clean them up in afterEach too.

Timers

Use fake timers to avoid slow sleeps. Vitest’s docs show using vi.useFakeTimers() with vi.runAllTimers() / vi.advanceTimersByTime() to speed time-based code. (See: https://vitest.dev/guide/mocking/timers)

Advanced note: if you configure fakeTimers.toFake to include nextTick, it is not supported with --pool=forks because Node’s child_process uses process.nextTick internally and can hang; it is supported with --pool=threads. (See: https://vitest.dev/config/faketimers)

CI reporting and sharding

Reporters

Sharding (multi-machine parallel CI)

Use --shard with the blob reporter and merge at the end. Vitest recommends the blob reporter for sharded runs and provides --merge-reports. (See: https://vitest.dev/guide/reporters)

Using test projects for multi-environment suites

Use test.projects to run multiple configurations in one process (monorepos or mixed environments). Vitest notes the older “workspace” name is deprecated in favor of projects. (See: https://vitest.dev/guide/projects)

Patterns:

  • project A: environment: 'node', pool: 'threads', isolate: false
  • project B: environment: 'jsdom', isolate: true

Deliverables this skill produces

When invoked, this skill can generate or update:

  • Vitest config(s): vitest.config.ts, multi-project configs, CI overrides
  • Test setup: setupTests.ts, test utils, mocks
  • Tests: unit, integration, React component tests, type tests
  • CI scripts: sharding + merging reports, coverage, flake detection
  • Performance tuning recommendations with measurable steps

Output quality gates

Before finalizing, ensure:

  • No test uses real timers (setTimeout waits), real network, or real clock time without explicit control.
  • All mocks/stubs are restored.
  • Tests pass with:

- vitest - vitest run

  • On CI, tests emit machine-readable artifacts (JUnit, JSON, blob merge) if requested.
  • Coverage settings match team goals and don’t create “coverage theater”.

Where to look for authoritative details (official docs)

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

36.26%
按下载量换算23

Claude

27.34%
按下载量换算17

Cursor

19.13%
按下载量换算12

Gemini CLI

8.39%
按下载量换算5

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

操作浏览器

该 Skill 可能涉及浏览器控制能力,使用时可能读取或操作网页内容,需要在受控环境中确认权限边界。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills