Skip to content

Commit

Permalink
fix :browser-test target devtools
Browse files Browse the repository at this point in the history
the dynamic recovery added in 2.2.30 cause the devtools to be
removed from the entries since they were added at the wrong time
  • Loading branch information
thheller committed Apr 16, 2018
1 parent 137df16 commit f266ca1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 16 deletions.
9 changes: 8 additions & 1 deletion src/main/shadow/build/targets/browser_test.clj
Expand Up @@ -52,7 +52,7 @@
;; we delay setting the :entries until compile-prepare which is called every cycle
;; need to come up with a cleaner API for this
(defn test-resolve
[{::build/keys [config]
[{::build/keys [mode config]
:keys [classpath]
::keys [runner-ns] :as state}]
(let [{:keys [ns-regexp] :or {ns-regexp "-test$"}}
Expand All @@ -74,6 +74,13 @@
(-> '[shadow.test.env] ;; must be included before any deftest because of the cljs.test mod
(into test-namespaces)
(conj runner-ns)))
(cond->
(and (= :dev mode) (:worker-info state))
(update-in [::modules/config :test] browser/inject-repl-client state config)

(= :dev mode)
(-> (update-in [::modules/config :test] browser/inject-preloads state config)
(update-in [::modules/config :test] browser/inject-devtools-console state config)))
(modules/analyze)
)))

Expand Down
44 changes: 29 additions & 15 deletions src/main/shadow/cljs/devtools/client/env.cljs
Expand Up @@ -82,25 +82,39 @@
(repl-error e)
)))

(defonce original-print-fn cljs.core/*print-fn*)
(defonce original-print-err-fn cljs.core/*print-err-fn*)
;; FIXME: this need to become idempotent somehow
;; but is something sets a print-fn we can't tell if that
;; will actually call ours. only a problem if the websocket is
;; reconnected though
(defonce reset-print-fn-ref (atom nil))

(defn set-print-fns! [msg-fn]
(set-print-fn!
(fn repl-print-fn [& args]
(msg-fn {:type :repl/out :text (str/join "" args)})
(when original-print-fn
(apply original-print-fn args))))

(set-print-err-fn!
(fn repl-print-err-fn [& args]
(msg-fn {:type :repl/err :text (str/join "" args)})
(when original-print-err-fn
(apply original-print-err-fn args)))))
;; cannot capture these before as they may change in between loading this file
;; and running the websocket connect. the user code is loaded after this file
(let [original-print-fn cljs.core/*print-fn*
original-print-err-fn cljs.core/*print-err-fn*]

(reset! reset-print-fn-ref
(fn reset-print-fns! []
(set-print-fn! original-print-fn)
(set-print-err-fn! original-print-err-fn)))

(set-print-fn!
(fn repl-print-fn [& args]
(msg-fn {:type :repl/out :text (str/join "" args)})
(when original-print-fn
(apply original-print-fn args))))

(set-print-err-fn!
(fn repl-print-err-fn [& args]
(msg-fn {:type :repl/err :text (str/join "" args)})
(when original-print-err-fn
(apply original-print-err-fn args))))))

(defn reset-print-fns! []
(set-print-fn! original-print-fn)
(set-print-err-fn! original-print-err-fn))
(when-let [x @reset-print-fn-ref]
(x)
(reset! reset-print-fn-ref nil)))

(defn process-ws-msg [text handler]
(binding [reader/*default-data-reader-fn*
Expand Down

0 comments on commit f266ca1

Please sign in to comment.