Kaocha - Clearer reporting

Are there any options/reporters that…

  1. Clear output before tests run in --watch mode?
    1.1 So that old outputs don’t interfere with the latest output
  2. Use aviso/pretty with Kaocha? For pretty stacktraces?
    2.1 Clear, shorter stacktraces so that I don’t have to keep scrolling up to see the exception

As mentioned on Clojurians neither of these is currently there. But as always Kaocha is flexible enough to do it yourself.

The first one is pretty easy. You can configure Kaocha to have multiple reporters, so you can add an extra reporter that only does the clear-screen.

Having a better look I’m afraid the reporter approach for clearing the screen won’t work, because we don’t have a reporter event that happens exactly once at the start. The closest we have is :kaocha/begin-suite, but if you run a test run which contains multiple suites then that will be a problem.

But we do have a :pre-run plugin hook, so you can either write a plugin with a pre-run hook, or use the hooks plugin and define it directly in tests.edn.

{:plugins [:hooks]
 :hooks/pre-run [(fn [test-plan] (print "\u001b[2J\u001b[H") test-plan)]}

Or if you only want it in watch mode: (when (:kaocha/watch? test-plan) (print ...))

The second part is slightly less trivial, since the way we handle stacktraces is baked into our reporters. Might be interesting to consider making that pluggable, but as things stand I think making a reporter that reimplements :summarize is the way to go.

Note that we already split the reporters into one that handles general assertions, and one that handles :summarize. So for instance the dots reporter consists of dots* and result. You only need to replace result.

(defn my-result [m]
  (when (= :summarize (:type m))
  ,,,copy-and-modify whatever you need from kaocha.report/result,,,
{:reporter [kaocha.report/dots* my.kaocha.stuff/my-result]}

I hope that makes sense! Good luck and let me know if you get stuck!