Skip to content

Commit

Permalink
test: Add minimal test for detect-shadow-cljs-port interceptor
Browse files Browse the repository at this point in the history
  • Loading branch information
liquidz committed Dec 20, 2024
1 parent 9f07c52 commit ce39d3d
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions test/elin/interceptor/connect/shadow_cljs_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
(ns elin.interceptor.connect.shadow-cljs-test
(:require
[clojure.core.async :as async]
[clojure.java.io :as io]
[clojure.test :as t]
[elin.function.select :as e.f.select]
[elin.interceptor.connect.shadow-cljs :as sut]
[elin.protocol.host :as e.p.host]
[elin.test-helper :as h]
[elin.util.file :as e.u.file]))

(t/use-fixtures :once h/malli-instrument-fixture)
(t/use-fixtures :once h/warn-log-level-fixture)

(def ^:private detect-shadow-cljs-port-enter
(:enter sut/detect-shadow-cljs-port))

;; (def ^:private detect-shadow-cljs-port-leave
;; (:leave sut/detect-shadow-cljs-port))

(t/deftest detect-shadow-cljs-port-enter-test
(let [cwd (.getAbsolutePath (io/file "."))
test-elin (h/test-elin)
detect-shadow-cljs-port-enter-test (fn [hostname port-file]
(-> test-elin
(assoc :hostname hostname
:port-file port-file)
(detect-shadow-cljs-port-enter)
(select-keys [:hostname port-file])))]
(t/testing "Positive"
(t/testing "No shadow-cljs port file"
(with-redefs [e.p.host/get-current-working-directory! (fn [& _]
(async/go cwd))
e.f.select/select-from-candidates (fn [_ candidates]
(first candidates))]
(t/is (= {:hostname nil}
(detect-shadow-cljs-port-enter-test nil nil)))))

(t/testing "Exists shadow-cljs port file, but not selected")
(t/testing "Exists shadow-cljs port file, and selected")

(t/testing "Failed to fetch project root directory"
(with-redefs [e.p.host/get-current-working-directory! (fn [& _]
(async/go cwd))
e.u.file/get-project-root-directory (constantly nil)]
(t/is (= {:hostname nil}
(detect-shadow-cljs-port-enter-test nil nil))))))

(t/testing "Negative")))

0 comments on commit ce39d3d

Please sign in to comment.