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

proposal: Fields for easier custom reporter development #8600

Closed
seeruk opened this issue Jun 24, 2019 · 5 comments
Closed

proposal: Fields for easier custom reporter development #8600

seeruk opened this issue Jun 24, 2019 · 5 comments

Comments

@seeruk
Copy link

seeruk commented Jun 24, 2019

Quite a simple proposal. I think there should be more fields to use in custom reporters. At present there's not much useful / usable information in a TestResult. Status, titles, duration, and number of passing assertions are all great, but it'd also be really useful to see more about what went wrong when something went wrong.

I can get a little bit closer to what I'm thinking if I disable colours, but I don't think I should have to disable colours to get a plain string of the error from custom reporter API.

Here's part of a snippet of some of this output for example:

failureMessages:
   [ 'Error: \u001b[2mexpect(\u001b[22m\u001b[31mreceived\u001b[39m\u001b[2m).\u001b[22mtoBe\u001b[2m(\u001b[22m\u001b[32mexpected\u001b[39m\u001b[2m) // Object.is equality\u001b[22m\n\nExpected: \u001b[32m2\u001b[39m\nReceived: \u001b[31m1\u001b[39m\n    at Object.<anonymous>

But it seems like it should be possible to expose the components of an error to build up strings with custom formatting; for example, to build up a rich block for a Slack notification for the error.

As above, it'd be useful simply to build more expressive and useful custom reporters. Slack is a good example, as it supports richer content than just text. So having the pieces of an error to build and split into sections can make quite a lot of difference to how easy it is to parse one of those error messages.

If the assertions are controlled as part of Jest, then surely they can be made to expose the error information in an easy to consume way (e.g. "expected x, received y" information, so on).

@thymikee
Copy link
Collaborator

I think you're looking for #7900. Please leave a comment on your use case there :) (closing this one then, hope you don't mind)

@seeruk
Copy link
Author

seeruk commented Jun 24, 2019

That looks quite similar, I think it probably touches on some of the pain points. There's is a lot of code related to dealing with splitting up and dealing with the error messages, despite them being formed from something far more usable within Jest itself. I suppose it might be worth trying to lump this into that, maybe this is a requirement of making #7900 work.

In the meantime, I suppose that doesn't leave me with many options other than to try use something else sadly.

@thymikee
Copy link
Collaborator

There's also #3160, but it's kinda stale for a while now, as we encountered a bunch of gotchas while prototyping. That saying, it's not a trivial thing to solve in Jest unfortunately.

@SimenB
Copy link
Member

SimenB commented Jun 24, 2019

You should ideally get underlying assertion error (#7594, PR welcome), if that's all you wanna format. That won't help for other errors though.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants