-
-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Show expected vs actual as pretty diff? #5
Comments
there is also tool that modifies output of cljs.test: https://github.com/pjstadig/humane-test-output |
Here is how to have diffs in the output using https://github.com/pjstadig/humane-test-output: (ns app.run-all
(:require
[cljs-test-display.core :as display]
[cljs.test :refer-macros [run-tests] :refer [empty-env]]
[goog.dom.classlist :as classlist]
[goog.dom :as gdom]
[cljs.pprint :as pp]
[pjstadig.print :as p]
[pjstadig.util :as util]
[app.test-test])
(:import [goog.string StringBuffer]))
(def dummy-env (empty-env))
;; fix bindings (https://github.com/pjstadig/humane-test-output/pull/38)
(set! p/with-pretty-writer
(fn with-pretty-writer [f]
(binding [p/*sb* (StringBuffer.)]
(binding [*out* (pp/get-pretty-writer (StringBufferWriter. p/*sb*))]
(f)))))
;; reporting with diffs
(set! display/add-fail-node!
(fn add-fail-node! [m]
(let [out (binding [cljs.test/*current-env* dummy-env] ;; we don't want `humane-test-output` to modify the env
(with-out-str
(util/report- (p/convert-event m))))
node (display/div :test-fail
(display/contexts-node)
(display/div :fail-body
(when-let [message (:message m)]
(display/div :test-message message))
(display/n :pre {}
(display/n :code {} out))))
curr-node (display/current-node)]
(classlist/add curr-node "has-failures")
(classlist/add (display/current-node-parent) "has-failures")
(gdom/appendChild curr-node node))))
(run-tests (cljs-test-display.core/init! "app-testing")
'app.test-test) |
Hi and thanks for the snippet above! I recently tried it out and it seems like the "fix bindings" part is no longer needed. Here is my version (which also includes a hack to remove the "FAIL IN" part of the humane-test-output report as well as adding the original (ns app.run-all
(:require
[cljs-test-display.core :as display]
[cljs.test :refer-macros [run-tests] :refer [empty-env]]
[goog.dom.classlist :as classlist]
[goog.dom :as gdom]
[cljs.pprint :as pp]
[pjstadig.print :as p]
[pjstadig.util :as util]
[app.test-test])
(:import [goog.string StringBuffer]))
(def dummy-env (empty-env))
;; reporting with diffs
(set! display/add-fail-node!
(fn add-fail-node! [m]
(let [out (binding [cljs.test/*current-env* dummy-env] ;; we don't want `humane-test-output` to modify the env
(with-out-str
(util/report- (p/convert-event m))))
clean-out (->> (str/split out #"\n")
(drop-while #(not (str/starts-with? % "expected")))
(str/join "\n")
(str (with-out-str (pp/pprint (:expected m))) "\n"))
node (display/div :test-fail
(display/contexts-node)
(display/div :fail-body
(when-let [message (:message m)]
(display/div :test-message message))
(display/n :pre {}
(display/n :code {} clean-out))))
curr-node (display/current-node)]
(js/console.log clean-out)
(classlist/add curr-node "has-failures")
(classlist/add (display/current-node-parent) "has-failures")
(gdom/appendChild curr-node node))))
(run-tests (cljs-test-display.core/init! "app-testing")
'app.test-test) |
I wonder if pretty diffs on expected vs actual results on failures might be interesting.
We should probably continue to show the current failure as is but including also including a pretty diff would make some failures much easier to grok.
I'm thinking along the lines of what eftest and kaocha produce.
The text was updated successfully, but these errors were encountered: