Skip to content

Commit 2be1584

Browse files
dan suttonbbatsov
authored andcommitted
Fix tests for figwheel-main init form
1 parent 5f17d0a commit 2be1584

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

cider.el

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -764,9 +764,10 @@ Figwheel for details."
764764

765765
(defun cider--figwheel-main-get-builds ()
766766
"Extract build names from the <build-id>.cljs.edn config files in the project root."
767-
(let ((builds (directory-files (clojure-project-dir) nil ".*\\.cljs\\.edn")))
768-
(mapcar (lambda (f) (string-match "^\\(.*\\)\\.cljs\\.edn" f)
769-
(match-string 1 f)) builds)))
767+
(when-let ((project-dir (clojure-project-dir)))
768+
(let ((builds (directory-files project-dir nil ".*\\.cljs\\.edn")))
769+
(mapcar (lambda (f) (string-match "^\\(.*\\)\\.cljs\\.edn" f)
770+
(match-string 1 f)) builds))))
770771

771772
(defun cider-figwheel-main-init-form ()
772773
"Produce the figwheel-main ClojureScript init form."

test/cider-tests.el

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@
3838
;; whitespace checks sprinkled amongst other tests
3939
(describe "from options"
4040
(it "leaves keywords alone"
41-
(let ((cider-figwheel-main-default-options ":dev "))
41+
(let ((cider-figwheel-main-default-options ":dev"))
4242
(expect (cider-figwheel-main-init-form) :to-equal "(do (require 'figwheel.main) (figwheel.main/start :dev))")))
4343
(it "leaves maps alone"
44-
(let ((cider-figwheel-main-default-options " {:a 1 :b 2}"))
44+
(let ((cider-figwheel-main-default-options "{:a 1 :b 2}"))
4545
(expect (cider-figwheel-main-init-form) :to-equal "(do (require 'figwheel.main) (figwheel.main/start {:a 1 :b 2}))")))
4646
(it "leaves s-exprs alone"
47-
(let ((cider-figwheel-main-default-options " (hashmap :a 1 :b 2)"))
47+
(let ((cider-figwheel-main-default-options "(hashmap :a 1 :b 2)"))
4848
(expect (cider-figwheel-main-init-form) :to-equal "(do (require 'figwheel.main) (figwheel.main/start (hashmap :a 1 :b 2)))")))
4949
(it "prepends colon to plain names"
5050
(let ((cider-figwheel-main-default-options " dev"))
@@ -55,16 +55,20 @@
5555
;; not necessary as of this writing, but it can't hurt
5656
(setq-local cider-figwheel-main-default-options nil))
5757
(it "leaves keywords alone"
58-
(spy-on 'completing-read :and-return-value " :prod ")
58+
(spy-on 'completing-read :and-return-value ":prod")
59+
(spy-on 'cider--figwheel-main-get-builds :and-return-value '("dev" "prod"))
5960
(expect (cider-figwheel-main-init-form) :to-equal "(do (require 'figwheel.main) (figwheel.main/start :prod))"))
6061
(it "leaves maps alone"
61-
(spy-on 'completing-read :and-return-value " {:c 3 :d 4}")
62+
(spy-on 'completing-read :and-return-value "{:c 3 :d 4}")
63+
(spy-on 'cider--figwheel-main-get-builds :and-return-value '("dev" "prod"))
6264
(expect (cider-figwheel-main-init-form) :to-equal "(do (require 'figwheel.main) (figwheel.main/start {:c 3 :d 4}))"))
6365
(it "leaves s-exprs alone"
64-
(spy-on 'completing-read :and-return-value "(keyword \"dev\") ")
66+
(spy-on 'completing-read :and-return-value "(keyword \"dev\")")
67+
(spy-on 'cider--figwheel-main-get-builds :and-return-value '("dev" "prod"))
6568
(expect (cider-figwheel-main-init-form) :to-equal "(do (require 'figwheel.main) (figwheel.main/start (keyword \"dev\")))"))
6669
(it "prepends colon to plain names"
67-
(spy-on 'completing-read :and-return-value "prod ")
70+
(spy-on 'completing-read :and-return-value "prod")
71+
(spy-on 'cider--figwheel-main-get-builds :and-return-value '("dev" "prod"))
6872
(expect (cider-figwheel-main-init-form) :to-equal "(do (require 'figwheel.main) (figwheel.main/start :prod))"))))
6973

7074
(describe "cider-project-type"

0 commit comments

Comments
 (0)