betterer icon indicating copy to clipboard operation
betterer copied to clipboard

Feature Request: Custom Failure Messages

Open Giesch opened this issue 3 years ago • 4 comments
trafficstars

When adding custom rules, it would be nice to be able to customize the output when the rule fails. The use case is that I made a rule counting import cycles, and I want to be able to print a link about how to fix an import cycle if CI fails. If there's a way to do this already that I missed, please let me know!

I'm happy to work on adding this feature, if that's appropriate. I'm guessing it would start with a new (optional) property on BettererTestOptionsComplex?

Giesch avatar Feb 23 '22 16:02 Giesch

So it's not the clearest API because I want to limit what is exposed publicly, but you should be able to provide a custom differ function as part of your test, and the return value of the differ can include a set of logs that will be printed.

Here's how it works for the BettererFileTest

phenomnomnominal avatar Feb 25 '22 01:02 phenomnomnominal

Thanks for your help! A couple questions:

  1. It looks like the 'diff' property that the differ returns is only used by file tests and the VS Code extension. Is that right?
  2. It looks like logs are only used if a test got worse or was force updated. That would mean there's no way for a non-file test to log a progress message when it improves. Is that right?
  3. If I understand 2. right, would a PR adding diff logging to the 'isBetter' case here be welcome? Or is this a 'make your own reporter' kind of thing?

Giesch avatar Feb 28 '22 16:02 Giesch

I'm going to close this, because existing functionality covered what we really wanted. Being able to customize the 'made progress' log was more of a nice-to-have.

Thanks for making this project! It's bettering my life 😄 .

Giesch avatar Mar 09 '22 20:03 Giesch

Gonna reopen it so I remember to look at it ❤️

Glad you're liking it, let me know if I can help with anything!

phenomnomnominal avatar Mar 10 '22 11:03 phenomnomnominal