Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

console error only print {}, without effect message. #41

Closed
JFRabbit opened this issue Aug 13, 2020 · 6 comments
Closed

console error only print {}, without effect message. #41

JFRabbit opened this issue Aug 13, 2020 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@JFRabbit
Copy link

support/index.js

collectTypes: [
          "cons:error",
          "cy:log",
          "cy:xhr",
          "cy:request",
          "cy:route",
          "cy:command",
        ],

截屏2020-08-13 下午9 08 54

截屏2020-08-13 下午9 09 01

@archfz
Copy link
Owner

archfz commented Aug 18, 2020

Are you sure this is not coming from your app or custom cypress code ? This plugin does not use any .split on anything. I would need more details on this. Maybe the error object format would be a starting point. Don't forget the it might seem that the error is coming from this plugin as it will show up in the stack since we are intercepting (overriding) the original console.error function in the browser.

@JFRabbit
Copy link
Author

This message should be a catched error from app, maybe like this code:

var a = 1;
try {
  a.split(",");
} catch (e) {
  // cypress-terminal-report print error line in terminal, but show "cons:error ✘  {}"
  // in browser console, I can get "TypeError: a.split is not a function
  console.error(e); 
}
a.split(","); // make cypress run failed when "uncaught:exception" return true

截屏2020-08-19 下午3 11 26

截屏2020-08-19 下午3 12 12

@JFRabbit
Copy link
Author

looks like console.error(error) will print {}, use string is ok.

@archfz
Copy link
Owner

archfz commented Aug 21, 2020

I tried to reproduce the issue you have with the same code but I couldnt. The issue is that for some reason on your code the error that is thrown is not instance of window.Error. Another possibility is that the error doesnt have the stack property but I doubt that. I have an idea for a possible fix, I will release next week in a patch so we can try if it resolves it for you.

In the meantime:

  • what browser do you use?
  • do you have any polyfills that might change the error object?
  • can you check in the catch whether error instanceof window.Error ?

@JFRabbit
Copy link
Author

  • what browser do you use?

Browser: Electron 80

  • can you check in the catch whether error instanceof window.Error ?

Yes

You create a react app to reproduce this issue:

import React, { Component } from "react";
import { Button } from "antd";
import "antd/dist/antd.css";

class App extends Component {
  makeTypeError = () => {
    var a = 1;
    try {
      a.split(",");
    } catch (e) {
      console.error(e);
      console.info(e instanceof window.Error);
    }
    a.split(",");
  };

  render() {
    return (
      <div>
        <Button id="error" onClick={this.makeTypeError}>
          Make Type Error
        </Button>
      </div>
    );
  }
}

export default App;

test code:

describe("foobar", () => {
  it("foobar", () => {
    cy.visit("http://localhost:3000/");

    cy.get("#error").click();
  });
});

Terminal:

      cy:command ✔  visit       http://localhost:3000/
      cy:command ✔  get #error
      cy:command ✘  click
          cy:xhr ⓘ  GET http://localhost:3000/sockjs-node/info?t=1598261034294
      cons:error ✘  {}

@archfz archfz added bug Something isn't working and removed clarification labels Aug 24, 2020
@archfz archfz self-assigned this Sep 1, 2020
@archfz
Copy link
Owner

archfz commented Sep 3, 2020

Released in 2.0.0.

@archfz archfz closed this as completed Sep 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants