Skip to content

Commit

Permalink
Merge pull request #685 from dvingo/dvingo/fix-cljs-instrument-check
Browse files Browse the repository at this point in the history
cljs instrumentation: ensure malli.generator is available at runtime
  • Loading branch information
ikitommi authored Apr 5, 2022
2 parents 005dfd2 + 8fceeea commit 3599fbd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/malli/instrument/cljs.clj
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
(ns malli.instrument.cljs
(:require [cljs.analyzer.api :as ana-api]
[clojure.walk :as walk]
[malli.core :as m]
[malli.generator :as mg]))
[malli.core :as m]))

;;
;; Collect schemas - register them into the known malli.core/-function-schemas[-cljs]* atom based on their metadata.
Expand Down Expand Up @@ -125,7 +124,7 @@
(defn -emit-check [{:keys [schema]} fn-sym]
`(let [schema# (m/function-schema ~schema)
fn# (or (get @instrumented-vars '~fn-sym) ~fn-sym)]
(when-let [err# (mg/check schema# fn#)]
(when-let [err# (perform-check schema# fn#)]
['~fn-sym err#])))

(defn -check []
Expand Down
6 changes: 5 additions & 1 deletion src/malli/instrument/cljs.cljs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
(ns malli.instrument.cljs
(:require-macros [malli.instrument.cljs]))
(:require-macros [malli.instrument.cljs])
(:require [malli.generator :as mg]))

(defonce instrumented-vars (atom {}))

(defn -filter-var [f] (fn [_ s _] (f s)))
(defn -filter-ns [& ns] (fn [n _ _] ((set ns) n)))

(defn perform-check [schema f]
(mg/check schema f))
4 changes: 4 additions & 0 deletions test/malli/instrument/cljs_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,7 @@

(is (= 1 (minus-small-int "2")))
(is (= 9 (minus-small-int 10)))))

(deftest check-test
(let [results (mi/check)]
(is (map? results))))

0 comments on commit 3599fbd

Please sign in to comment.