mcpField
T
test-focus

test-focus

github.com/laurigates测试与质量5956 次安装1 天前更新
代码仓库

关于 test-focus

test-focus 面向需要迭代单个失败测试文件的开发者,可识别常见测试框架并以快速失败方式运行,并支持串行或调试模式。

主要功能

  1. 01按测试框架生成命令
  2. 02单文件快速失败运行
  3. 03可选串行执行
  4. 04可选可视化或调试模式
  5. 05提供失败信息和重跑命令

适用场景

  1. 01快速重跑已知失败的测试
  2. 02串行运行共享状态测试
  3. 03可视化调试单个浏览器测试文件

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/laurigates/claude-plugins --skill test-focus

安装后在 Claude Code 中输入/test-focus确认已加载。

详细介绍

适用场景

在以下情况下使用此技能……在以下情况下改用 test-run……
针对单个失败的测试用例迭代,并快速获取失败反馈运行项目的完整测试套件
对 WebGL 或共享状态测试强制串行执行在多个文件中以监视模式运行测试(使用 test-quick)
以有头/调试模式运行单个测试文件排查某个目录中的测试结果(使用 test-analyze)
针对已知有问题的文件,获取 30 秒以内的反馈选择要运行的测试层级(使用 test-tier-selection)

上下文

  • 项目文件: !find . -maxdepth 1 \( -name 'pyproject.toml' -o -name 'package.json' -o -name 'Cargo.toml' -o -name 'go.mod' \)
  • Playwright 配置: !find . -maxdepth 1 -name 'playwright.config.*'
  • Vitest 配置: !find . -maxdepth 1 \( -name 'vitest.config.*' -o -name 'vite.config.*' \)
  • Jest 配置: !find . -maxdepth 1 -name 'jest.config.*'
  • Pytest 配置: !find . -maxdepth 1 \( -name pyproject.toml -o -name setup.cfg \) -exec grep -l 'pytest' {} +
  • Package.json 是否存在: !find . -maxdepth 1 -name 'package.json' -type f

参数

  • $1(必填):测试文件路径或模式(例如,login.spec.ts、tests/e2e/auth.spec.ts)
  • --serial:强制使用单个工作线程顺序执行(适用于 WebGL、数据库测试)
  • --debug:以调试/有头模式运行,便于进行可视化调试

你的任务

以快速失败模式运行单个测试文件,加快开发迭代。首次失败时立即停止,以尽量缩短反馈时间。

1. 检测测试框架并构造命令

Playwright(存在 playwright.config.* 时):

# Standard fail-fast
bunx playwright test "$FILE" --max-failures=1 --reporter=line

# With --serial (WebGL, shared state)
bunx playwright test "$FILE" --max-failures=1 --workers=1 --reporter=line

# With --debug
bunx playwright test "$FILE" --max-failures=1 --headed --debug

Vitest(存在 vitest.config.* 或 vite.config.* 时):

# Standard fail-fast
bunx vitest run "$FILE" --bail=1 --reporter=dot

# With --serial
bunx vitest run "$FILE" --bail=1 --pool=forks --poolOptions.threads.singleThread --reporter=dot

# With --debug
bunx vitest run "$FILE" --bail=1 --inspect-brk

Jest(存在 jest.config.* 时):

# Standard fail-fast
bunx jest "$FILE" --bail --silent

# With --serial
bunx jest "$FILE" --bail --runInBand --silent

# With --debug
bunx jest "$FILE" --bail --runInBand

pytest(Python 项目):

# Standard fail-fast
python -m pytest "$FILE" -x -v --tb=short

# With --serial (already serial by default)
python -m pytest "$FILE" -x -v --tb=short

# With --debug
python -m pytest "$FILE" -x -v --tb=long -s

Cargo test(Rust 项目):

# Standard fail-fast
cargo test --test "$FILE" -- --test-threads=1

# With --debug
cargo test --test "$FILE" -- --test-threads=1 --nocapture

Go test:

# Standard fail-fast
go test -v -failfast "$FILE"

# With --debug
go test -v -failfast "$FILE" -count=1
2. 执行测试

运行构造的命令。捕获并显示输出。

3. 分析结果

如果测试通过:

[FILE]: PASSED
Duration: Xs

Ready for next iteration or file.

如果测试失败:

[FILE]: FAILED (stopped at first failure)
Duration: Xs

First failure:
  Test: [test name]
  Error: [brief error message]
  Location: [file:line]

Quick actions:
- Fix the issue and re-run: /test:focus [same file]
- Debug visually: /test:focus [file] --debug
- See full output: /test:run [file]
4. 提供重新运行命令

始终显示重新运行测试的确切命令:

Rerun: /test:focus $FILE

节省时间的背景

有针对性地进行测试可显著缩短反馈时间:

方式典型耗时使用场景
/test:focus2-30 秒针对单个文件进行迭代
/test:quick30 秒修改后运行单元测试
/test:full5-30 分钟提交/PR 前

Agent 式优化

上下文标志
Playwright 快速模式--max-failures=1 --reporter=line
Playwright WebGL--max-failures=1 --workers=1 --reporter=line
Vitest 快速模式--bail=1 --reporter=dot
Jest 快速模式--bail --silent
pytest 快速模式-x -v --tb=short

错误处理

  • 如果找不到文件:使用 glob 列出相似的测试文件,并建议更正路径
  • 如果未检测到框架:显示 package.json 中包含 "test" 的可用脚本
  • 如果测试超时:建议使用 --serial 标志或延长超时时间

评论

支持 Markdown