Token导航 LogoToken导航

Agent Skill · 前端设计

vitest-v4(Vitest V4 测试)

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

vitest-v4 是前端设计类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为操作浏览器;许可证信息还不明确,第三方扫描已通过,按安装量在前端设计类的 10,216 个 Skill 里排第 6,576。

总安装 489周安装 21GitHub Stars 8下载 171核验 2026-05-01

安装说明

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

安装方式

通过对话安装

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

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

命令行安装

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

skills.shnpx skills
npx skills add https://github.com/nodnarbnitram/claude-code-extensions --skill vitest-v4

这个 Skill 是做什么的

前端设计类 Skill 关注页面结构、视觉规范和组件写法,输出通常是可运行的界面代码。

用于辅助测试设计、自动化测试、用例整理和回归验证。适合编写单元测试、端到端测试、测试计划或根据失败日志定位问题。使用时需确认项目测试框架、运行命令和夹具数据,避免误改真实逻辑。

安装命令:npx skills add https://github.com/nodnarbnitram/claude-code-extensions --skill vitest-v4。涉及浏览器或外部服务时应区分本地模拟、测试环境和生产环境。

来源仓库内路径:skills/vitest-v4

上手步骤

4 步
  1. 1

    确认自己的宿主工具

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

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/nodnarbnitram/claude-code-extensions --skill v…;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

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

  4. 4

    按最小权限试用

    它需要操作浏览器,先在测试目录或测试账号里跑,确认没问题再放到正式项目。

常见问题

6 条

vitest-v4 怎么安装?

在终端执行 npx skills add https://github.com/nodnarbnitram/claude-code-extensions --skill vitest-v4。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

vitest-v4 支持哪些 AI 工具?

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

vitest-v4 需要什么权限?

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

vitest-v4 是免费的吗?

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

vitest-v4 用的人多吗?

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

vitest-v4 安全吗?

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

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

值得选的地方

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

先想清楚的地方

  • 许可证没有明确标注,能不能商用、能不能再分发都不确定。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

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

不太适合

  • 需要明确授权才能用到公司项目里的场景。
  • 需要厂商级技术支持和 SLA 的生产系统。

前端设计类 Skill 对比

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

前端设计 · Codex、Claude

8,823,360126,072只读MIT通过
vercel-composition-patterns

Vercel 组合模式 · Codex、Claude

3,858,81625,893需要联网MIT通过
vercel-react-native-skills

Vercel React native skills 前端 · Codex、Claude

2,468,66425,878只读MIT通过
adapt

adapt 搜索 · Codex、Claude

2,027,04023,125操作浏览器未明确通过
bolder

bolder 分析 · Codex、Claude

2,004,28823,130只读未明确通过
vitest-v4

Vitest V4 测试 · 本页

4898操作浏览器未明确通过

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

SKILL.md 原文

Vitest 4 Testing Skill

Write, configure, and debug Vitest 4 test suites with Vite-native patterns.

Before You Start

This skill prevents 7+ common Vitest 4 mistakes and saves ~50% tokens.

MetricWithout SkillWith Skill
Setup Time~90 min~30 min
Common Errors7+0
Token UsageHigh (trial/error)Low (known patterns)

Known Issues This Skill Prevents

  1. Hanging agent runs from using watch mode instead of vitest run
  2. Broken coverage configs from using removed coverage.all or coverage.extensions
  3. Browser Mode spying failures from sealed ESM namespace objects
  4. Mock leakage between tests from missing restore/reset config
  5. Invalid multi-project setup from using deprecated workspace terminology
  6. Wrong APIs from mixing Jest helpers into Vitest tests
  7. Flaky browser interactions from using synthetic helpers instead of vitest/browser
  8. Slow or unstable large suites from choosing the wrong execution pool or isolation mode

Quick Start

Step 1: Configure Vitest 4 for agent-safe runs

// vitest.config.ts
import { defineConfig } from 'vitest/config';

export default defineConfig({
  test: {
    environment: 'node',
    restoreMocks: true,
    clearMocks: true,
    coverage: {
      provider: 'v8',
      include: ['src/**/*.{ts,tsx}'],
    },
  },
});

Why this matters: Vitest 4 removed coverage.all and coverage.extensions, and agent/CI environments need one-shot execution plus automatic mock cleanup.

Step 2: Write tests with Vitest APIs, not Jest APIs

import { describe, expect, it, vi } from 'vitest';
import { addUser } from './add-user';
import * as api from './api';

