Skip to content

Conversation

@lucgonp
Copy link

@lucgonp lucgonp commented Nov 25, 2025

  • Closes

Additional details

Steps to test

How has the user experience changed?

PR Tasks


Note

Introduces a Timeout Diagnostics module with tests and updates the Vite Cypress plugin to asynchronously load files with lazy retry and safer HTML injection.

  • Driver:
    • Timeout Diagnostics: Add packages/driver/src/cypress/timeout_diagnostics.ts providing contextual suggestions for timeout errors, plus formatting and error-enhancement helpers.
    • Tests/Docs: Add unit tests in packages/driver/test/unit/cypress/timeout_diagnostics.spec.ts and README TIMEOUT_DIAGNOSTICS_README.md.
  • Vite Dev Server:
    • Async fs: Replace sync reads with async readFile via util.promisify in npm/vite-dev-server/src/plugins/cypress.ts.
    • Lazy loader with retry: Introduce cached loaderPromise with error handling for initCypressTests.js.
    • HTML injection robustness: Inject scripts into index.html before </body> when present, or append at end when missing.

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

…ormance

- Replace fs.readFileSync with async fs.readFile
- Add proper error handling with debug logs
- Improve performance by avoiding event loop blocking
- Remove TODO comment about async fs methods

This follows Node.js best practices and improves DX with faster build times.
- Replace fs.readFileSync with promisified fs.readFile for async operation
- Implement lazy initialization with getLoaderPromise() to prevent unhandled promise rejections
- Add proper blank lines to satisfy padding-line-between-statements ESLint rule
- Maintain proper error handling with try/catch blocks
- Add catch handler to reset promise on failure for retry capability
- Address Cursor Bot feedback about unhandled promise rejection
- Maintain lazy initialization to prevent unnecessary promise creation
- Improve error recovery for init file loading
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
@CLAassistant
Copy link

CLAassistant commented Nov 25, 2025

CLA assistant check
All committers have signed the CLA.

@cypress-app-bot
Copy link
Collaborator

suggestions.push({
reason: 'The selector appears to target dynamic/loading content',
suggestions: [
`Wait for the loading state to complete: cy.get('${selector}').should('not.exist')`,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Unescaped selector quotes break generated code suggestions

Selectors containing single quotes are directly interpolated into code suggestions without escaping, causing syntax errors in the generated examples. For instance, a selector like [data-test='value'] would produce invalid JavaScript like cy.get('[data-test='value']') instead of properly escaped code.

Additional Locations (2)

Fix in Cursor Fix in Web

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolvido

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
@jennifer-shehane
Copy link
Member

@lucgonp Could you please sign our CLA?


## 📝 Licença

MIT - Consistente com o projeto Cypress
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Unrelated timeout diagnostics code accidentally committed

The PR is titled "Feat/vite async fs operations" but includes a complete timeout diagnostics feature for the driver package. The README is in Portuguese and describes this as a future feature that needs integration. The documentation explicitly states this is not yet integrated and requires modifications to error_utils.ts and other components. This appears to be work-in-progress code accidentally included in a PR about Vite async operations.

Additional Locations (2)

Fix in Cursor Fix in Web

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.

4 participants