cypress-flake-fixer
它能做什么
这个 AI 智能体可以帮你查找并修复自动化软件测试(Cypress)中的问题。它会寻找导致测试间歇性失败的代码模式,并给出修改建议。
适用场景
- ✓你的测试偶尔会失败,但并非每次都失败时。
- ✓你的测试在自己电脑上能通过,但在其他环境(比如持续集成(CI))中失败时。
- ✓你要把 Cypress 升级到新版本,并想确保旧测试仍然可以运行时。
技能链接
https://github.com/github/awesome-copilot/blob/main/skills/cypress-flake-fixer/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请帮我查找并修复 Cypress 项目中的不稳定测试(flaky test)问题。”
每周 5 个新技能,1 分钟读完。
工作原理
它会分析你的 Cypress 测试代码,查找已知的会导致测试不稳定的模式。然后它会建议修改方案,让测试更可靠,而不是单纯地增加等待时间或强制执行操作。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Cypress Flake Fixer
Audit an existing Cypress suite for the code patterns that cause intermittent failures, then fix them without hiding the problem behind retries, longer timeouts, or force: true.
When to Use This Skill
- A Cypress spec passes locally and fails in CI, or fails once in every few runs
- The suite contains
cy.wait(<number>),{ force: true }, or tests that only pass in order - Errors mention "detached from the DOM", "timed out retrying", or a subject that "is no longer attached"
- The project is upgrading Cypress across a major version (12 through 16)
- A review of Cypress test code is requested
For writing new Cypress tests from scratch, coding standards are enough. This skill is for diagnosing and repairing an existing suite.
Prerequisites
- Node.js 18 or later to run the scanner (it has no dependencies and does not need Cypress installed)
- The Cypress version, read from
package.json. Fixes differ by major version
Workflow
1. Scan
node ./scripts/scan-cypress.mjs <project-root>
node ./scripts/scan-cypress.mjs <project-root> --json # machine-readable
node ./scripts/scan-cypress.mjs <project-root> --strict # add low-confidence rules
node ./scripts/scan-cypress.mjs cypress/e2e/checkout.cy.ts # one file
The scanner reads the Cypress version from the nearest package.json and grades removed APIs as error when the installed major already rejects them and warn when they break on upgrade. Run --list-rules for the catalog.
Findings are heuristic. Open each location and confirm before editing.
2. Measure before changing anything
When the goal is to fix a specific flaky spec, record how often it fails first. Without a baseline there is no way to tell a fix from luck.
for i in $(seq 1 20); do npx cypress run --spec "cypress/e2e/checkout.cy.ts" --quiet || echo "FAIL $i"; done
A spec that fails 1 run in 10 needs about 30 clean runs after the fix before the fix is believable.
3. Fix in this order
| Order | Rules | Why first |
|---|---|---|
| 1 | CY002, CY003, CY007 graded error |
The test is wrong or already broken; other fixes build on correct command flow |
| 2 | CY001, intercept ordering | Time-based waits are the largest single source of flake |
| 3 | CY005, CY006 | Broken retry-ability causes detached-DOM and one-shot assertion failures |
| 4 | CY004 | force: true hides a real overlap, animation, or disabled state |
| 5 | CY008, CY010, CY012 | State leaks and order dependence |
| 6 | CY013, CY101, CY102 | Selector and assertion hygiene |
Before-and-after code for every rule is in references/anti-patterns.md. Replacements for removed APIs are in references/removed-apis.md. Read the section for the rule being fixed; do not load both files upfront.
4. Replace each fixed wait with the condition it was standing in for
Do not delete a cy.wait(n) or swap it for a guess. Work out what the delay covered:
| The wait covered | Replace with |
|---|---|
| A network request | cy.intercept(...).as('x') registered before the trigger, then cy.wait('@x') |
| A render that follows a request or state change | A .should() on the DOM that results |
| A debounce, throttle, polling interval, or toast timeout | cy.clock() before cy.visit(), then cy.tick(ms) |
| A CSS animation or transition | An assertion on the final state; Cypress already waits for the element to stop moving before acting |
| Client-side hydration of server-rendered HTML | A signal the app sets when hydration finishes (see Gotchas) |
| Unknown | Run the test in npx cypress open, select the wait in the Command Log, and read which requests and DOM changes happened during it |
5. Verify
- Run the changed spec alone, then repeat it at least as many times as the baseline run.
- Rerun the scanner and compare counts per rule.
- Run the full suite once to catch order dependence exposed by the change.
Rules for the fix itself
- Change test code only. If the test exposes an application bug (double submit, missing loading state, race in the UI), report it instead of working around it.
- Do not raise
defaultCommandTimeout, addretries, or add{ force: true }to make a test pass. Each one converts a visible failure into a slower or hidden one. - Do not replace
cy.wait(2000)withcy.wait(5000), or with.should('exist')on an element that was already present.
…
常见问题
什么是“不稳定”的测试(flaky tests)?
不稳定的测试是指即使被测代码没有任何改动,它有时通过、有时失败。这类测试很让人头疼,因为它无法可靠地说明软件是否正常工作。
使用这个智能体需要安装什么吗?
不需要。这个 AI 智能体无需安装,它通过分析你提供的代码来工作。
什么是“反模式”(anti-patterns)?
反模式是一些常见的编码做法。它们一开始看起来可以工作,但往往会在后续引发问题,比如测试不稳定或难以维护。
详情
作者的原始描述
Find and fix flake-prone anti-patterns in an existing Cypress suite, and APIs removed in Cypress 12 to 16. Bundles a zero-dependency scanner for fixed cy.wait() delays, assigned command return values, async/await, force: true, chaining after actions, one-shot expect() inside .then(), conditional testing, and removed APIs such as Cypress.env(), cy.exec(), cy.server()/cy.route(). Use when asked to f
repo: github/awesome-copilot
热度
- GitHub 星标
- 40k
- 排名
- #7157
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …
同一仓库的更多技能
acquire-codebase-knowledge
40k帮你的智能体理解并编写现有代码项目的文档。它有助于新成员快速上手,或者快速了解项目架构。
acreadiness-assess
40k让你的智能体评估一个项目对 AI 的准备程度,并生成报告。它有助于了解项目在使用 AI 工具方面的准备情况。
acreadiness-generate-instructions
40k帮你的智能体根据评估结果编写 AI 工具的指令文件。它有助于改善 AI 与代码的交互方式,并弥补已发现的不足。
acreadiness-policy
40k让你的智能体协助制定或应用 AI 项目评估的政策。它有助于规范项目的评估方式,并确保合规。