跳到正文
Skillpedia
测试9.1k · #12301

filtering

它能做什么

这项技能讲解运行部分 Go Ginkgo 测试的多种方法。适合希望只运行某一组、跳过其他测试,或把测试标记为未就绪的开发者。

适用场景

  • ✓当你想只运行大型 Ginkgo 测试套件中的一部分时。
  • ✓当某个测试尚未就绪,需要暂时跳过的时候。
  • ✓当你想运行带有特定标签的测试,例如 slow 或 integration 时。

技能链接

https://github.com/onsi/ginkgo/blob/master/plugins/ginkgo/skills/filtering/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/onsi/ginkgo/blob/master/plugins/ginkgo/skills/filtering/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请只运行带有 integration 标签的 Ginkgo 测试,并跳过所有标记为 pending 的测试。”

每周 5 个新技能,1 分钟读完。

工作原理

智能体会在编译时的 pending 标记、运行时的 skip、focus、标签过滤器和名称过滤器之间做出选择,然后说明它们如何组合,因为有些选项会覆盖其他选项。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Filtering specs: running a subset

Ginkgo offers many ways to run fewer specs — ad-hoc (Pending/Skip/Focus) and structured (labels, semver, file/description filters). They combine by a strict precedence (see bottom). Decorator specifics live in ginkgo:decorators; label-driven CI in ginkgo:ci. Docs: https://onsi.github.io/ginkgo/#filtering-specs.

Pending — compile-time skip, uncoercible

Marks a spec/container as under development. Nothing can override Pending and make it run — not focus, not labels.

It("needs work", Pending, func() { ... })
It("placeholder", Pending)            // pending specs need no closure
PDescribe("not ready", func() { ... }) // == Describe(..., Pending); X-prefix is identical
PIt(...) / XIt(...) / PEntry(...)

Pending specs don't fail the suite. ginkgo --fail-on-pending makes them fail CI — a policy that pending specs shouldn't be committed. Pending is compile-time only; you cannot make a spec pending at runtime — for that, use Skip.

Skip — runtime skip

Call Skip("reason") from any subject or setup node to skip during the run phase. It panics to halt the spec (like Fail) and records the reason; it does not fail the suite (even skipping every spec passes).

It("if it can", func() {
	if !someCondition { Skip("special condition wasn't met") }
	...
})

Scope matters: in a BeforeEach it skips the current spec; in a BeforeAll it skips all specs in the Ordered container; in a BeforeSuite it skips the entire suite. You cannot call Skip in a container body — it only applies during the run phase.

Focus — programmatic, for iterating (don't commit it)

When any spec is focused, Ginkgo runs only focused specs.

FIt("just me", func() { ... })   // or It(..., Focus, ...)
FDescribe(...) / FContext(...) / FEntry(...)

Child focus unfocuses focused ancestors. F an inner It inside an FDescribe and only that It runs — matches how you narrow while debugging.

The danger: committing focus breaks CI quietly-loudly. A passing suite with programmatic focus exits non-zero (logs say it succeeded but flags focused specs) so CI catches it. Strip them all with ginkgo unfocus (removes F prefixes and Focus decorators).

Labels and --label-filter

Label("a", "b") (→ ginkgo:decorators) tags container/subject nodes; a spec's labels are the union down its hierarchy. No &|!,()/" chars in a label. Filter with ginkgo --label-filter=QUERY:

Operator Meaning
&& AND
`
! NOT
() grouping
/regexp/ regex match against labels

Bare words match label literals — case-insensitive, whitespace-trimmed.

ginkgo --label-filter="network && !slow"
ginkgo --label-filter="integration, smoke"   # comma == ||
ginkgo --label-filter=/library/              # regex

Consistent labelling is a best-practice for maintainable filtering.

Label sets — KEY:VALUE

A label KEY:VALUE adds VALUE to set KEY (multiple values accumulate, e.g. Label("API:Library", "API:Geo") → API = {Library, Geo}). Filter with KEY: OP <arg> where arg is a single value or {V1, V2}:

Op Matches when set KEY…
isEmpty has no KEY:* labels
containsAny contains any arg element
containsAll contains all arg elements
consistsOf equals exactly the args
isSubsetOf is a subset of args — note: an empty set always matches
ginkgo --label-filter="integration && !slow && Readiness: isSubsetOf {Beta, RC}"
ginkgo --label-filter="API: consistsOf {Library, Geo}"

Set values are literals (no regex). Prefer sets over regexes for structured filtering.

  • Suite-level labels: RunSpecs(t, "Books Suite", Label("books")) apply to the whole suite — filter out entire suites.
  • Runtime check: Label("perf").MatchesLabelFilter(GinkgoLabelFilter()) lets a spec branch on the active --label-filter (GinkgoLabelFilter() returns it).
  • Discover/iterate: ginkgo labels lists labels in a package; ginkgo --dry-run -v --label-filter=Q shows what a filter selects without running.

SemVer filtering

SemVerConstraint(">= 3.2.0") (and ComponentSemVerConstraint("redis", ">= 8.0.0")) gate specs by version; run with --sem-ver-filter. Constraints follow Masterminds/semver (~, ^, comma-ANDed). Hierarchical: child constraints *narrow

常见问题

能强制运行 pending 测试吗?

不能。没有任何设置能覆盖 pending 标记,因此该测试仍会被跳过。

pending 和 skip 有什么区别?

pending 在编译时设置,而 skip 在运行过程中决定。

pending 测试会导致构建失败吗?

默认不会,但开启失败于 pending 的选项后,只要存在 pending 测试,持续集成就会失败。

详情

作者的原始描述

Run a subset of a Ginkgo suite — Pending/PIt/XIt, runtime Skip, programmatic Focus/FIt (and ginkgo unfocus), Label with the --label-filter query language and label sets, suite-level labels, SemVerConstraint/--sem-ver-filter, --focus/--skip and --focus-file/--skip-file, the filtering precedence rules, and --fail-on-pending/--fail-on-empty. Use when you want to run, skip, focus, label, or version-gate specs, or debug why specs were or weren't selected.

repo: onsi/ginkgo

热度

GitHub 星标
9.1k
排名
#12301
许可证
MIT
更新时间
2026/10/9

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能