filtering
Skill này làm gì
Skill này giải thích nhiều cách để chạy một tập con của các bài kiểm thử Go Ginkgo. Nó dành cho lập trình viên muốn chạy một nhóm, bỏ qua các nhóm khác, hoặc đánh dấu bài kiểm thử là chưa sẵn sàng.
Khi nào nên dùng
- ✓Khi bạn muốn chỉ chạy một phần của một bộ kiểm thử Ginkgo lớn.
- ✓Khi một bài kiểm thử chưa sẵn sàng và nên được bỏ qua tạm thời.
- ✓Khi bạn muốn chạy các bài kiểm thử có một nhãn cụ thể, chẳng hạn slow hoặc integration.
Liên kết skill
https://github.com/onsi/ginkgo/blob/master/plugins/ginkgo/skills/filtering/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Chỉ chạy các bài kiểm thử Ginkgo có nhãn integration, và bỏ qua mọi bài được đánh dấu pending.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Agent chọn giữa dấu pending lúc biên dịch, bỏ qua lúc chạy, focus, bộ lọc nhãn và bộ lọc tên, rồi giải thích cách chúng kết hợp, vì một số tùy chọn ghi đè các tùy chọn khác.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
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 labelslists labels in a package;ginkgo --dry-run -v --label-filter=Qshows 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
Câu hỏi thường gặp
Có thể ép một bài kiểm thử pending chạy không?
Không. Không gì có thể ghi đè dấu pending, nên bài kiểm thử vẫn bị bỏ qua.
Khác nhau giữa pending và skip là gì?
Pending được đặt lúc biên dịch, còn skip được quyết định trong lúc chạy.
Các bài kiểm thử pending có làm build thất bại không?
Mặc định thì không, nhưng một tùy chọn fail-on-pending sẽ làm CI thất bại nếu còn bài nào pending.
Chi tiết
Mô tả gốc của tác giả
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
Độ phổ biến
- Sao GitHub
- 9.1k
- Vị trí xếp hạng
- #12301
- Giấy phép
- MIT
- Cập nhật
- 9/10/2026
Bình luận
- …
Thêm skill từ kho mã này
ci
9.1kGiúp agent của bạn thiết lập kiểm thử Ginkgo cho CI, với các cờ khuyến nghị để bắt dấu focus hoặc pending còn sót và bài kiểm thử không ổn định.
debugging-failures
9.1kGiúp agent của bạn tìm lý do kiểm thử Ginkgo bị lỗi bằng cách đọc dòng tóm tắt và lấy đúng các bài thất bại cùng thông báo từ báo cáo JSON.
decorators
9.1kGiúp agent của bạn dùng đúng các decorator của kiểm thử Ginkgo, như Serial, Ordered, Label, Focus và timeout, bằng cách giải thích mỗi decorator làm gì.
ordering-and-flakes
9.1kGiúp agent của bạn kiểm soát thứ tự chạy kiểm thử Go và xử lý bài không ổn định, bằng Serial, Ordered và tùy chọn thử lại của Ginkgo.
Skill tương tự
test-driven-development
311kDạy agent của bạn viết kiểm thử thất bại trước, xem nó thất bại, rồi viết đoạn mã ngắn nhất để vượt qua trước khi làm bất kỳ tính năng hay bản sửa nào.
verification-before-completion
311kDạy agent của bạn chạy kiểm tra thực tế và đọc kết quả đầu ra trước khi khẳng định một việc, bản sửa hoặc bản build đã hoàn thành hay vượt qua.
migrate-to-shoehorn
310kThay các ép kiểu rủi ro trong tệp kiểm thử bằng thư viện shoehorn, để các bài kiểm thử dùng dữ liệu một phần vẫn qua được kiểm tra kiểu.