configure-tests

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

/configure:tests

/configure:tests

Check and configure testing frameworks against best practices (Vitest, Jest, pytest, cargo-nextest).
根据最佳实践检查并配置测试框架(Vitest、Jest、pytest、cargo-nextest)。

When to Use This Skill

何时使用该技能

Use this skill when...Use another approach when...
Setting up testing infrastructureJust running tests (use
/test:run
skill)
Checking test framework configurationTests already properly configured
Migrating to modern test frameworks (Vitest, pytest, nextest)Writing individual tests (write tests directly)
Validating coverage configurationDebugging failing tests (check test output)
Ensuring test best practicesSimple project with no testing needed
使用该技能的场景...使用其他方法的场景...
搭建测试基础设施仅运行测试(使用
/test:run
技能)
检查测试框架配置测试已正确配置完成
迁移至现代测试框架(Vitest、pytest、nextest)编写单个测试用例(直接编写测试)
验证覆盖率配置调试失败的测试(查看测试输出)
确保测试符合最佳实践无需测试的简单项目

Context

上下文信息

  • Package.json: !
    find . -maxdepth 1 -name \'package.json\' 2>/dev/null
  • Pyproject.toml: !
    find . -maxdepth 1 -name \'pyproject.toml\' 2>/dev/null
  • Cargo.toml: !
    find . -maxdepth 1 -name \'Cargo.toml\' 2>/dev/null
  • Test config files: !
    find . -maxdepth 1 \( -name 'vitest.config.*' -o -name 'jest.config.*' -o -name 'pytest.ini' -o -name '.nextest.toml' \) 2>/dev/null
  • Pytest in pyproject: !
    grep -c 'tool.pytest' pyproject.toml 2>/dev/null
  • Test directories: !
    find . -maxdepth 2 -type d \( -name 'tests' -o -name '__tests__' -o -name 'test' \) 2>/dev/null
  • Test scripts in package.json: !
    grep -m5 -o '"test[^"]*"' package.json 2>/dev/null
  • Coverage config: !
    grep -l 'coverage' vitest.config.* jest.config.* 2>/dev/null
  • Project standards: !
    head -20 .project-standards.yaml 2>/dev/null
Modern testing stack preferences:
  • JavaScript/TypeScript: Vitest (preferred) or Jest
  • Python: pytest with pytest-cov
  • Rust: cargo-nextest for improved performance
  • Package.json: !
    find . -maxdepth 1 -name \'package.json\' 2>/dev/null
  • Pyproject.toml: !
    find . -maxdepth 1 -name \'pyproject.toml\' 2>/dev/null
  • Cargo.toml: !
    find . -maxdepth 1 -name \'Cargo.toml\' 2>/dev/null
  • 测试配置文件: !
    find . -maxdepth 1 \( -name 'vitest.config.*' -o -name 'jest.config.*' -o -name 'pytest.ini' -o -name '.nextest.toml' \) 2>/dev/null
  • pyproject中的pytest配置: !
    grep -c 'tool.pytest' pyproject.toml 2>/dev/null
  • 测试目录: !
    find . -maxdepth 2 -type d \( -name 'tests' -o -name '__tests__' -o -name 'test' \) 2>/dev/null
  • package.json中的测试脚本: !
    grep -m5 -o '"test[^"]*"' package.json 2>/dev/null
  • 覆盖率配置: !
    grep -l 'coverage' vitest.config.* jest.config.* 2>/dev/null
  • 项目标准: !
    head -20 .project-standards.yaml 2>/dev/null
现代测试技术栈偏好:
  • JavaScript/TypeScript:Vitest(优先推荐)或Jest
  • Python:搭配pytest-cov的pytest
  • Rust:性能更优的cargo-nextest

Parameters

参数

