Skip to content

Conversation

@lucgonp
Copy link

@lucgonp lucgonp commented Nov 26, 2025

  • Closes

Additional details

Steps to test

How has the user experience changed?

PR Tasks


Note

Introduces a timeout diagnostics module that augments timeout errors with contextual suggestions, adds unit tests and README, updates changelog, and makes Vite dev server HTML injection robust when is missing.

  • Driver:
    • Timeout Diagnostics (new): Add packages/driver/src/cypress/timeout_diagnostics.ts to analyze timeout context and append actionable suggestions to error messages (analyze, formatSuggestions, enhanceTimeoutError).
    • Docs & Tests: Add TIMEOUT_DIAGNOSTICS_README.md and unit tests packages/driver/test/unit/cypress/timeout_diagnostics.spec.ts covering selectors, network, animations, DOM mutations, escaping, and formatting.
  • Dev Server (Vite):
    • HTML Injection Robustness: Update npm/vite-dev-server/src/plugins/cypress.ts to safely inject loader script even when </body> is absent; logs via debug and appends at end of HTML as fallback.
  • Changelog:
    • Update cli/CHANGELOG.md to list the new timeout diagnostics under **Features:** for 15.7.1.

Written by Cursor Bugbot for commit 7f48063. This will update automatically on new commits. Configure here.

@CLAassistant
Copy link

CLAassistant commented Nov 26, 2025

CLA assistant check
All committers have signed the CLA.

@cypress-app-bot
Copy link
Collaborator

@lucgonp lucgonp force-pushed the feat/timeout-diagnostics branch from 671295a to fdf2196 Compare November 26, 2025 12:09
Add smart diagnostic suggestions for timeout errors to improve DX

- Created TimeoutDiagnostics module with contextual error analysis
- Detects common timeout patterns:
  * Dynamic/loading content selectors
  * Complex and fragile selectors
  * Dynamic ID selectors
  * Network-related delays
  * Animation issues
  * Excessive DOM mutations
- Provides actionable suggestions with docs links
- Includes comprehensive test coverage (17 tests)
- Fully documented with examples and integration guide

Benefits:
- Reduces debugging time for developers
- Provides inline education about best practices
- Decreases frustration with clearer error messages
- Reduces support questions about timeouts

Example output:
`
cy.get() timed out waiting 4000ms

 Diagnostic Suggestions:

1. The selector appears to target dynamic/loading content
   a) Wait for the loading state to complete
   b) Consider using data-cy attributes
   c) Use cy.intercept() to wait for API requests
    Learn more: https://on.cypress.io/best-practices
`

Related: Timeout errors are one of the most common issues users face
Fix critical bugs identified by Cursor Bot code review:

1. **Missing body tag handling in Vite plugin**
   - Added check for missing </body> tag (lastIndexOf returns -1)
   - Prevents malformed HTML with script at wrong position
   - Gracefully appends script at end if body tag not found
   - Added debug logging for missing body tag case

2. **Contradictory loading content suggestion**
   - Fixed confusing suggestion for loading selectors
   - Now suggests waiting for loading to disappear THEN get content
   - Provides alternative to wait for API request
   - Clarifies when user actually needs the loading element itself

3. **Unescaped quotes in generated code suggestions**
   - All selectors now properly escaped before interpolation
   - Prevents syntax errors like: cy.get('[data-test='value']')
   - Correctly generates: cy.get('[data-test=\\'value\\']')
   - Applied to all suggestion types (dynamic, complex, ID, general)

Test coverage:
- Added tests for quote escaping in selectors
- Verified proper handling of special characters
- All 19 tests passing
- Lint checks passing

Before:
- cy.get('[data-test='value']')  // SYNTAX ERROR

After:
- cy.get('[data-test=\\'value\\']')  // VALID

Related: Security and code quality improvements
@lucgonp lucgonp force-pushed the feat/timeout-diagnostics branch from 708299f to b611123 Compare November 26, 2025 12:46
@lucgonp lucgonp force-pushed the feat/timeout-diagnostics branch from b611123 to 454b5db Compare November 26, 2025 13:01
@lucgonp lucgonp force-pushed the feat/timeout-diagnostics branch from d11c142 to 77deef7 Compare November 26, 2025 13:30
@lucgonp lucgonp marked this pull request as draft November 28, 2025 16:54
@lucgonp lucgonp marked this pull request as ready for review November 28, 2025 16:54
@lucgonp lucgonp changed the title Feat/timeout diagnostics feat: timeout diagnostics Nov 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants