kaocha icon indicating copy to clipboard operation
kaocha copied to clipboard

Could we store the test result in the results that are passed to the post-summary hook?

Open gabrielgiussi opened this issue 1 year ago • 3 comments

Right now, at least with version v1, the result of each test received by the post-summary hook contains the following keys

(:kaocha.result/error
 :kaocha.result/pending
 :kaocha.result/pass
 :kaocha.var/test
 :kaocha.plugin.randomize/sort-key
 :kaocha.testable/events
 :kaocha.plugin.capture-output/output
 :kaocha.testable/meta
 :kaocha.result/count
 :kaocha.testable/type
 :kaocha.var/name
 :kaocha.var/var
 :kaocha.testable/desc
 :kaocha.testable/wrap
 :kaocha.result/fail
 :kaocha.testable/id)

I would like to have access to the test result, assuming kaocha is calling the function under :test we would be storing true for this simple case

(deftest simple-test
  (is (= 1 1)))

((:test (meta #'simple-test)))
; => true

However, if you run a test using the defflow macro from state-flow the result is a pair [result state] which would allow me to store information in the state that I can later use to build a report in the post-summary hook.

(defflow my-flow {:init (constantly {:value 1
                                     :map   {:a 1 :b 2}})}
  [value (state/gets :value)]
  (testing "1" (mc/match? 1 value))
  (testing "b is 2" (mc/match? {:b 2} (state/gets :map))))

((:test (meta #'my-flow)))
; => [{:match/result :match,
;  :match/expected {:b 2},
;  :match/actual {:a 1, :b 2},
;  :probe/results [{:check-result true, :value {:a 1, :b 2}}],
;  :probe/sleep-time 200,
;  :probe/times-to-try 1}
; {:value 1, :map {:a 1, :b 2}}]

gabrielgiussi avatar Mar 07 '24 20:03 gabrielgiussi