Parse these from
$ARGUMENTS
:
FlagDescription
--check-only
Report status without offering fixes
--fix
Apply all fixes automatically without prompting
--framework <framework>
Override framework detection (
vitest
,
jest
,
pytest
,
nextest
)
$ARGUMENTS
中解析以下参数:
标记说明
--check-only
仅报告状态,不提供修复方案
--fix
自动应用所有修复,无需确认
--framework <framework>
覆盖框架自动检测结果(可选值:
vitest
jest
pytest
nextest

Version Checking

版本检查

CRITICAL: Before flagging outdated versions, verify latest releases:
  1. Vitest: Check vitest.dev or GitHub releases
  2. Jest: Check jestjs.io or npm
  3. pytest: Check pytest.org or PyPI
  4. cargo-nextest: Check nexte.st or GitHub releases
Use WebSearch or WebFetch to verify current versions before reporting outdated frameworks.
关键注意事项:在标记版本过时前,请先验证最新版本:
  1. Vitest:查看vitest.devGitHub releases
  2. Jest:查看jestjs.ionpm
  3. pytest:查看pytest.orgPyPI
  4. cargo-nextest:查看nexte.stGitHub releases
在报告框架版本过时前,请使用WebSearch或WebFetch工具验证当前最新版本。

Execution

执行步骤

Execute this testing framework compliance check:
执行以下测试框架合规性检查:

Step 1: Detect framework

步骤1:检测框架

Identify the project language and existing test framework:
IndicatorLanguageDetected Framework
vitest.config.*
JavaScript/TypeScriptVitest
jest.config.*
JavaScript/TypeScriptJest
pyproject.toml
[tool.pytest]
Pythonpytest
pytest.ini
Pythonpytest
Cargo.toml
Rustcargo test
.nextest.toml
Rustcargo-nextest
If
--framework
flag is provided, use that value instead.
识别项目语言及已存在的测试框架:
识别标识语言检测到的框架
vitest.config.*
JavaScript/TypeScriptVitest
jest.config.*
JavaScript/TypeScriptJest
pyproject.toml
[tool.pytest]
Pythonpytest
pytest.ini
Pythonpytest
Cargo.toml
Rustcargo test
.nextest.toml
Rustcargo-nextest
若提供了
--framework
标记,则使用该标记指定的框架。

Step 2: Analyze current state

步骤2:分析当前状态

Read the detected framework's configuration and check completeness. For each framework, verify:
Vitest:
  • Config file exists (
    vitest.config.ts
    or
    .js
    )
  • globals: true
    configured for compatibility
  • environment
    set appropriately (jsdom, happy-dom, node)
  • Coverage configured with
    @vitest/coverage-v8
    or
    @vitest/coverage-istanbul
  • Watch mode exclusions configured
Jest:
  • Config file exists (
    jest.config.js
    or
    .ts
    )
  • testEnvironment
    configured
  • Coverage configuration present
  • Transform configured for TypeScript/JSX
  • Module path aliases configured
pytest:
  • pyproject.toml
    has
    [tool.pytest.ini_options]
    section
  • testpaths
    configured
  • addopts
    includes useful flags (
    -v
    ,
    --strict-markers
    )
  • markers
    defined for test categorization
  • pytest-cov
    installed
cargo-nextest:
  • .nextest.toml
    exists
  • Profile configurations (default, ci)
  • Retry policy configured
  • Test groups defined if needed
读取检测到的框架配置并检查完整性。针对每个框架,验证以下内容:
Vitest:
  • 配置文件存在(
    vitest.config.ts
    .js
  • 已配置
    globals: true
    以确保兼容性
  • environment
    已正确设置(jsdom、happy-dom、node)
  • 已通过
    @vitest/coverage-v8
    @vitest/coverage-istanbul
    配置覆盖率
  • 已配置监听模式排除项
Jest:
  • 配置文件存在(
    jest.config.js
    .ts
  • testEnvironment
    已配置
  • 存在覆盖率配置
  • 已为TypeScript/JSX配置转换规则
  • 已配置模块路径别名
pytest:
  • pyproject.toml
    中包含
    [tool.pytest.ini_options]
    章节
  • testpaths
    已配置
  • addopts
    包含实用标记(
    -v
    --strict-markers
  • 已定义
    markers
    用于测试分类
  • 已安装
    pytest-cov
cargo-nextest:
  • .nextest.toml
    存在
  • 已配置Profile(默认、ci)
  • 已配置重试策略
  • 按需定义了测试分组

Step 3: Report results

步骤3:报告结果

Print a compliance report with:
  • Detected framework and version
  • Configuration check results for each item
  • Test organization (unit/integration/e2e directories)
  • Package scripts status (test, test:watch, test:coverage)
  • Overall issue count and recommendations
If
--check-only
, stop here.
输出合规性报告,包含:
  • 检测到的框架及版本
  • 各项配置的检查结果
  • 测试组织方式(单元/集成/e2e目录)
  • 包脚本状态(test、test:watch、test:coverage)
  • 问题总数及改进建议
若使用
--check-only
标记,执行至此结束。

Step 4: Apply fixes (if --fix or user confirms)

步骤4:应用修复(若使用--fix或用户确认)

Install dependencies and create configuration using templates from REFERENCE.md:
  1. Missing config: Create framework config file from template
  2. Missing dependencies: Install required packages
  3. Missing coverage: Add coverage configuration with 80% threshold
  4. Missing scripts: Add test scripts to package.json
  5. Missing test directories: Create standard test directory structure
REFERENCE.md中获取模板,安装依赖并创建配置:
  1. 缺失配置:从模板创建框架配置文件
  2. 缺失依赖:安装所需包
  3. 缺失覆盖率配置:添加覆盖率配置,阈值设为80%
  4. 缺失脚本:向package.json中添加测试脚本
  5. 缺失测试目录:创建标准测试目录结构

Step 5: Set up test organization

步骤5:设置测试组织方式

Create standard test directory structure for the detected language. See directory structure patterns in REFERENCE.md.
为检测到的语言创建标准测试目录结构。目录结构模式请参考REFERENCE.md

Step 6: Configure CI/CD integration

步骤6:配置CI/CD集成

Check for test commands in GitHub Actions workflows. If missing, add CI test commands using the CI templates from REFERENCE.md.
检查GitHub Actions工作流中是否包含测试命令。若缺失,使用REFERENCE.md中的CI模板添加CI测试命令。

Step 7: Handle migration (if upgrading)

步骤7:处理迁移(若升级框架)

If migrating between frameworks (e.g., Jest to Vitest, unittest to pytest), follow the migration guide in REFERENCE.md.
若在框架间迁移(如从Jest迁移到Vitest,从unittest迁移到pytest),请遵循REFERENCE.md中的迁移指南。

Step 8: Update standards tracking

步骤8:更新标准跟踪文件

Update
.project-standards.yaml
:
yaml
standards_version: "2025.1"
last_configured: "<timestamp>"
components:
  tests: "2025.1"
  tests_framework: "<vitest|jest|pytest|nextest>"
  tests_coverage_threshold: 80
  tests_ci_integrated: true
For detailed configuration templates, migration guides, CI/CD integration examples, and directory structure patterns, see REFERENCE.md.
更新
.project-standards.yaml
yaml
standards_version: "2025.1"
last_configured: "<timestamp>"
components:
  tests: "2025.1"
  tests_framework: "<vitest|jest|pytest|nextest>"
  tests_coverage_threshold: 80
  tests_ci_integrated: true
详细的配置模板、迁移指南、CI/CD集成示例及目录结构模式,请查看REFERENCE.md

Agentic Optimizations

智能优化

ContextCommand
Detect test framework
find . -maxdepth 1 \( -name 'vitest.config.*' -o -name 'jest.config.*' -o -name 'pytest.ini' \) 2>/dev/null
Check coverage config
grep -l 'coverage' package.json pyproject.toml 2>/dev/null
List test files
find . \( -path '*/tests/*' -o -path '*/test/*' -o -name '*.test.*' -o -name '*.spec.*' \) 2>/dev/null | head -n 10
Quick compliance check
/configure:tests --check-only
Auto-fix configuration
/configure:tests --fix
上下文命令
检测测试框架
find . -maxdepth 1 \( -name 'vitest.config.*' -o -name 'jest.config.*' -o -name 'pytest.ini' \) 2>/dev/null
检查覆盖率配置
grep -l 'coverage' package.json pyproject.toml 2>/dev/null
列出测试文件
find . \( -path '*/tests/*' -o -path '*/test/*' -o -name '*.test.*' -o -name '*.spec.*' \) 2>/dev/null | head -n 10
快速合规性检查
/configure:tests --check-only
自动修复配置
/configure:tests --fix

Error Handling

错误处理

  • No package.json found: Cannot configure JS/TS tests, skip or error
  • Conflicting frameworks: Warn about multiple test configs, require manual resolution
  • Missing dependencies: Offer to install required packages
  • Invalid config syntax: Report parse error, offer to replace with template
  • 未找到package.json:无法配置JS/TS测试,跳过或抛出错误
  • 框架冲突:警告存在多个测试配置,需手动解决
  • 缺失依赖:提示安装所需包
  • 配置语法无效:报告解析错误,提示使用模板替换

See Also

相关内容

  • /configure:coverage
    - Configure coverage thresholds and reporting
  • /configure:all
    - Run all compliance checks
  • /test:run
    - Universal test runner
  • /test:setup
    - Comprehensive testing infrastructure setup
  • Vitest documentation: https://vitest.dev
  • pytest documentation: https://docs.pytest.org
  • cargo-nextest documentation: https://nexte.st
  • /configure:coverage
    - 配置覆盖率阈值与报告
  • /configure:all
    - 运行所有合规性检查
  • /test:run
    - 通用测试运行器
  • /test:setup
    - 全面测试基础设施搭建
  • Vitest文档https://vitest.dev
  • pytest文档https://docs.pytest.org
  • cargo-nextest文档https://nexte.st