archfz / cypress-terminal-report

Plugin for cypress. Logs to terminal and files, mimicking cypress UI.
MIT License
507 stars 39 forks source link

Bug: Cypress Component testing on React logs console logs recursively #232

Closed RomelClavel closed 10 months ago

RomelClavel commented 10 months ago

When running a component test suite on cypress with the default setup, any console event will be printed into console recursively until there is a RangeError: Maximum call stack size exceeded.

The conditions for this behavior to occur are the following:

Here is a simple example of the test suite that leads to this behavior:

describe("Recursive logging on console events", () => {

  const Title = () => {
    return <h1>title</h1>;
  };

  it("Component test 1", () => {
    cy.mount(<Title />);
    console.warn("warning");
    cy.get("h2");
  });

  it("Component test 2", () => {
    cy.mount(<Title />);
    console.warn("warning");
    cy.get("h2");
  });
})

Currently the only way I have of mitigating this unwanted behavior is excluding the console events setting the Collect Types option in the Install Logs Collector. Like so:


require("cypress-terminal-report/src/installLogsCollector")({
  collectTypes: ["cy:log", "cy:xhr", "cy:request", "cy:intercept", "cy:command"]
});
archfz commented 10 months ago

Fixed in 5.3.11