Token导航 LogoToken导航

Agent Skill · 开发

vitest(Vitest 测试)

用于辅助 API 设计、接口文档、请求响应结构和服务集成说明。它适合让 Agent 梳理 endpoint、生成 OpenAPI 草稿、检查字段命名、整理错误码或辅助前后端联调。使用时需要确认真实业务语义、鉴权方式、分页和错误处理规则;涉及生成接口文档时,应避免凭空补字段,最好从现有代码、schema 或接口样例中提取事实。

vitest 是开发类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为接触敏感数据;许可证信息还不明确,第三方扫描已通过,按安装量在开发类的 21,746 个 Skill 里排第 20,060。

总安装 242周安装 10GitHub Stars 6下载 79核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
unknown

安装方式

通过对话安装

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

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

命令行安装

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

skills.shnpx skills
npx skills add https://github.com/ghosttypes/ff-5mp-api-ts --skill vitest

这个 Skill 是做什么的

开发类 Skill 面向写代码、改代码和排查问题,一般会读写仓库文件,部分还会执行构建或测试命令。

Vitest 测试技能辅助 API 设计和接口文档生成,支持字段命名和结构检查。适用于服务集成说明和联调支持等前后端协作场景。通过 GitHub 仓库安装,使用 npx skills add 命令启用技能模块。使用时需结合现有 schema 或接口样例,避免生成与实际不符的接口定义。

vitest 属于开发类 Skill,可作为该场景下的辅助能力补充。

来源仓库内路径:skills/vitest

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/ghosttypes/ff-5mp-api-ts --skill vitest;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它需要接触敏感数据,先在测试目录或测试账号里跑,确认没问题再放到正式项目。

常见问题

6 条

vitest 怎么安装?

在终端执行 npx skills add https://github.com/ghosttypes/ff-5mp-api-ts --skill vitest。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

vitest 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

vitest 需要什么权限?

权限级别是接触敏感数据。该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

vitest 是免费的吗?

公开资料没有标注明确许可证,收费和商用限制都无法确认。正式使用前请到来源仓库核对授权说明。

vitest 用的人多吗?

公开数据是累计安装 242 次,近一周安装 10 次,下载 79 次,GitHub 6 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

vitest 安全吗?

第三方扫描结果为通过,但这只覆盖已知的静态检查项,不能替代自己读一遍源码和安装命令。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。
  • 第三方扫描已通过,常见的高风险行为没有命中。

先想清楚的地方

  • 需要接触敏感数据,装到常用环境前要先评估影响面。
  • 许可证没有明确标注,能不能商用、能不能再分发都不确定。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理开发类任务、又不想每次都手写提示词的人。

不太适合

  • 环境里有大量密钥、凭证,不方便给第三方 Skill 读取的人。
  • 需要明确授权才能用到公司项目里的场景。
  • 需要厂商级技术支持和 SLA 的生产系统。

开发类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
skill-vetter

技能审查员 · OpenClaw

8,779,018986操作浏览器MIT-0通过
ontology

本体论 · OpenClaw

6,636,960576只读MIT-0通过
entra-app-registration

内部应用程序注册 · Codex、Claude

6,631,872764接触敏感数据未明确通过
entra-app-registration

内部应用程序注册 · Codex、Claude

3,757,680201接触敏感数据未明确通过
nano-banana-pro

纳米香蕉专业版 · OpenClaw

3,526,898364接触敏感数据MIT-0有提醒
vitest

Vitest 测试 · 本页

2426接触敏感数据未明确通过

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

Vitest

Overview

Vitest is a blazing-fast unit test framework powered by Vite. This skill provides complete Vitest documentation, APIs, configuration options, and migration guides to enable flawless test development in any JavaScript or TypeScript project.

Key capabilities:

  • Vite-native for instant feedback and HMR
  • Jest-compatible API for easy migration
  • Works in Vite and non-Vite projects
  • Built-in TypeScript, JSX, and ESM support
  • Native code coverage (V8 and Istanbul)
  • Browser mode for component testing
  • Workspace support for monorepos

Quick Start Decision Tree

Is this a new project or adding tests to an existing project?

  • New project: Start with "Installation & Setup"
  • Existing project: Check framework type below

What type of project is it?

  • Vite/Vue/React/Svelte: Use Vite integration (see "Vite Project Setup")
  • Non-Vite (Next.js, Angular, vanilla): Use standalone mode (see "Standalone Project Setup")
  • Monorepo: Use workspace configuration (see "Workspace Setup")

Are you migrating from Jest?

  • Yes: See "Migration from Jest" section

Installation & Setup

Basic Installation

# Install Vitest
npm install -D vitest

# Add test script to package.json
{
  "scripts": {
    "test": "vitest",
    "test:ui": "vitest --ui"
  }
}

Vite Project Setup

For projects already using Vite, extend the existing vite.config.ts:

import { defineConfig } from 'vitest/config'

export default defineConfig({
  test: {
    // test options
  },
  // your existing Vite config
})

Vitest automatically shares your Vite config, plugins, and transformations.

Standalone Project Setup

For non-Vite projects, create vitest.config.ts:

import { defineConfig } from 'vitest/config'

export default defineConfig({
  test: {
    include: ['**/*.{test,spec}.{js,ts}'],
    environment: 'node' // or 'jsdom' for browser environment
  }
})

Framework-specific setup guides:

  • Next.js: See references/guide/index.md for configuration
  • Angular: Use environment: 'jsdom' with appropriate transformers
  • React/Vue/Svelte: Extend Vite config for best experience

TypeScript Setup

Vitest supports TypeScript out of the box. Ensure tsconfig.json includes test files:

{
  "include": ["src/**/*", "**/*.test.ts"]
}

Writing Tests

Basic Test Structure

// math.test.ts
import { describe, it, expect } from 'vitest'
import { add } from './math'

describe('add', () => {
  it('should add two numbers', () => {
    expect(add(1, 2)).toBe(3)
  })

  it('should handle negative numbers', () => {
    expect(add(-1, -2)).toBe(-3)
  })
})

Test Organization

  • Use describe blocks to group related tests
  • Name test files with .test.ts or .spec.ts suffix
  • Co-locate tests with source code or in __tests__ directories
  • Use test context for sharing data between tests (see references/guide/test-context.md)

Lifecycle Hooks

import { beforeAll, beforeEach, afterAll, afterEach } from 'vitest'

describe('database tests', () => {
  beforeAll(async () => {
    // Runs once before all tests
    await connectDatabase()
  })

  beforeEach(async () => {
    // Runs before each test
    await clearDatabase()
  })

  afterEach(async () => {
    // Runs after each test
    await cleanup()
  })

  afterAll(async () => {
    // Runs once after all tests
    await disconnectDatabase()
  })
})

For complete lifecycle reference, see references/api/hooks.md.

Running Tests

# Run all tests once
vitest run

# Watch mode (default)
vitest

# Run matching pattern
vitest --testNamePattern="should add"

# UI mode
vitest --ui

# Coverage
vitest --coverage

See references/guide/cli.md for complete CLI reference.

Mocking

Vitest provides comprehensive mocking capabilities through the vi utility.

Function Mocking

import { vi, describe, it, expect } from 'vitest'

const mockFn = vi.fn()
mockFn('hello')
expect(mockFn).toHaveBeenCalledWith('hello')

// With return value
const mocked = vi.fn().mockReturnValue('test')
expect(mocked()).toBe('test')

// With implementation
const callback = vi.fn((x) => x + 1)
expect(callback(1)).toBe(2)

Module Mocking

import { vi, expect, it } from 'vitest'
import { fetchData } from './api'

// Mock entire module
vi.mock('./api', () => ({
  fetchData: vi.fn(() => Promise.resolve('mocked data'))
}))

it('uses mocked API', async () => {
  const data = await fetchData()
  expect(data).toBe('mocked data')
})

Timer Mocking

import { vi, beforeEach, expect, it } from 'vitest'

beforeEach(() => {
  vi.useFakeTimers()
})

it('calls callback after timeout', () => {
  const callback = vi.fn()
  setTimeout(callback, 1000)

  vi.advanceTimersByTime(1000)
  expect(callback).toHaveBeenCalled()
})

Complete mocking reference:

  • Functions: references/guide/mocking/functions.md
  • Modules: references/guide/mocking/modules.md
  • Timers: references/guide/mocking/timers.md
  • Globals: references/guide/mocking/globals.md
  • Dates: references/guide/mocking/dates.md

Configuration Patterns

Common Configuration Scenarios

1. Browser Environment (React/Vue/Svelte)

import { defineConfig } from 'vitest/config'