describe('addUser', () => {
  it('returns the created user', async () => {
    vi.spyOn(api, 'createUser').mockResolvedValue({ id: '1', name: 'Ada' });

    await expect(addUser('Ada')).resolves.toEqual({ id: '1', name: 'Ada' });
  });
});

Why this matters: vi is the supported mocking API. Mixing jest.fn() or Jest-only patterns causes confusing failures and poor autocomplete.

Import rule: Import describe, it, expect, and vi from vitest unless the project explicitly enables globals: true.

Step 3: Use the correct runtime command

vitest run
vitest run --coverage
vitest run path/to/example.test.ts

Why this matters: vitest without run starts watch mode by default in development, which is a poor fit for agents, CI, and non-interactive verification.

Critical Rules

Always Do

  • Use vitest run or vitest --no-watch for agent and CI workflows
  • Prefer vi.mock(import('./module')) for type-safe module mocks
  • Configure restoreMocks, clearMocks, or mockReset intentionally
  • Use projects for multi-project configs; the rename began in Vitest 3.2 and older workspace-file usage is removed in Vitest 4
  • Use a shared base config when multiple projects need common settings; projects do not inherit root config unless you opt in
  • Use coverage.include to report on untested source files
  • Use page and userEvent from vitest/browser in Browser Mode
  • Prefer forks when native modules or runtime compatibility matter more than raw speed
  • Share vitest.config.ts and the implementation file when asking AI to generate tests

Never Do

  • Never use jest.fn, jest.spyOn, or Jest-only globals in Vitest code
  • Never rely on removed coverage.all or coverage.extensions in Vitest 4
  • Never use plain watch mode for agent-driven verification
  • Never use vi.spyOn on native ESM exports in Browser Mode
  • Never forget that vi.mock() is hoisted before the rest of the file executes
  • Never leave env/global stubs un-restored across tests

Common Mistakes

Wrong - removed coverage option:

export default defineConfig({
  test: {
    coverage: {
      all: true,
    },
  },
});

Correct - use include globs:

export default defineConfig({
  test: {
    coverage: {
      provider: 'v8',
      include: ['src/**/*.{ts,tsx}'],
    },
  },
});

Why: Vitest 4 removed coverage.all and coverage.extensions; coverage.include is the supported way to include uncovered files.

Wrong - Browser Mode spy on sealed export:

import * as math from './math';
import { vi } from 'vitest';

vi.spyOn(math, 'add').mockReturnValue(10);

Correct - use spy-enabled module mock:

import { vi } from 'vitest';

vi.mock(import('./math'), { spy: true });

Why: Native browser ESM namespace objects are sealed, so direct spies on exports fail in Browser Mode.

Known Issues Prevention

IssueRoot CauseSolution
Tests never exitWatch mode started in a non-interactive sessionUse vitest run
Coverage report misses untested filescoverage.include not configuredAdd explicit source globs
Browser Mode spy throws or does nothingvi.spyOn used on sealed ESM exportsUse vi.mock(import('./mod'), {spy: true})
Mocks leak between testsCleanup flags missingEnable restoreMocks / clearMocks / unstubEnvs
Multi-project config breaks after upgradeDeprecated workspace terminology or removed workspace-file patterns carried overSwitch to projects and defineProject
Worker or pool config stops workingOld maxThreads, maxForks, or poolOptions carried forwardMigrate to Vitest 4 worker settings such as maxWorkers
Project-specific config unexpectedly disappearsRoot config assumptions are not inherited into projectsUse extends: true, mergeConfig, or a shared base explicitly
AI-generated tests use wrong helpersJest patterns copied into VitestReplace with vi, Vitest imports, and Vitest matchers
Browser tests hangBlocking dialogs or wrong user-event utilitiesMock dialogs and use vitest/browser helpers
Fast pool causes strange native-module failuresthreads chosen for a suite that needs process isolationSwitch to forks or narrow thread usage

Bundled Resources

References

Configuration Reference

vitest.config.ts

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'],
          environment: 'node',
        },
      }),
      defineProject({
        test: {
          name: 'browser',
          include: ['src/**/*.browser.test.ts'],
          browser: {
            enabled: true,
            provider: playwright(),
            instances: [{ browser: 'chromium' }],
          },
        },
      }),
    ],
    coverage: {
      provider: 'v8',
      include: ['src/**/*.{ts,tsx}'],
    },
    restoreMocks: true,
    unstubEnvs: true,
    setupFiles: ['./test/setup.ts'],
  },
});

