Skip to content

Replace ~289s of hardcoded cy.wait() in custom-import-map-dashboards tests with cy.intercept and Cypress retry-ability #1987

Description

@zhongnansu

Description

The custom-import-map-dashboards Cypress test suite contains 33 hardcoded cy.wait() calls totaling 289 seconds (~5 minutes) of unconditional sleep per test run. Zero cy.intercept() / cy.wait('@alias') calls exist. This is a primary source of both test flakiness and slow CI feedback loops.

Affected files

All under cypress/integration/plugins/custom-import-map-dashboards/:

File cy.wait() calls Total sleep
4_documentsLayer.spec.js 13 112s
5_add_map_to_dashboard.spec.js 7 45s
2_opensearchMapLayer.spec.js 4 36s
3_add_saved_object.spec.js 3 35s
1_import_vector_map_tab.spec.js 2 25s
6_geojson_file_upload.spec.js 1 15s
0_add_saved_object.js 2 11s
7_enable_new_home_ui.spec.js 1 10s

Anti-patterns found

1. Sleep-before-visit — Every file calls cy.wait(10000-15000) in before() after addSampleData(), then again after cy.visit(). Example in 4_documentsLayer.spec.js:19,25,27: 15s + 10s + 10s before the first assertion.

2. Sleep-instead-of-assertion — In 5_add_map_to_dashboard.spec.js:29-40, every UI interaction is preceded by cy.wait(5000). The pattern cy.wait(5000).get(selector).click() appears 6 times in a row.

3. Sleep-in-a-loop — At 2_opensearchMapLayer.spec.js:40-44, a for loop runs 21 iterations of cy.wait(1000).get('canvas').trigger('dblclick'), adding 21 seconds of dead time.

Suggested fixes

  1. Replace cy.wait(N) after addSampleData() with cy.intercept on the sample data API, then cy.wait('@sampleData'). Eliminates 10-15s in every before() hook.

  2. Replace cy.wait(N).get(selector) with cy.get(selector, { timeout }).should('be.visible') — Cypress's built-in retry makes this both faster and more reliable. Mechanical find-and-replace for ~20 occurrences.

  3. Replace the zoom loop with programmatic map control via cy.window() to call setZoom(), or at minimum remove the cy.wait(1000) inside the loop.

  4. Add cy.intercept for page-load readiness after cy.visit() instead of fixed sleeps.

Impact

  • Flakiness on slower CI: if the server takes longer than the hardcoded sleep, the test fails
  • Wasted time on faster CI: always sleeps the full duration even when the UI is ready in 200ms
  • ~289 seconds of dead time per test run that could be reduced to near-zero with proper Cypress patterns

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions