Skip to content

refactor(e2e): Replace arbitrary waits with state-based waiting in flag tests#6828

Closed
talissoncosta wants to merge 2 commits intomainfrom
chore/improve-flag-tests-wait-strategy
Closed

refactor(e2e): Replace arbitrary waits with state-based waiting in flag tests#6828
talissoncosta wants to merge 2 commits intomainfrom
chore/improve-flag-tests-wait-strategy

Conversation

@talissoncosta
Copy link
Contributor

Summary

Improves the E2E test reliability and speed by replacing arbitrary timeout waits with proper state-based waiting.

Changes

Replace fixed t.wait(500) timeouts with waitForElementVisible('#try-it-results') in three locations within flag-tests.ts.

Why This is Better

Current approach (PR #6827):

  • Uses t.wait(500)t.wait(2000) and t.wait(1500)
  • Fixed delays regardless of actual response time
  • Still has race conditions if CI is very slow
  • Slower tests even when API responds quickly

This approach:

  • Waits for #try-it-results element to appear (only exists when loading completes)
  • Runs as fast as possible (no artificial delays)
  • More reliable on slow CI environments (uses LONG_TIMEOUT of 40s)
  • Semantically correct: waits for the exact element we need
  • Consistent with E2E best practices used elsewhere in the codebase

Technical Details

The TryIt component only assigns the #try-it-results ID when !this.state.isLoading (TryIt.js:82). This makes it the perfect indicator that:

  1. The API request completed
  2. The state updated
  3. The DOM rendered with results

Test Plan

Related Issues

talissoncosta and others added 2 commits February 27, 2026 23:59
Scan the frontend codebase for design token misuse, dark mode gaps,
and component fragmentation. Produces a structured report with 85
findings across 7 areas (colours, typography, spacing, buttons, forms,
icons, notifications) and a component inventory covering 11 categories.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ag tests

Replace fixed 500ms timeouts with `waitForElementVisible('#try-it-results')`
to wait for the actual loading state to complete. This approach:

- Eliminates race conditions on slow CI runners
- Runs faster when API responds quickly (no artificial 500ms delays)
- More semantically correct (waits for the element we actually need)
- Consistent with E2E best practices already used elsewhere

The #try-it-results element only receives its ID when the TryIt component
finishes loading (isLoading: false), making it the perfect indicator to
wait for rather than guessing arbitrary timeout values.

Related: #6827 (increased timeouts from 500ms to 2000ms/1500ms)
This PR provides a better alternative to arbitrary timeout increases.
@talissoncosta talissoncosta requested a review from a team as a code owner March 2, 2026 20:17
@talissoncosta talissoncosta requested review from Zaimwa9 and removed request for a team March 2, 2026 20:17
@vercel
Copy link

vercel bot commented Mar 2, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
flagsmith-frontend-preview Building Building Preview, Comment Mar 2, 2026 8:17pm
flagsmith-frontend-staging Building Building Preview, Comment Mar 2, 2026 8:17pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Ignored Ignored Mar 2, 2026 8:17pm

Request Review

@github-actions github-actions bot added front-end Issue related to the React Front End Dashboard refactor labels Mar 2, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2026

Docker builds report

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-api-test:pr-6828 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-e2e:pr-6828 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-api:pr-6828 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-private-cloud:pr-6828 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-frontend:pr-6828 Finished ✅ Results

@talissoncosta
Copy link
Contributor Author

Closing in favour of clean branch without extra files

@talissoncosta talissoncosta deleted the chore/improve-flag-tests-wait-strategy branch March 2, 2026 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

front-end Issue related to the React Front End Dashboard refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant