husky-test-coverage by shipshitdev/library
npx skills add https://github.com/shipshitdev/library --skill husky-test-coverage设置或验证 Husky git 钩子,以确保每次提交时都运行测试并强制执行覆盖率阈值。
此技能自动化设置:
此技能应在以下情况下使用:
在设置测试覆盖率之前,请发现项目的上下文:
jest,查找 jest.config.js 或 jest.config.json广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
vitest,查找 vitest.config.ts 或 vitest.config.jsmocha,检查覆盖率工具(nyc, c8)coverageThresholdcoverage.thresholds.nycrc.json 或 package.json 中的覆盖率配置.husky/ 目录是否存在*.test.* 或 *.spec.* 文件# 基本设置(80% 覆盖率阈值,低于阈值则阻止提交)
python3 ~/.claude/skills/husky-test-coverage/scripts/setup-husky-coverage.py \
--root /path/to/project
# 自定义阈值(85%)
python3 ~/.claude/skills/husky-test-coverage/scripts/setup-husky-coverage.py \
--root /path/to/project \
--threshold 85
# 仅警告(不阻止提交)
python3 ~/.claude/skills/husky-test-coverage/scripts/setup-husky-coverage.py \
--root /path/to/project \
--no-fail-on-below
# 如果未找到测试则跳过
python3 ~/.claude/skills/husky-test-coverage/scripts/setup-husky-coverage.py \
--root /path/to/project \
--skip-if-no-tests
# 空运行以预览更改
python3 ~/.claude/skills/husky-test-coverage/scripts/setup-husky-coverage.py \
--root /path/to/project \
--dry-run
npx husky install).husky/pre-commit 钩子prepare 脚本添加到 package.json(如果缺失)此技能自动检测:
jest --coverage --watchAll=falsevitest --coverage --runnyc 或 c8 配合 mocha 测试命令Jest:
coverageThreshold 创建或更新 jest.config.jsonVitest:
vitest.config.ts/jsMocha + nyc:
.nycrc.json创建的钩子:
--root <path>:项目根目录(必需)--threshold <number>:覆盖率阈值百分比(默认:80)--fail-on-below:如果覆盖率低于阈值,则提交失败(默认:true)--no-fail-on-below:即使覆盖率低于阈值也允许提交--skip-if-no-tests:如果未找到测试文件,则跳过钩子--dry-run:显示将进行的更改而不实际更改在项目根目录中创建 .husky-test-coverage.json:
{
"coverageThreshold": {
"lines": 80,
"branches": 75,
"functions": 80,
"statements": 80
},
"failOnCoverageBelowThreshold": true,
"skipIfNoTests": false
}
或者,添加到 package.json:
{
"huskyTestCoverage": {
"threshold": 80,
"failOnBelow": true
}
}
检测:
jestjest.config.js 或 jest.config.json配置:
jest.config.jsonnpm test -- --coverage --watchAll=false示例 jest.config.json:
{
"coverageThreshold": {
"global": {
"lines": 80,
"branches": 75,
"functions": 80,
"statements": 80
}
}
}
检测:
vitestvitest.config.ts 或 vitest.config.js配置:
npm test -- --coverage --run示例 vitest.config.ts:
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
coverage: {
provider: 'v8',
reporter: ['text', 'json', 'html'],
thresholds: {
lines: 80,
branches: 75,
functions: 80,
statements: 80
}
}
}
})
检测:
mochanyc 或 c8)配置:
.nycrc.jsonnyc --reporter=text --reporter=html npm test示例 .nycrc.json:
{
"check-coverage": true,
"lines": 80,
"branches": 75,
"functions": 80,
"statements": 80,
"reporter": ["text", "text-summary", "html", "lcov"]
}
此技能自动检测并使用:
npm run testyarn testpnpm run testbun run test使用此技能时:
此技能可与以下技能协同工作:
| 技能 | 协同工作方式 |
|---|---|
| fullstack-workspace-init | 在脚手架搭建后自动调用,以设置 80% 覆盖率阈值 |
| linter-formatter-init | 两者都配置 Husky;此技能专注于测试覆盖率,linter-formatter-init 专注于代码检查/格式化 |
| testing-expert | 使用来自 testing-expert 技能的测试模式和覆盖率目标 |
当使用 fullstack-workspace-init 搭建新项目时,此技能会自动应用,包括:
如果您使用了 fullstack-workspace-init,则无需单独运行此技能。
如果添加到现有项目:
python3 ~/.claude/skills/husky-test-coverage/scripts/setup-husky-coverage.py \
--root /path/to/project \
--threshold 80
# 重新安装 Husky
npx husky install
chmod +x .husky/pre-commit
此技能按优先级顺序使用第一个检测到的运行器:Vitest > Jest > Mocha
当此技能处于活动状态时,Claude 将:
每周安装次数
81
仓库
GitHub 星标数
16
首次出现
2026年1月20日
安全审计
安装于
codex57
opencode55
gemini-cli55
cursor51
claude-code51
github-copilot46
Set up or verify Husky git hooks to ensure tests run and coverage thresholds are enforced on every commit.
This skill automates the setup of:
This skill should be used when:
Before setting up test coverage, discover the project's context:
Check package.json:
Identify Test Runner:
jest in dependencies, look for jest.config.js or jest.config.jsonvitest in dependencies, look for vitest.config.ts or vitest.config.jsmocha in dependencies, check for coverage tool (nyc, c8)Check Coverage Configuration:
coverageThreshold in jest.config.*coverage.thresholds in vitest.config.*.nycrc.json or coverage config in package.jsonVerify Existing Husky Setup:
.husky/ directory existsDetect Test Files:
*.test.* or *.spec.* files# Basic setup (80% coverage threshold, blocks commits below threshold)
python3 ~/.claude/skills/husky-test-coverage/scripts/setup-husky-coverage.py \
--root /path/to/project
# Custom threshold (85%)
python3 ~/.claude/skills/husky-test-coverage/scripts/setup-husky-coverage.py \
--root /path/to/project \
--threshold 85
# Warn only (don't block commits)
python3 ~/.claude/skills/husky-test-coverage/scripts/setup-husky-coverage.py \
--root /path/to/project \
--no-fail-on-below
# Skip if no tests found
python3 ~/.claude/skills/husky-test-coverage/scripts/setup-husky-coverage.py \
--root /path/to/project \
--skip-if-no-tests
# Dry run to preview changes
python3 ~/.claude/skills/husky-test-coverage/scripts/setup-husky-coverage.py \
--root /path/to/project \
--dry-run
npx husky install).husky/pre-commit hook that runs tests with coverageprepare script to package.json (if missing)The skill automatically detects:
jest --coverage --watchAll=false in pre-commit hookvitest --coverage --run in pre-commit hooknyc or c8 with mocha test commandJest:
jest.config.json with coverageThresholdVitest:
vitest.config.ts/js with coverage thresholdsMocha + nyc:
.nycrc.json with coverage thresholdsThe created hook:
--root <path>: Project root directory (required)--threshold <number>: Coverage threshold percentage (default: 80)--fail-on-below: Fail commit if coverage below threshold (default: true)--no-fail-on-below: Allow commit even if coverage below threshold--skip-if-no-tests: Skip hook if no test files found--dry-run: Show what would be done without making changesCreate .husky-test-coverage.json in project root:
{
"coverageThreshold": {
"lines": 80,
"branches": 75,
"functions": 80,
"statements": 80
},
"failOnCoverageBelowThreshold": true,
"skipIfNoTests": false
}
Alternatively, add to package.json:
{
"huskyTestCoverage": {
"threshold": 80,
"failOnBelow": true
}
}
Detection:
jest in dependenciesjest.config.js or jest.config.jsonConfiguration:
jest.config.json with coverage thresholdsnpm test -- --coverage --watchAll=falseExample jest.config.json:
{
"coverageThreshold": {
"global": {
"lines": 80,
"branches": 75,
"functions": 80,
"statements": 80
}
}
}
Detection:
vitest in dependenciesvitest.config.ts or vitest.config.jsConfiguration:
npm test -- --coverage --runExample vitest.config.ts:
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
coverage: {
provider: 'v8',
reporter: ['text', 'json', 'html'],
thresholds: {
lines: 80,
branches: 75,
functions: 80,
statements: 80
}
}
}
})
Detection:
mocha in dependenciesnyc or c8)Configuration:
.nycrc.json for nycnyc --reporter=text --reporter=html npm testExample .nycrc.json:
{
"check-coverage": true,
"lines": 80,
"branches": 75,
"functions": 80,
"statements": 80,
"reporter": ["text", "text-summary", "html", "lcov"]
}
The skill automatically detects and uses:
npm run testyarn testpnpm run testbun run testWhen using this skill:
Discover Project Context:
Detect Test Runner:
Setup or Verify Husky:
Configure Coverage:
Create Pre-commit Hook:
Verify Setup:
This skill works alongside:
| Skill | How It Works Together |
|---|---|
| fullstack-workspace-init | Automatically invoked after scaffolding to set up 80% coverage threshold |
| linter-formatter-init | Both configure Husky; this skill focuses on test coverage, linter-formatter-init focuses on linting/formatting |
| testing-expert | Uses testing patterns and coverage targets from testing-expert skill |
When using fullstack-workspace-init to scaffold a new project, this skill is automatically applied with:
You don't need to run this skill separately if you used fullstack-workspace-init.
If adding to an existing project:
python3 ~/.claude/skills/husky-test-coverage/scripts/setup-husky-coverage.py \
--root /path/to/project \
--threshold 80
# Reinstall Husky
npx husky install
chmod +x .husky/pre-commit
The skill uses the first detected runner in priority order: Vitest > Jest > Mocha
When this skill is active , Claude will:
Weekly Installs
81
Repository
GitHub Stars
16
First Seen
Jan 20, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
codex57
opencode55
gemini-cli55
cursor51
claude-code51
github-copilot46
Skills CLI 使用指南:AI Agent 技能包管理器安装与管理教程
44,900 周安装
Agent Skills (agentskills.io) - 为AI智能体创建可移植技能的规范与工具
1 周安装
LangGraph 1.x 工作流模式指南:状态管理、路由与并行执行最佳实践
80 周安装
shadcn/ui 组件库使用指南:Radix UI + Tailwind CSS 可自定义前端组件集成
1 周安装
Web性能优化专家模式 | 核心Web指标、页面加载速度与渲染性能优化工具
1 周安装
API安全审查指南:OWASP API十大风险检测与自动化测试工具
1 周安装
Claude技能创建器指南:如何构建高效AI技能模块,扩展Claude能力
1 周安装