Skip to content

Conversation

@jennifer-shehane
Copy link
Member

@jennifer-shehane jennifer-shehane commented Nov 7, 2025

Additional details

When cy.wrap() is called with objects containing circular references, the logging code in stringifyActual causes infinite recursion because it doesn't track visited objects. This can lead to stack overflow errors - which cause the Cypress App to completely hang.

I'm not sure if this is an issue with other command logs, but this addresses the issue with logging in general, so it would resolve situations there as well.

Steps to test

  • Run yarn cypress:open
  • Run the example below to ensure it doesn't hang:
class Node {
  parent;
  children = [];

  appendChild(child) {
    child.parent = this;
    this.children.push(child);
    return child;
  }
}

describe("Reproduce the Cypress's issue", () => {
  it("Wrap an object containing circular references", () => {
    const rootNode = new Node();
    rootNode.appendChild(new Node()).appendChild(new Node());
    cy.wrap(rootNode);
    cy.visit("https://example.cypress.io/");
  })
})

How has the user experience changed?

Before

!!!! Complete Cypress App hang when running the test

After

Screenshot 2025-11-07 at 4 43 06 PM

PR Tasks


Note

Prevents hangs when cy.wrap() logs objects with circular references by tracking visited objects during stringification and adds comprehensive tests; updates changelog.

  • Driver (utils):
    • Track visited objects via WeakSet in stringifyActual()/stringifyActualObj() to detect cycles and return [Circular], Object{N}, or Array[N] safely.
    • Avoid infinite recursion/hangs when logging complex objects/arrays, impacting cy.wrap() logging.
  • Tests:
    • Add extensive e2e coverage for circular references in cy.wrap() (packages/driver/cypress/e2e/commands/misc.cy.js).
    • Expand utils.stringify tests for circular/nested/multiple references and adjust expectations for arrays/objects (packages/driver/cypress/e2e/cypress/utils.cy.js).
  • Docs:
    • Update cli/CHANGELOG.md with bugfix entry for cy.wrap() freezing on circular references.

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

@jennifer-shehane jennifer-shehane self-assigned this Nov 7, 2025
@cypress
Copy link

cypress bot commented Nov 7, 2025

cypress    Run #67231

Run Properties:  status check passed Passed #67231  •  git commit f6dc83e841: Merge branch 'fix-wrap-circular-reference-log' of https://github.com/cypress-io/...
Project cypress
Branch Review fix-wrap-circular-reference-log
Run status status check passed Passed #67231
Run duration 19m 01s
Commit git commit f6dc83e841: Merge branch 'fix-wrap-circular-reference-log' of https://github.com/cypress-io/...
Committer Jennifer Shehane
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 12
Tests that did not run due to a developer annotating a test with .skip  Pending 1098
Tests that did not run due to a failure in a mocha hook  Skipped 4
Tests that passed  Passing 26594
View all changes introduced in this branch ↗︎

Warning

Partial Report: The results for the Application Quality reports may be incomplete.

UI Coverage  45.61%
  Untested elements 187  
  Tested elements 161  
Accessibility  97.98%
  Failed rules  4 critical   8 serious   2 moderate   2 minor
  Failed elements 101  

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.

Cypress hangs when wrapping an object containing circular references.

2 participants