kaocha

Official support channel: https://clojureverse.org/c/projects/kaocha
2020-06-26T09:46:44.346500Z

Is it intended that in kaocha a clojure.test/testing block doesn’t (appear) to print the context string if it contains no assertions?

2020-06-26T09:55:22.352600Z

Normally you’d put assertions in… but https://github.com/igrishaev/etaoin implicitly encourages a style of testing where you don’t always explicitly assert. Essentially because browser testing is inherently asynchronous, you end up testing by waiting for predicates to become true, until a timeout is thrown. The timeout exception is then essentially an assertion failure, and the fact the test makes progress is an implicit success. I don’t particularly like this, but the alternative seems to be that you wait for the predicate to be true; and then assert that predicate for clojure.test; but then each assertion is expressed twice. I suppose I could write a trivial macro to tidy this up; but I was surprised to discover testing blocks without a success or failure don’t appear to display.

plexus 2020-06-26T10:19:07.353Z

hmmm, let me see. You're using the :documentation reporter?

plexus 2020-06-26T10:20:14.353500Z

the thing is that testing blocks don't emit events, they only change the context

(defmacro testing
  "Adds a new string to the list of testing contexts.  May be nested,
  but must occur inside a test function (deftest)."
  {:added "1.1"}
  [string & body]
  `(binding [*testing-contexts* (conj *testing-contexts* ~string)]
     ~@body))

plexus 2020-06-26T10:21:00.354200Z

the actual printing happens in :pass / :error / :fail, so yes this behavior is in a sense expected. clojure.test does the same thing.

plexus 2020-06-26T10:21:59.354900Z

(defmethod report :fail [m]
  (with-test-out
    (inc-report-counter :fail)
    (println "\nFAIL in" (testing-vars-str m))
    (when (seq *testing-contexts*) (println (testing-contexts-str)))
    (when-let [message (:message m)] (println message))
    (println "expected:" (pr-str (:expected m)))
    (println "  actual:" (pr-str (:actual m)))))
(this is from clojure.test, notice the (when (seq *testing-contexts*) ...))

plexus 2020-06-26T10:22:40.355200Z

somewhat similar in Kaocha

(defmethod doc :pass [m]
  (t/with-test-out
    (doc-print-contexts t/*testing-contexts*)))

(defmethod doc :error [m]
  (t/with-test-out
    (doc-print-contexts t/*testing-contexts*)
    (print (output/colored :red " ERROR"))))

(defmethod doc :kaocha/fail-type [m]
  (t/with-test-out
    (doc-print-contexts t/*testing-contexts*)
    (print (output/colored :red " FAIL"))))

2020-06-26T10:30:36.356700Z

Yeah it’s the documentation reporter… Makes sense; I was just surprised when none of my tests appeared to run (because etaoin tests) don’t always contain assertions. I’ve hacked it by explicitly adding some (is :succeeded)

2020-06-26T10:30:53.357200Z

So I guess without an event your hands are tied then?

2020-06-26T10:31:30.357600Z

I guess I might need to write my own macro

plexus 2020-06-26T10:33:13.358900Z

yeah, this is one of the many small annoyances where clojure.test just doesn't give us the affordances to make things better... One day I'll do lambdaisland.test which will be 100% the same API but will have little things like this fixed

plexus 2020-06-29T07:22:43.363900Z

oh really? where was this posted?

dominicm 2020-06-29T07:35:38.364600Z

Just mentioned here. There were loose plans to spin clojure.test out, similarly to how clojure.spec was.

plexus 2020-06-26T10:34:37.360300Z

right now in the doc reporter we need to keep track of which testing contexts we've already printed, so that if you have multiple assertions we don't print them multiple times... instead we could have had :start-context / :end-context

plexus 2020-06-26T10:36:07.361Z

making your own testing macro that delegates to clojure.test/testing but also calls (t/with-test-out (doc-print-contexts t/*testing-contexts*)) should work

👍 1
plexus 2020-06-26T10:37:16.362Z

or to do it cleanly, have it (t/do-report {:type :start-context}), and then add a (defmethod :kaocha.report/doc :start-context [m] (t/with-test-out (doc-print-contexts t/*testing-contexts*)))

dominicm 2020-06-26T14:45:17.362100Z

Alex was looking for a new maintainer