The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Improve Cypress flaky-test guidance (#82752)
Stas Gavrylov5b9d69ca6657
diff --git a/.claude/skills/_shared/cypress-conventions.md b/.claude/skills/_shared/cypress-conventions.mdindex ced59608bde..4459c08d16d 100644--- a/.claude/skills/_shared/cypress-conventions.md+++ b/.claude/skills/_shared/cypress-conventions.md@@ -27,12 +27,27 @@ describe("feature name", () => {Use existing navigation helpers (`H.openOrdersTable()`, `H.openNativeEditor()`, `H.visitDashboard(id)`, `H.visitQuestion(id)`, etc.) instead of raw `cy.visit()` chains. Grep `e2e/support/helpers/` to discover what's available.+### Changing shared helpers++Before changing a shared helper's default behavior, enumerate its callers and check:++- repeated calls with the same and different arguments;+- cache, deduplication, or conditional paths where an expected request may not occur;+- existing intercepts, alias reuse, and concurrent requests;+- inherited `within` scopes and other caller-owned context.++If only some callers need additional synchronization or assertions, prefer an explicit opt-in option over changing every caller implicitly. Validate both an opted-in caller and an existing caller that retains the default behavior.+## Constants and IDs**Sample Database schema** (table/field definitions) — import from `cypress_sample_database`:```js-import { ORDERS, ORDERS_ID, PRODUCTS } from "e2e/support/cypress_sample_database";+import {+ ORDERS,+ ORDERS_ID,+ PRODUCTS,+} from "e2e/support/cypress_sample_database";```**Instance data** (dashboard IDs, user IDs, etc.) — import from `cypress_sample_instance_data`:@@ -68,6 +83,7 @@ cy.visit("/dashboard/10");4. Other `data-*` attributes as a fallback (e.g. `cy.get("[data-element-id='foo']")`) when a stable `data-testid` isn't available.NEVER use:+- `cy.get("[data-testid='...']")` — always use `cy.findByTestId(...)` instead.- CSS class names (especially generated ones from styled-components or Mantine).- Ad-hoc CSS attribute selectors (`path[fill="..."]`, `[stroke="..."]`, etc.) in test specs or new helpers.@@ -78,6 +94,7 @@ NEVER use:`e2e/support/helpers/e2e-visual-tests-helpers.js` is the **only** file allowed to reach into rendered chart DOM via raw CSS attribute selectors. ECharts renders SVG with no `data-testid` attributes and minimal a11y surface, so there's no first-class alternative for asserting on chart visuals. The helpers there (`echartsContainer`, `goalLine`, `chartPathWithFillColor`, `pieSliceWithColor`, `cartesianChartCircle`, `BoxPlot.*`, etc.) are the intentional exception.When writing or reviewing visualization tests:+- Always go through these helpers — don't roll your own `cy.get("path[fill=...]")` inline.- If a chart pattern isn't covered, add a new helper to that file rather than embedding the selector in a spec.@@ -144,11 +161,14 @@ The `metabase/no-unscoped-text-selectors` lint rule enforces this for the top-le- Use `cy.request()` or existing API helpers to set up state.- Only drive the UI for the flow you're actually testing.+- Before replacing UI steps with API setup, state the behavior the test must preserve. An interaction belongs to the tested flow when it is part of the regression path, appears in relevant failure evidence, or is an intended integration boundary. Keep those interactions in the UI; use APIs only for preconditions outside that behavior.## Waits and timing- **Never** use numeric `cy.wait(ms)`.- For API timing: define `cy.intercept()` BEFORE the action that triggers the request, then `cy.wait("@alias")`.+- A network wait is valid only when the triggering action is expected to issue that request. Account for caches, request deduplication, unchanged query arguments, and conditional fetches before making a wait mandatory.+- Treat network completion and DOM readiness as separate boundaries: first verify the expected response, then assert the resulting UI state.- For DOM readiness: prefer `.should("be.visible")` — it asserts the element is rendered **and** visible to the user, which is the right proxy for "the UI is ready". `.should("exist")` only proves the node is in the DOM and is **not** a readiness check; reserve it for cases where you specifically need to assert presence without visibility (hidden inputs, off-screen / portal-detached nodes, etc.).```js@@ -159,7 +179,7 @@ cy.wait("@dataset");## Never assign return values from `cy.*` commands-`cy.*` commands are not synchronous — they enqueue work on Cypress's command queue and resolve asynchronously. Assigning the return value to a variable yields a *chainer*, not the underlying DOM element / string / response. Treating that variable as if it held the resolved value is one of the most common foot-guns in Cypress and a frequent source of "but my console.log printed something weird" confusion. See the [official anti-pattern doc](https://docs.cypress.io/app/core-concepts/best-practices#Assigning-Return-Values).+`cy.*` commands are not synchronous — they enqueue work on Cypress's command queue and resolve asynchronously. Assigning the return value to a variable yields a _chainer_, not the underlying DOM element / string / response. Treating that variable as if it held the resolved value is one of the most common foot-guns in Cypress and a frequent source of "but my console.log printed something weird" confusion. See the [official anti-pattern doc](https://docs.cypress.io/app/core-concepts/best-practices#Assigning-Return-Values).```js// Bad — `button` is a chainer, NOT a DOM node@@ -385,6 +405,7 @@ Before writing a new `it()` block, look at sibling tests in the same `describe`.A near-duplicate test pays the full `beforeEach` cost again, doubles the maintenance surface (two places to update when the flow changes), and obscures intent — readers can't tell why the second test exists if it's not visibly different from the first.Signals that this is the case:+- The new `it()` repeats the same `H.openOrdersTable()` / `H.visitDashboard(id)` / opening sequence as the test above it.- The new `it()` differs only in the last few lines.- The new `it()` title is a near-paraphrase of an existing one ("can pick a sum function" + "can pick an avg function" — these are likely the same test parameterised over function name).diff --git a/.claude/skills/e2e-test-review/SKILL.md b/.claude/skills/e2e-test-review/SKILL.mdindex 968420e9132..d25e109f2f3 100644--- a/.claude/skills/e2e-test-review/SKILL.md+++ b/.claude/skills/e2e-test-review/SKILL.md@@ -47,6 +47,16 @@ The checklist mirrors the order of the conventions file. Items marked **(lint)**- [ ] **No hardcoded numeric IDs anywhere** — including for entities the test creates itself. Capture from the create response or alias the intercept.- [ ] Existing navigation helpers used (`H.openOrdersTable`, `H.visitDashboard(id)`, etc.) instead of raw `cy.visit()` chains+### Shared helper changes++When a diff changes a shared helper, inspect its callers rather than reviewing the helper in isolation:++- [ ] Default behavior changes are justified for every caller; otherwise the new behavior is explicit and opt-in.+- [ ] Repeated calls with identical and different arguments are safe.+- [ ] Mandatory network waits account for cache hits, request deduplication, unchanged query arguments, and conditional fetches where no request occurs.+- [ ] Intercepts and aliases cannot accumulate, collide, or resolve against the wrong request.+- [ ] Verification covers both an affected caller and a representative caller using unchanged defaults.+### Selectors- [ ] Prefers a11y queries (`findByRole`, `findByLabelText`) over `findByText`diff --git a/.claude/skills/e2e-test/SKILL.md b/.claude/skills/e2e-test/SKILL.mdindex 3749359944a..d78105768e5 100644--- a/.claude/skills/e2e-test/SKILL.md+++ b/.claude/skills/e2e-test/SKILL.md@@ -14,12 +14,14 @@ Only use `MB_EDITION=ee` when the user explicitly asks to write or run an enterp**For `MB_EDITION=ee`:**These tokens must be exported in the shell before starting Claude Code:+- `CYPRESS_MB_ALL_FEATURES_TOKEN` — all features (most EE tests need this)- `CYPRESS_MB_PRO_SELF_HOSTED_TOKEN` — pro self-hosted (permissions, SSO, sandboxing)- `CYPRESS_MB_STARTER_CLOUD_TOKEN` — starter plan (rarely needed)- `CYPRESS_MB_PRO_CLOUD_TOKEN` — pro cloud (rarely needed)**NEVER echo, print, or log token values. Only check if they are set:**+```bashecho "ALL_FEATURES: ${CYPRESS_MB_ALL_FEATURES_TOKEN:+set}" && echo "PRO_SELF_HOSTED: ${CYPRESS_MB_PRO_SELF_HOSTED_TOKEN:+set}" && echo "STARTER: ${CYPRESS_MB_STARTER_CLOUD_TOKEN:+set}" && echo "PRO_CLOUD: ${CYPRESS_MB_PRO_CLOUD_TOKEN:+set}"```@@ -30,9 +32,19 @@ If tokens are missing, tell the user: "EE tokens are not set. Either export themIf the user asks "how long does this test take" / "what's the timing" — **do not run it**. Read `e2e/support/timings.json`, which holds the latest CI duration (in ms) per spec. Match on the spec path (entries are stored as `../test/scenarios/...`). Per-`it()` granularity is not recorded there; for that you'd need the Cypress JSON reporter, which requires running the spec.+## Diagnosing flakiness++Before changing a flaky test:++1. Gather the available longitudinal CI history, failure messages, screenshots, and retries. Classify distinct failures by the UI or network boundary where they occur instead of treating every occurrence as one race.+2. State which user interactions the test is intended to cover. Preserve interactions that are part of the regression path or relevant failure evidence; do not move them to API setup merely to make the test pass.+3. Fix the narrowest boundary supported by evidence. Keep backend errors, failed requests, and application crashes visible unless the task explicitly targets their recovery behavior.+4. Treat a local stress run as evidence about a candidate change, not proof that historical flakiness never existed. A small passing sample does not outweigh repeated CI failures.+## RunningFirst check if snapshots exist:+```bashls e2e/snapshots/default.sql 2>/dev/null && echo "snapshots exist" || echo "snapshots missing"```@@ -40,11 +52,13 @@ ls e2e/snapshots/default.sql 2>/dev/null && echo "snapshots exist" || echo "snapAlways pass the spec path via `--spec`. The runner feeds its arguments to Cypress's CLI parser (`cypress.cli.parseRunArguments`), which silently drops bare positional paths and then runs the entire suite. A leading `run` argument is harmless, but the path itself must follow `--spec`. Sanity-check that the first `Running:` line says `(1 of 1)`.If snapshots exist, skip regeneration for speed:+```bashMB_EDITION=oss CYPRESS_VIDEO=false CYPRESS_RETRIES=0 CYPRESS_GUI=false GENERATE_SNAPSHOTS=false bun test-cypress --spec path/to/spec.cy.spec.js```If snapshots are missing (first run), let the runner generate them:+```bashMB_EDITION=oss CYPRESS_VIDEO=false CYPRESS_RETRIES=0 CYPRESS_GUI=false bun test-cypress --spec path/to/spec.cy.spec.js```@@ -54,12 +68,15 @@ When running enterprise tests, replace `MB_EDITION=oss` with `MB_EDITION=ee` inIf `$ARGUMENTS` is empty, ask the user which spec to run.If the user provides a test name or fuzzy name instead of a spec path, find the spec file:+```bashfind e2e/test/scenarios -name "*FUZZY_NAME*.cy.spec.*" -type f```+Then run with `--spec "path/to/matched.cy.spec.js"`.To filter by test name, use the `GREP` env var (not `--env grep=`, which breaks on commas):+```bashGREP="test name here" MB_EDITION=oss bun test-cypress --spec path/to/spec.js```