Skip to content

Commit e50663e

Browse files
committed
Improve nrepl test reporting
1 parent a42b2c7 commit e50663e

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

src/portal/nrepl.clj

+20-7
Original file line numberDiff line numberDiff line change
@@ -111,26 +111,39 @@
111111
(catch Exception _))
112112
transport))
113113

114+
(def ^:private ^:dynamic *test-report* nil)
115+
116+
(defmulti ^:dynamic report (constantly :default))
117+
118+
(defmethod report :default [message]
119+
(when *test-report*
120+
(swap! *test-report* conj message))
121+
(when-let [f (get-method report (:type message))]
122+
(f message)))
123+
124+
(defn- add-method [^clojure.lang.MultiFn multifn dispatch-val f]
125+
(.addMethod multifn dispatch-val f))
126+
127+
(doseq [[dispatch-value f] (methods test/report)]
128+
(add-method report dispatch-value f))
129+
114130
(defn- wrap-portal* [handler msg]
115-
(let [report (atom [])
116-
test-report test/report
117-
portal-report (fn [value]
118-
(swap! report conj value)
119-
(test-report value))]
131+
(let [test-report (atom [])]
120132
(handler
121133
(cond-> msg
122134
(#{"eval" "load-file"} (:op msg))
123135
(-> (update :transport
124136
->PortalTransport
125137
(assoc msg
126-
:report report
138+
:report test-report
127139
:stdio (atom [])
128140
:start (System/nanoTime)
129141
:time (Date.)))
130142
(update :session
131143
(fn [session]
132144
(swap! session assoc
133-
#'test/report portal-report)
145+
#'test/report report
146+
#'*test-report* test-report)
134147
session)))))))
135148

136149
(defn wrap-portal

0 commit comments

Comments
 (0)