export default defineConfig({
  test: {
    environment: 'jsdom',
    globals: true,
    setupFiles: ['./src/test/setup.ts']
  }
})

2. Code Coverage

export default defineConfig({
  test: {
    coverage: {
      provider: 'v8', // or 'istanbul'
      include: ['src/**/*.{js,ts}'],
      exclude: ['src/**/*.test.{js,ts}', 'src/**/*.config.{js,ts}']
    }
  }
})

3. Monorepo/Workspace

export default defineConfig({
  test: {
    workspace: [
      'packages/*',
      'apps/*'
    ]
  }
})

4. Browser Mode (Component Testing)

export default defineConfig({
  test: {
    browser: {
      enabled: true,
      provider: 'playwright', // or 'webdriverio'
      headless: true
    }
  }
})

See references/config/INDEX.md for complete configuration reference.

Advanced Features

Snapshot Testing

import { expect, it } from 'vitest'

it('matches snapshot', () => {
  const data = { foo: 'bar' }
  expect(data).toMatchSnapshot()
})

See references/guide/snapshot.md for complete snapshot guide.

In-Source Testing

Write tests directly next to code:

// src/math.ts
export function add(a: number, b: number) {
  return a + b
}

// @ts-ignore
if (import.meta.vitest) {
  const { it, expect } = import.meta.vitest
  it('adds numbers', () => {
    expect(add(1, 2)).toBe(3)
  })
}

See references/guide/in-source.md for configuration.

Test Tags

Organize and filter tests by tags:

import { test } from 'vitest'

test('slow integration test', { tags: ['@slow', '@integration'] }, () => {
  // test code
})

// Run only fast tests
// vitest --tags @fast

See references/guide/test-tags.md for usage.

Browser Testing

Test components in real browser:

import { expect, test } from 'vitest'
import { render } from '@testing-library/vue'

test('renders button', async () => {
  const { getByText } = render(Button, {
    props: { label: 'Click me' }
  })

  expect(getByText('Click me')).toBeTruthy()
})

See references/guide/browser/ for complete browser testing guide.

Migration

From Jest to Vitest

Vitest is largely compatible with Jest. The migration process:

  1. Install Vitest: npm install -D vitest
  2. Update configuration: Replace jest.config.js with vitest.config.ts
  3. Update scripts: Change test script to use vitest
  4. Update imports: Replace @jest/globals with vitest
  5. Verify mocks: Most Jest mocks work unchanged

Key differences:

  • Auto-mocked modules: Vitest doesn't auto-mock by default
  • Timer mocks: Use vi.useFakeTimers() instead of jest.useFakeTimers()
  • Environment variables: Use process.env directly

See references/guide/comparisons.md for detailed Jest comparison.

From Older Vitest Versions

Migrating to Vitest 4.0:

  • Coverage provider changes: V8 now uses AST-based remapping
  • Removed coverage.all and coverage.extensions - use coverage.include instead
  • Coverage ignore hints updated - see references/guide/migration.md

See migration guides:

  • Vitest 4.0: references/guide/migration.md#vitest-4
  • Vitest 3.0: references/vitest-3.md
  • Vitest 3.2: references/vitest-3-2.md

Troubleshooting

Common Issues

Tests run in wrong environment:

// vitest.config.ts
export default defineConfig({
  test: {
    environment: 'jsdom' // for browser tests
    // or 'node' for server tests
  }
})

Modules not transforming:

  • Check transformMode configuration
  • Ensure dependencies are in deps.interopDefault

Timeouts:

  • Increase timeout: test({timeout: 10000}, () => {...})
  • Or globally: test: {timeout: 10000}

Watch mode not detecting changes:

  • Check file inclusion patterns
  • Verify include and exclude in config

See references/guide/common-errors.md for more troubleshooting.

Resources

This skill includes comprehensive Vitest documentation organized for progressive disclosure:

Documentation Indices

Key Documentation

Getting Started:

Core Concepts:

Mocking:

API Reference:

Configuration:

Migration:

Advanced:

When working with Vitest, consult the appropriate reference file based on your task. Start with the guide for conceptual understanding, then refer to API/config references for specific implementation details.

平台分布

Claude

32.51%
按下载量换算26

Codex

32.21%
按下载量换算25

Cursor

20.16%
按下载量换算16

Gemini CLI

10.19%
按下载量换算8

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

接触敏感数据

该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

安装前确认

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

继续浏览同类 Skills