Is it intended that in kaocha a clojure.test/testing
block doesn’t (appear) to print the context string if it contains no assertions?
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.
hmmm, let me see. You're using the :documentation
reporter?
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))
the actual printing happens in :pass
/ :error
/ :fail
, so yes this behavior is in a sense expected. clojure.test
does the same thing.
(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*) ...)
)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"))))
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)
So I guess without an event your hands are tied then?
I guess I might need to write my own macro
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
oh really? where was this posted?
Just mentioned here. There were loose plans to spin clojure.test out, similarly to how clojure.spec was.
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
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
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*)))
Alex was looking for a new maintainer