Skip to content
Browse files

Add REPL (support) tests (Issue #70).

  • Loading branch information...
1 parent 51180b4 commit 21425533621dbed4364eaca029c3621a6b3224db @emezeske committed
View
30 support/src/cljsbuild/repl/listen.clj
@@ -9,22 +9,26 @@
(let [env (browser/repl-env :port (Integer. port) :working-dir output-dir)]
(repl/repl env)))
-(defn process-start-delayed [command]
- (try
- ; TODO: Poll the REPL to see if it's ready before starting
- ; the process, instead of sleeping.
- (Thread/sleep 5000)
- (util/process-start command)
- (catch Exception e
- (println "Error in background process: " e)
- (throw e))))
+(defn delayed-process-start [command]
+ (future
+ (try
+ ; TODO: Poll the REPL to see if it's ready before starting
+ ; the process, instead of sleeping.
+ (util/sleep 5000)
+ (util/process-start command)
+ (catch Exception e
+ (println "Error in background process: " e)
+ (throw e)))))
+
+(defn delayed-process-wait [process]
+ (let [p @process]
+ ((:kill p))
+ ((:wait p))))
(defn run-repl-launch [port output-dir command]
(println "Background command output will be shown after the REPL is exited via :cljs/quit .")
- (let [process-delayed (future (process-start-delayed command))]
+ (let [process (delayed-process-start command)]
(try
(run-repl-listen port output-dir)
(finally
- (let [process @process-delayed]
- ((:kill process))
- ((:wait process)))))))
+ (delayed-process-wait process)))))
View
23 support/test/cljsbuild/test/repl/listen.clj
@@ -0,0 +1,23 @@
+(ns cljsbuild.test.repl.listen
+ (:use
+ cljsbuild.repl.listen
+ midje.sweet)
+ (:require
+ [cljs.repl :as repl]
+ [cljs.repl.browser :as browser]
+ [cljsbuild.util :as util]))
+
+(def port (Integer. 1234))
+(def output-dir "output-dir")
+(def command {:shell ["command"]})
+
+(fact
+ (run-repl-listen port output-dir) => nil
+
+ (run-repl-launch port output-dir command) => nil
+ (provided
+ (delayed-process-start command) => (future {:kill (fn [] nil) :wait (fn [] nil)}))
+
+ (against-background
+ (browser/repl-env :port port :working-dir output-dir) => {} :times 1
+ (repl/repl {}) => nil :times 1))
View
13 support/test/cljsbuild/test/repl/rhino.clj
@@ -0,0 +1,13 @@
+(ns cljsbuild.test.repl.rhino
+ (:use
+ cljsbuild.repl.rhino
+ midje.sweet)
+ (:require
+ [cljs.repl :as repl]
+ [cljs.repl.rhino :as rhino]))
+
+(fact
+ (run-repl-rhino) => nil
+ (provided
+ (rhino/repl-env) => {} :times 1
+ (repl/repl {}) => nil :times 1))

0 comments on commit 2142553

Please sign in to comment.
Something went wrong with that request. Please try again.