decorators
它能做什么
这项技能是 Ginkgo 装饰器的参考手册,这些装饰器会改变测试的运行方式或选择方式。适合需要选对选项的 Go 测试开发者。
适用场景
- ✓当你想让某些 Ginkgo 测试一次只运行一个,或按固定顺序运行的时候。
- ✓当你想为测试加上标签,以便只运行其中一部分的时候。
- ✓当某个较慢的测试需要超时或重试设置时。
技能链接
https://github.com/onsi/ginkgo/blob/master/plugins/ginkgo/skills/decorators/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请让这个 Ginkgo 测试单独运行,不要并行,并设置 30 秒超时。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体为每个节点选择合适的装饰器,例如用 Serial 禁止并行运行,用 NodeTimeout 设置时间限制,并检查每个装饰器可以放在哪些类型的代码块上。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Ginkgo decorator reference
Terse lookup. Decorators are passed alongside a node's text/closure: It("...", Serial, Label("slow"), func(){...}). Most attach to containers and/or subjects; some are setup-only or interruptible-only. Decorators on a container apply to all nodes within it; the innermost/most-specific wins when they conflict. Full docs: https://onsi.github.io/ginkgo/#decorator-reference.
Execution / ordering
Serial(container, subject) — never runs in parallel; Ginkgo runs serial specs last, on process #1. →ginkgo:parallelism.Ordered(container only) — child specs run in definition order, never reordered; enablesBeforeAll/AfterAll. →ginkgo:ordering-and-flakes.ContinueOnFailure(outermostOrderedcontainer only) — a failing spec doesn't skip the rest of the ordered group.OncePerOrdered(setup nodes) — makes aBeforeEach/AfterEachrun once around anOrderedcontainer (like aBeforeAll) instead of per-spec.SpecPriority(int)(container, subject) — hint to run higher-priority specs earlier; use sparingly, not to impose a total order.
Selection / filtering (→ ginkgo:filtering)
Label("a", "b")(container, subject) — tag specs for--label-filter; labels union down the hierarchy. No&|!,()/"chars.Focus(container, subject) — run only focused specs; don't commit it (CI exits non-zero). Constructors:FDescribe,FContext,FIt,FEntry.Pending(container, subject) — never run (and never compiled into the run set); no closure needed. Constructors:PDescribe,XDescribe,PIt,XIt,PEntry.SemVerConstraint(">= 2.0.0", ...)/ComponentSemVerConstraint("redis", ">= 8.0.0")(container, subject) — run only when--sem-ver-filtersatisfies the constraint; children may narrow, not widen.
Flakiness / repetition (→ ginkgo:ordering-and-flakes)
FlakeAttempts(n)(container, subject) — retry a failing spec up tontimes; a later pass marks it flaky, not failed. CLI--flake-attempts=noverrides.MustPassRepeatedly(n)(container, subject) — the spec must passntimes in a row to count as passed.
Timeouts / interruption (interruptible nodes — those taking ctx SpecContext; → ginkgo:timeouts-and-async)
NodeTimeout(d)(subject, setup,DeferCleanup/DeferOnFailure) — deadline for a single interruptible node.SpecTimeout(d)(Itonly) — deadline for the whole spec (all its nodes combined).GracePeriod(d)(subject, setup,DeferCleanup/DeferOnFailure) — how long Ginkgo waits for an interrupted node to return before leaking it; overrides--grace-period.
Progress reporting (→ ginkgo:debugging-failures)
PollProgressAfter(d)(subject, setup) — emit a progress report if the node runs longer thand;0disables.PollProgressInterval(d)(subject, setup) — interval between progress reports once they start.SuppressProgressReporting(subject, setup) — silence progress reports for this node.
Wrapping / advanced
AroundNode(fn)(any node, incl.RunSpecs) — wrap a node's execution; forms a stack on a container applied to every descendant node (unlikeBeforeEach, which runs once per spec). Forms: a barefunc(), a context transformerfunc(context.Context) context.Context, or a full wrapperfunc(ctx, func(context.Context)).
Location / identity (rarely needed by hand)
Offset(n)(any node) — skipnstack frames when computing the reported code location. PreferGinkgoHelper()inside helper funcs instead.CodeLocation(loc)(any node) — supply atypes.CodeLocationexplicitly.
Tables
EntryDescription("format %d")— auto-formatEntrydescriptions from their parameters; usable table-wide or per-entry. →ginkgo:tables-and-dynamic-specs.Entry/Italso acceptLabel,Focus,Pending,FlakeAttempts, etc. — every decorator above works on table entries.
Reporting
ReportEntryVisibility{Always,FailureOrVerbose,Never}— passed toAddReportEntryto control console emission. →ginkgo:reporting.
常见问题
装饰器能应用于一组测试吗?
有些可以。这项技能说明了哪些装饰器适用于一组测试,哪些只适用于单个测试。
两个装饰器冲突时怎么办?
距离测试最近、最具体的那个优先。
应该提交 Focus 吗?
不应该。这项技能提醒不要提交 Focus,否则持续集成会失败。
详情
作者的原始描述
One-line reference for every Ginkgo decorator, grouped by what it does, with the node types each can decorate — Serial, Ordered, ContinueOnFailure, OncePerOrdered, Label, Focus, Pending, FlakeAttempts, MustPassRepeatedly, NodeTimeout, SpecTimeout, GracePeriod, PollProgressAfter/Interval, SuppressProgressReporting, SpecPriority, SemVerConstraint, AroundNode, Offset/CodeLocation, EntryDescription. Use to look up a decorator's exact name, semantics, and where it's legal.
repo: onsi/ginkgo
热度
- GitHub 星标
- 9.1k
- 排名
- #12300
- 许可证
- MIT
- 更新时间
- 2026/10/9
评论
- …
同一仓库的更多技能
ci
9.1k帮你的智能体为持续集成设置 Ginkgo 测试,使用推荐的参数,能捕捉遗留的 Focus 或 Pending 标记以及不稳定的测试。
debugging-failures
9.1k帮你的智能体通过阅读摘要行,并从 JSON 报告中提取确切的失败测试和消息,找出 Ginkgo 测试失败的原因。
filtering
9.1k帮你的智能体只运行部分 Ginkgo 测试,按正确的优先顺序使用 pending、skip、focus、标签、版本约束和文件过滤器。
ordering-and-flakes
9.1k帮你的智能体控制 Go 测试的执行顺序并处理不稳定的测试,使用 Ginkgo 的 Serial 和 Ordered 设置以及重试选项。