Key settings:

  • test.projects: Stable multi-project terminology; the rename started in Vitest 3.2, and projects do not automatically inherit every root config value, so shared settings should be factored into a reused base when needed
  • coverage.include: Required when uncovered source files must appear in the report
  • browser.provider: In Vitest 4, import the provider factory from the provider package, such as playwright()
  • restoreMocks / unstubEnvs: Prevent test pollution across files
  • setupFiles: Run shared test initialization such as MSW, globals, or polyfills before test files

Project Structure

my-app/
├── src/
│   ├── feature.ts
│   ├── feature.test.ts
│   └── feature.browser.test.ts
├── vitest.config.ts
├── vite.config.ts
└── package.json

Why this matters: Keeping Node and Browser Mode tests clearly separated makes provider setup, test selection, and troubleshooting much simpler.

Choose the right environment: Prefer jsdom for most component tests and lightweight DOM assertions. Use Browser Mode when native browser APIs, real layout/event behavior, or screenshot assertions matter.

Choose the right execution model: Prefer forks for stability and native-module compatibility, especially in mixed or infrastructure-heavy suites. Reach for threads only when you know the test environment is safe for worker-thread execution and the extra speed matters.

Common Patterns

Type-safe module mock pattern

import { beforeEach, describe, expect, it, vi } from 'vitest';
import { getUserName } from './get-user-name';
import * as api from './api';

vi.mock(import('./api'), () => ({
  fetchUser: vi.fn(),
}));

describe('getUserName', () => {
  beforeEach(() => {
    vi.mocked(api.fetchUser).mockReset();
  });

  it('returns the fetched user name', async () => {
    vi.mocked(api.fetchUser).mockResolvedValue({ id: '1', name: 'Ada' });

    await expect(getUserName('1')).resolves.toBe('Ada');
  });
});

Browser Mode interaction pattern

import { expect, test } from 'vitest';
import { page, userEvent } from 'vitest/browser';
import { render } from 'vitest-browser-react';
import { Counter } from './counter';

test('increments after click', async () => {
  render(<Counter />);

  await userEvent.click(page.getByRole('button', { name: /increment/i }));

  await expect.element(page.getByText('1')).toBeInTheDocument();
});

In-source testing pattern

export function sum(a: number, b: number) {
  return a + b;
}

if (import.meta.vitest) {
  const { it, expect } = import.meta.vitest;

  it('adds numbers', () => {
    expect(sum(1, 2)).toBe(3);
  });
}

Dependencies

Required

PackageVersionPurpose
vitest^4Test runner and assertion/mocking APIs
vite^6Shared Vite-powered module pipeline
node>=20Required runtime for Vitest 4

Optional

PackageVersionPurpose
@vitest/coverage-v8^4Fast, accurate coverage with AST remapping
@vitest/coverage-istanbul^4Istanbul coverage backend
@vitest/browser-playwright^4Playwright provider for Browser Mode
@vitest/browser-webdriverio^4WebdriverIO provider for Browser Mode
@vitest/browser-preview^4Preview provider for Browser Mode

Official Documentation

Troubleshooting

Agent run hangs forever

Symptoms: The test process never exits or Claude waits for additional file changes.

Solution:

vitest run

Browser Mode test cannot spy on export

Symptoms: vi.spyOn() throws, does nothing, or works in Node mode but fails in browser.

Solution:

vi.mock(import('./module'), { spy: true });

Coverage misses source files with no tests

Symptoms: The report only contains files touched by executed tests.

Solution:

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

Legacy worker or pool settings break after upgrade

Symptoms: Old maxThreads, maxForks, singleThread, singleFork, or poolOptions settings stop working after moving to Vitest 4.

Solution:

test: {
  maxWorkers: 4,
}

Why: Vitest 4 simplified worker configuration and removed several older pool-specific options.

Setup Checklist

Before using this skill, verify:

  • Node.js is >=20
  • vite is >=6
  • vitest.config.ts or vite.config.ts contains a test block
  • Agent/CI commands use vitest run
  • Coverage provider packages are installed if coverage is enabled
  • Browser provider packages are installed if Browser Mode is enabled

平台分布

Codex

33.28%
按下载量换算57

Claude

29.35%
按下载量换算50

Cursor

20.65%
按下载量换算35

Gemini CLI

8.45%
按下载量换算14

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

操作浏览器

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

安装前确认

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

继续浏览同类 Skills