diff --git a/src/main/shadow/build/targets/browser_test.clj b/src/main/shadow/build/targets/browser_test.clj index 0e0cac60..52855fbd 100644 --- a/src/main/shadow/build/targets/browser_test.clj +++ b/src/main/shadow/build/targets/browser_test.clj @@ -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$"}} @@ -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) ))) diff --git a/src/main/shadow/cljs/devtools/client/env.cljs b/src/main/shadow/cljs/devtools/client/env.cljs index 94b09630..81999850 100644 --- a/src/main/shadow/cljs/devtools/client/env.cljs +++ b/src/main/shadow/cljs/devtools/client/env.cljs @@ -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*