Skip to content

Commit

Permalink
fix: Tweak the storage function to use the component schema
Browse files Browse the repository at this point in the history
  • Loading branch information
liquidz committed Jul 28, 2024
1 parent 391b29e commit b7e5ffe
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
25 changes: 16 additions & 9 deletions src/elin/function/storage/test.clj
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
(ns elin.function.storage.test
(:require
[elin.protocol.storage :as e.p.storage]
[elin.schema.handler :as e.s.handler]
[elin.schema.component :as e.s.component]
[malli.core :as m]))

(def ^:private last-test-query-key ::last-test-query)
(def ^:private last-failed-tests-key ::last-failed-tests)

(m/=> set-last-test-query [:=> [:cat e.s.handler/?Elin string?] :nil])
(defn set-last-test-query
[{:component/keys [session-storage]} query]
(e.p.storage/set session-storage last-test-query-key query))
(m/=> set* [:=> [:cat keyword? e.s.component/?Storage string?] :nil])
(defn- set*
[storage-key storage query]
(e.p.storage/set storage storage-key query))

(m/=> get-last-test-query [:=> [:cat e.s.handler/?Elin] string?])
(defn get-last-test-query
[{:component/keys [session-storage]}]
(e.p.storage/get session-storage last-test-query-key))
(m/=> get* [:=> [:cat keyword? e.s.component/?Storage] string?])
(defn- get*
[storage-key storage]
(e.p.storage/get storage storage-key))

(def set-last-test-query (partial set* last-test-query-key))
(def get-last-test-query (partial get* last-test-query-key))

(def set-last-failed-tests-query (partial set* last-failed-tests-key))
(def get-last-failed-tests-query (partial get* last-failed-tests-key))
16 changes: 8 additions & 8 deletions src/elin/handler/test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

(m/=> run-test-under-cursor [:=> [:cat e.s.handler/?Elin] any?])
(defn run-test-under-cursor
[{:as elin :component/keys [interceptor]}]
[{:as elin :component/keys [interceptor session-storage]}]
(e/let [{:keys [code response options]} (e.f.evaluate/evaluate-current-top-list elin)
{ns-str :ns} options
var-name (or (some->> (extract-multi-method-name code)
Expand All @@ -50,7 +50,7 @@
;; cider-nrepl
(let [query {:ns-query {:exactly [(:ns ctx)]}
:exactly (:vars ctx)}]
(e.f.s.test/set-last-test-query elin query)
(e.f.s.test/set-last-test-query session-storage query)
(assoc ctx :response (e.f.n.cider/test-var-query!! nrepl query)))

;; plain
Expand All @@ -60,11 +60,11 @@
:vars vars'
:current-file (:file ctx)
:base-line (:line ctx)}]
(e.f.s.test/set-last-test-query elin query)
(e.f.s.test/set-last-test-query session-storage query)
(assoc ctx :response (e.f.n.test/test-var-query!! nrepl query))))))))

(defn run-tests-in-ns
[{:as elin :component/keys [host interceptor]}]
[{:as elin :component/keys [host interceptor session-storage]}]
(e/let [ns-str (e.f.sexpr/get-namespace elin)
path (async/<!! (e.p.host/get-current-file-path! host))
context (-> (e.u.map/select-keys-by-namespace elin :component)
Expand All @@ -82,20 +82,20 @@
(if (e.p.nrepl/supported-op? nrepl e.c.nrepl/test-var-query-op)
;; cider-nrepl
(let [query {:ns-query {:exactly [(:ns ctx)]}}]
(e.f.s.test/set-last-test-query elin query)
(e.f.s.test/set-last-test-query session-storage query)
(assoc ctx :response (e.f.n.cider/test-var-query!! nrepl query)))
;; plain
(let [vars' `(vals (ns-interns '~(symbol (:ns ctx))))
query {:ns (:ns ctx)
:vars vars'
:current-file (:file ctx)
:base-line (:line ctx)}]
(e.f.s.test/set-last-test-query elin query)
(e.f.s.test/set-last-test-query session-storage query)
(assoc ctx :response (e.f.n.test/test-var-query!! nrepl query))))))))

(defn rerun-last-tests
[{:as elin :component/keys [interceptor]}]
(let [query (e.f.s.test/get-last-test-query elin)
[{:as elin :component/keys [interceptor session-storage]}]
(let [query (e.f.s.test/get-last-test-query session-storage)
context (-> (e.u.map/select-keys-by-namespace elin :component)
(assoc :ns (or (:ns query) "")
:line (or (:base-line query) 0)
Expand Down

0 comments on commit b7e5ffe

Please sign in to comment.