К основному содержанию
скилл официальный · GitHub

cypress-flake-fixer — скилл для GitHub Copilot: чинит флаки в Cypress

Скилл ищет в существующем наборе тестов Cypress шаблоны, из-за которых тесты падают через раз, и правит их. Пригодится перед обновлением до Cypress 15 или 16.

Установить в GitHub Copilot · GitHub CLI Все способы и платформы ↓
gh skill install github/awesome-copilot cypress-flake-fixer
Открыть на GitHub

Что делает cypress-flake-fixer

Скилл проходит по спекам и находит то, что даёт плавающие падения: фиксированные cy.wait(<число>), присвоение результата команды в переменную, async/await, { force: true }, цепочки после действий, одноразовый expect() внутри .then(), условные проверки. Отдельно помечает API, вырезанные в Cypress с 12 по 16: Cypress.env(), cy.exec(), cy.server() и cy.route(). Внутри лежит сканер на Node.js без зависимостей, сам Cypress ему не нужен.

Сканер читает версию Cypress из ближайшего package.json и потому по-разному оценивает удалённые API: как error, если установленная мажорная версия их уже не принимает, и как warn, если они сломаются при обновлении. Запускается так: node ./scripts/scan-cypress.mjs <project-root>, есть режимы --json, --strict и --list-rules. Находки эвристические, каждое место нужно открыть и подтвердить руками.

Перед правками скилл советует замерить, как часто спека падает: без базовой линии не отличить починку от везения. Нужен Node.js 18 или новее. Фиксированный cy.wait не удаляют, а заменяют тем условием, которое он прикрывал: перехватом запроса, проверкой DOM, cy.clock() с cy.tick(ms). Поднимать defaultCommandTimeout, добавлять retries или { force: true } скилл запрещает — так видимый провал превращается в скрытый.

Какие задачи решает

  • убрать фиксированные cy.wait(<число>) из спеков
  • разобраться с ошибкой «detached from the DOM»
  • найти API, вырезанные в Cypress с 12 по 16
  • подготовить набор тестов к обновлению до Cypress 15 или 16
  • отделить флак в тесте от бага в приложении

Примеры запросов агенту

  • просканируй cypress/e2e/checkout.cy.ts и покажи находки
  • замени фиксированные ожидания в этом спеке на условия, которые они прикрывали
  • проверь набор тестов на API, удалённые в Cypress 16

Как установить cypress-flake-fixer

1GitHub CLI

gh skill install github/awesome-copilot cypress-flake-fixer

2Вручную: положить файлы

.github/skills/cypress-flake-fixer/SKILL.md

По шагам, с командами для каждой платформы: Как установить скилл в Claude Code: пять способов

Вопросы о cypress-flake-fixer

Как установить cypress-flake-fixer в GitHub Copilot?

Выполните gh skill install github/awesome-copilot cypress-flake-fixer, файл скилла окажется по пути .github/skills/cypress-flake-fixer/SKILL.md.

Что делает cypress-flake-fixer?

Ищет в готовом наборе тестов Cypress шаблоны, которые дают нестабильные падения, и предлагает правки. Заодно отмечает API, удалённые в версиях с 12 по 16.

Что нужно для запуска сканера?

Node.js 18 или новее. Зависимостей у сканера нет, устанавливать Cypress для него не требуется.

Исходный текст

SKILL.md · MIT
---
name: cypress-flake-fixer
description: '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 fix flaky Cypress tests, remove cy.wait, stabilize or harden a Cypress suite, audit Cypress specs, debug "detached from the DOM" errors, or prepare an upgrade to Cypress 15 or 16.'
---

# 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

