Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cljs instrumentation: ensure malli.generator is available at runtime #685

Merged
merged 1 commit into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))))