360 Secure SkillHub
360 安全技能中心

Jest Config Validator

核心功能:校验jest.config系列文件及package.json中的Jest配置,覆盖22+规则(含结构、环境、转换、覆盖率、弃用项、最佳实践),支持全量验证、语法检查、配置解释、优化建议等命令。典型场景:Jest配置验证、版本迁移、测试环境审计。输入为配置文件路径,输出有文本、JSON、摘要三种格式,提供CI友好的退出码。

charlie-morrison
charlie-morrison
热度 56.35
最近更新 2026-05-11 17:44:47
分类:开发依赖:代码执行 / 读写文件应用场景:代码审查 / 调试排错 / DevOps

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add jest-config-validator
Metadata
name
jest-config-validator
description
Validate jest.config.ts/js/json and Jest configuration in package.json for deprecated options, transform conflicts, and best practices. Use when validating Jest test runner configs, auditing test setups, migrating Jest versions, or linting jest.config files.

Jest Config Validator

Validate jest.config.ts, jest.config.js, jest.config.json, and package.json#jest for deprecated options, transform conflicts, coverage misconfigurations, and best practices. Supports text, JSON, and summary output formats with CI-friendly exit codes.

Commands

# Full validation (all 22+ rules)
python3 scripts/jest_config_validator.py validate jest.config.js

# Quick syntax-only check (structure rules only)
python3 scripts/jest_config_validator.py check jest.config.ts

# Explain config in human-readable form
python3 scripts/jest_config_validator.py explain jest.config.json

# Suggest improvements
python3 scripts/jest_config_validator.py suggest package.json

# JSON output (CI-friendly)
python3 scripts/jest_config_validator.py validate jest.config.js --format json

# Summary only (pass/fail + counts)
python3 scripts/jest_config_validator.py validate jest.config.js --format summary

# Strict mode (warnings become errors)
python3 scripts/jest_config_validator.py validate jest.config.js --strict

Rules (22+)

# Category Severity Rule
S1 Structure Error File not found or unreadable
S2 Structure Error Empty config or missing module.exports/export default
S3 Structure Warning Both jest.config and package.json#jest present (conflict)
S4 Structure Warning Unknown top-level config keys detected
S5 Structure Error Invalid JSON syntax (for .json configs)
T1 Test Environment Error Invalid testEnvironment value
T2 Test Environment Warning testEnvironment: jsdom without jest-environment-jsdom (Jest 28+)
T3 Test Environment Warning testURL deprecated in Jest 28+ (use testEnvironmentOptions)
T4 Test Environment Warning Empty testMatch or testPathPattern
X1 Transforms Warning Overlapping transform patterns (conflict)
X2 Transforms Warning ts-jest and babel-jest used together without clear separation
X3 Transforms Warning transformIgnorePatterns too broad (may skip needed transforms)
X4 Transforms Warning Missing transform for .tsx/.jsx when React detected
V1 Coverage Warning collectCoverageFrom empty or too broad
V2 Coverage Warning coverageThreshold set but collectCoverage not enabled
V3 Coverage Warning Deprecated coverageReporters values
D1 Deprecated Warning Deprecated Jest options detected
D2 Deprecated Warning jest.fn() used inside config file (configs should not mock)
D3 Deprecated Warning timers: 'fake' (old syntax, use fakeTimers object)
B1 Best Practices Info No clearMocks/resetMocks/restoreMocks set
B2 Best Practices Warning roots pointing outside project directory
B3 Best Practices Warning setupFiles/setupFilesAfterFramework path pattern issues
B4 Best Practices Info moduleNameMapper with complex regex missing comment
B5 Best Practices Warning preset and manual config overlap
B6 Best Practices Warning maxWorkers set to 1 in non-CI context

Output Formats

text (default): Human-readable with file path, rule code, severity, and message per finding.

json: Machine-readable JSON with file, summary, and findings array. Each finding has rule, severity, message, and line fields.

summary: One-line pass/fail with error/warning/info counts. Ideal for CI output gates.

Exit Codes

Code Meaning
0 No errors found (warnings/info may exist)
1 One or more errors found
2 File not found or parse error