Token导航 LogoToken导航TokenDH.com
效率操作浏览器clawhub未标认证来源可访问clear审计提醒

setup-unit-test设置单元测试

Agent Skill

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

总安装

8,256

周安装

344

GitHub Stars

1

下载量

2,752
OpenClaw

安装说明

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

GitHub

来源数

2

许可证

MIT-0

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

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

请帮我安装这个 Agent Skill:setup-unit-test(设置单元测试)
来源仓库:https://github.com/hibehero/setup-unit-test
安装命令:
openclaw skills install setup-unit-test
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

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

ClawHubOpenClaw
openclaw skills install setup-unit-test

简介

一键初始化前端项目的单元测试环境,支持 React、Vue、TypeScript 与 Next.js 框架。

  • 适用于自动化测试搭建、用例生成与回归验证等效率场景。
  • 通过 openclaw skills install setup-unit-test 安装,需确认项目结构与依赖管理工具。
  • 依赖本地包管理与测试框架,建议检查框架兼容性与配置文件。
  • 使用前请核实是否允许修改项目文件、执行测试命令及访问外部资源,避免破坏现有逻辑。

SKILL.md

name
setup-unit-test
description
>

Security & Permissions Statement

This skill performs the following privileged operations to automate test environment configuration:

  • File System: Reads package.json and writes config files (vitest.config.ts, .claude/commands/*.md).
  • Shell Execution: Runs npm/yarn/pnpm commands to install dependencies, and runs git commands to detect staged files.
  • Git Hooks: Initializes Husky and modifies .husky/pre-commit to automate the testing workflow.

All scripts run locally and will not transmit project data to external servers (unless explicitly sent to Claude via a command invocation).


Initialize Unit Testing Environment

One-click setup of a production-grade unit testing solution for any frontend project. Detect environment → Install enhanced plugins → Auto alias resolution → AI command injection.

Workflow

Step 1: Detect Project Environment

Run the detection script to identify project details:

node <skill-dir>/scripts/detect-framework.mjs <project-dir>

Returns JSON containing: os, framework, isNext, typescript, hasTsConfig, packageManager, hasGit, hasVitest, etc.

Step 2: Install Enhanced Dependencies

Install dev dependencies (-D) using the corresponding package manager. Skip already-installed dependencies.

Core Toolchain:

  • vitest
  • @vitest/ui (visual test interface)
  • @vitest/coverage-v8 (code coverage)
  • jsdom (browser environment simulation)
  • msw (API network request mocking)
  • vitest-tsconfig-paths (auto-resolve path aliases from tsconfig.json)

Additional for React/Next.js projects:

  • @testing-library/react
  • @testing-library/jest-dom
  • @testing-library/user-event
  • @vitejs/plugin-react

Additional for Vue projects:

  • @testing-library/vue
  • @testing-library/jest-dom
  • @testing-library/user-event
  • @vitejs/plugin-vue

Step 3: Generate Smart Config Files

vitest.config.ts

Uses the tsconfigPaths() plugin for "zero-config alias resolution".

import { defineConfig } from 'vitest/config'
import react from '@vitejs/plugin-react'
import vue from '@vitejs/plugin-vue'
import tsconfigPaths from 'vitest-tsconfig-paths'

export default defineConfig({
  plugins: [
    tsconfigPaths(),
    // react(), // Enable for React/Next.js projects
    // vue(),   // Enable for Vue projects
  ],
  test: {
    globals: true,
    environment: 'jsdom',
    include: ['tests/unit/**/*.test.{ts,tsx}'],
    setupFiles: ['./tests/unit/setup/index.ts'],
    coverage: {
      provider: 'v8',
      reporter: ['text', 'html', 'json-summary'],
      include: ['src/**/*.{ts,tsx,vue}'],
      exclude: ['src/**/*.stories.*', 'src/**/*.d.ts'],
      thresholds: { statements: 70, branches: 70, functions: 70, lines: 70 },
    },
    // Additional config for Next.js server component mocking can be added here
  },
})

tests/unit/setup/index.ts

import '@testing-library/jest-dom/vitest'
import { afterAll, afterEach, beforeAll, vi } from 'vitest'
import { server } from './msw-server'

// Global Mock example (e.g., Next.js Router)
// vi.mock('next/navigation', () => ({ useRouter: () => ({ push: vi.fn() }) }))

beforeAll(() => server.listen({ onUnhandledRequest: 'warn' }))
afterEach(() => server.resetHandlers())
afterAll(() => server.close())

Step 4: Inject AI Commands (Cross-Project Reuse)

Write prompt templates to the project's .claude/commands/:

  • gen-unit-test.md: Core test generation instructions.
  • fix-test.md: Automated failure repair instructions.

Step 5: Automation Integration (Git Hooks)

5.1 Install Husky & lint-staged

5.2 Copy check-missing-tests.mjs

5.3 Write .husky/pre-commit (dual-layer guard)

  • Layer 1: vitest related --run (only run tests affected by the current changes).
  • Layer 2: When AUTO_GEN_TEST=1, detect missing tests and invoke Claude Code to auto-generate them.

Step 6: Verification & Summary Output

Initialization complete:
- Framework:       [detection result] (Next.js compatible)
- Alias resolution: Enabled (vitest-tsconfig-paths)
- Visual UI:       Enabled (npm run test:ui)
- Coverage threshold: 70% (manually adjustable in vitest.config.ts)
- AI automation:   Injected /gen-unit-test and /fix-test commands
- Auto-generation: Disabled by default, enable via export AUTO_GEN_TEST=1

Resource Files

  • scripts/detect-framework.mjs — Environment detection script (with OS and Next.js detection)
  • scripts/check-missing-tests.mjs — Cross-platform path-compatible test checking script
  • references/gen-unit-test-prompt.md
  • references/fix-test-prompt.md

适合场景

01

OpenClaw 用户查找和安装 Skill 时

02

用户想查找某类 Agent Skill 时

03

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

04

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

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

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

能力 4

补充不同宿主或平台的使用分布数据

能力 5

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

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

平台分布

OpenClaw

83.22%
按下载量换算2,290

安全审计

VirusTotal

通过

ClawScan

可疑

Static analysis

可疑

权限和风险

操作浏览器

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

安装前确认

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

来源信息

继续浏览同类 Skills