```bash
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.

```bash
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](./references/anti-patterns.md). Replacements for removed APIs are in [references/removed-apis.md](./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

1. Run the changed spec alone, then repeat it at least as many times as the baseline run.
2. Rerun the scanner and compare counts per rule.
3. 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`, add `retries`, 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)` with `cy.wait(5000)`, or with `.should('exist')` on an element that was already present.
- Keep one rule category per commit so a regression can be bisected.
- Fix shared custom commands in `cypress/support` first. A fixed wait inside a command runs in every test that calls it.

## Gotchas

- **Register `cy.intercept()` before the request can fire.** For requests made on page load that means before `cy.visit()`. An intercept registered after the request has left never matches, and `cy.wait('@alias')` times out intermittently depending on network speed.
- **Each `cy.wait('@alias')` consumes one request.** If the app calls the endpoint twice, the first wait resolves on the first call and the assertion runs against stale data. Wait once per expected call, or assert on the DOM.
- **GraphQL uses one URL for every operation.** Alias inside the handler: `cy.intercept('POST', '/graphql', (req) => { if (req.body.operationName === 'GetOrders') req.alias = 'getOrders' })`.
- **`.should('not.exist')` passes before the element has rendered.** Using it to wait for a spinner to disappear succeeds instantly on a slow page. Assert the positive end state.
- **Server-rendered apps accept clicks before handlers are attached.** In Next.js, Nuxt, SvelteKit, and Remix the button is visible and enabled in the server HTML, so Cypress clicks it during hydration and nothing happens. Have the app set a marker when hydration completes (for example a `data-hydrated` attribute on `<body>` from a mount effect) and assert on it after `cy.visit()`.
- **A `.should()` in the middle of a chain pins the subject.** Queries after it cannot re-query past the assertion, so a re-render produces a detached-DOM error. Split the chain at the assertion.
- **`.then()` breaks the retry chain even with no assertion inside.** Everything before it runs once.
- **Cypress 16 types with no delay between keys** (`keystrokeDelay` default changed from 10 to 0). Inputs that re-render per keystroke or debounce on input may now drop characters or fire once. Assert the field value after typing instead of restoring the delay.
- **Cypress 16 turned cookie and storage getters into queries.** `cy.getCookie()`, `cy.getCookies()`, `cy.getAllCookies()`, `cy.getAllLocalStorage()`, and `cy.getAllSessionStorage()` now retry chained `.should()` assertions, which removes the need for waits around auth cookies.
- **The page is blank after `cy.session()`.** A missing `cy.visit()` after it looks like a flaky selector failure.
- **`testIsolation: false` shares state across tests.** If the config sets it, every order-dependent failure is expected behavior, not flake. Check the config before diagnosing.
- **Retries hide flake unless configured to report it.** To find flaky tests instead of masking them, use the experimental strategy that retries and still fails:

  ```js
  retries: {
    experimentalStrategy: 'detect-flake-but-always-fail',
    experimentalOptions: { maxRetries: 2, stopIfAnyPassed: true },
    openMode: true,
    runMode: true,
  }
  ```

- **CY005 is a judgement call.** `cy.get(input).clear().type('x')` on an input that never re-renders is fine. Split the chain when the element belongs to a list, a form library that remounts fields, or anything driven by async state.

## Report format

```markdown
## Cypress flake audit: <scope>

- Cypress version: <range>, major <n>
- Files scanned: <n>
- Baseline: <spec> failed <f> of <n> runs

| Rule | Before | After | Notes |
|---|---|---|---|
| CY001 fixed-wait | 14 | 0 | 9 replaced by intercept aliases, 5 by assertions |

### Not fixed
- <location>: <reason, for example needs an application change>

### Application issues found
- <behavior the tests exposed>

### Verification
- <spec>: <n> of <n> runs passed after the change
```

## Troubleshooting

| Issue | Solution |
|---|---|
| Scanner reports "No Cypress files found" | Pass the folder that contains `cypress/` or `*.cy.*` files. Specs outside those conventions can be passed as explicit file paths |
| A finding is a false positive | Add `// cy-scan-ignore CY0xx` on the same or previous line, with the reason |
| Version shows "not detected" | Pass `--cypress-major <n>`; in a monorepo, run the scanner from the package that depends on Cypress |
| The test fails only in CI after fixes | Compare viewport, browser, and CPU. Run locally with the CI browser and `--browser chrome --headless`, and throttle CPU to surface timing gaps |
| `cy.wait('@alias')` times out after the change | The intercept is registered after the request, the URL pattern misses a query string (add `*`), or the request is served from cache and never reaches the network |

## References

- [references/anti-patterns.md](./references/anti-patterns.md): before-and-after code for every scanner rule
- [references/removed-apis.md](./references/removed-apis.md): removed APIs by Cypress major, with migration code for `Cypress.env()` and `cy.exec()`
- [Cypress retry-ability](https://docs.cypress.io/app/core-concepts/retry-ability)
- [Cypress migration guide](https://docs.cypress.io/app/references/migration-guide)

© github · MIT · github/awesome-copilot

Похожие скиллы

Всё по теме «Тесты и QA» →
cypress-explain cypress-io Разбирает сквозные и компонентные тесты Cypress, объясняет вызовы команд и проводит ревью кода без внесения правок в файлы проекта. CX Codex +1 8 000установок cypress-author cypress-io Скилл создаёт, обновляет и чинит тесты Cypress — E2E и компонентные. Пригодится, когда просишь агента написать тесты, а он не знает, с чего начать. CX Codex +1 9 000установок cypress Claude MPM Team Скилл для написания E2E- и компонентных тестов на Cypress: устойчивые селекторы, ожидания без фиксированных пауз, перехват сети. CX Codex +1 653установок cypress-defect-tracking-cursorrules-prompt-file PatrickJS Правило для Cursor, которое превращает агента в QA-инженера: пишет тесты Cypress с тегами команд, категорий и case ID и собирает отчёты через qa-shadow-report. ★ 41 011звёзд репо cypress-automation kindlmann Скилл для написания тестов на Cypress в TypeScript: E2E, компонентные тесты, cy.intercept, cy.session и запуск в CI. CX Codex +1 1 000установок test-specialist ailabs-393 Скилл направляет агента при написании тестов и поиске багов в проектах на JavaScript и TypeScript. Пригодится для закрытия пробелов в покрытии и пошаговой отладки логики. CX Codex +1 902установок

Из того же набора732

Весь набор →
pr-address-feedback Скилл пошагово разбирает замечания ревью в пулл-реквесте, группирует похожие комментарии и готовит план правок до изменения файлов. Пригодится при разборе ревью в ветке. 2установок java-testcontainers Помогает писать интеграционные тесты на Java с Testcontainers 2.x и JUnit Jupiter, поднимая базы данных и очереди в Docker. Пригодится при настройке тестов или миграции с ветки 1.x. 1установок java-debugging Скилл ведёт агента по методике поиска причины бага в Java: воспроизвести, сузить, проверить гипотезу, подключить отладчик. Пригодится, когда логи уже не помогают. 1установок quarkus-native-and-container Помогает собрать нативный исполняемый файл Quarkus, починить ошибки reflection и сделать образ контейнера с манифестами Kubernetes. ★ 40 418звёзд репо vue Правило задаёт Copilot стандарты Vue 3: Composition API, <script setup>, реактивность, Pinia и Vue Router. Пригодится, когда агент пишет компоненты в вашем стиле. ★ 40 418звёзд репо update-docs-on-code-change Правило для GitHub Copilot, которое напоминает обновлять README.md и документацию, когда меняется код. Пригодится, если доки у вас отстают от реальности. ★ 40 418звёзд репо terraform-azure Правило задаёт Copilot стиль и ограничения при работе с Terraform на Azure: структура файлов, модули AVM, запрет на секреты в состоянии. ★ 40 418звёзд репо tanstack-start-shadcn-tailwind Правило задаёт Copilot стек TanStack Start, Shadcn/ui и Tailwind CSS и требует валидировать внешние данные через Zod. ★ 40 418звёзд репо

Спонсоры проекта

Компании, которые помогают держать аналитику открытой