13
13
(defn inc! [r]
14
14
(swap! r inc))
15
15
16
+ (set! *target* " nodejs" )
17
+
18
+ (def vm (js/require " vm" ))
19
+ (def fs (js/require " fs" ))
16
20
(def st (cljs/empty-state ))
17
21
22
+ (defn node-eval [{:keys [name source]}]
23
+ (.runInThisContext vm source (str (munge name) " .js" )))
24
+
25
+ (def libs
26
+ {'bootstrap-test.core :cljs
27
+ 'bootstrap-test.macros :clj
28
+ 'bootstrap-test.helper :clj })
29
+
30
+ (defn node-load [{:keys [name macros]} cb]
31
+ (if (contains? libs name)
32
+ (let [path (str " src/test/cljs/" (cljs/ns->relpath name)
33
+ " ." (cljs.core/name (get libs name)))]
34
+ (.readFile fs path " utf-8"
35
+ (fn [err src]
36
+ (cb (if-not err
37
+ {:lang :clj :source src}
38
+ (.error js/console err))))))
39
+ (cb nil )))
40
+
41
+ (defn elide-env [env ast opts]
42
+ (dissoc ast :env ))
43
+
18
44
(deftest test-compile-str
19
45
(async done
20
46
(let [l (latch 3 done)]
34
60
(fn [{:keys [error value]}]
35
61
(is (nil? error))
36
62
(is (= value " (cljs.core.truth_(cljs.core.first)?1:2)" ))
63
+ (inc! l))))))
64
+
65
+ (deftest test-eval-str
66
+ (async done
67
+ (let [l (latch 3 done)]
68
+ (cljs/eval-str st " (+ 1 1)" nil
69
+ {:eval node-eval}
70
+ (fn [{:keys [error value]}]
71
+ (is (nil? error))
72
+ (is (== value 2 ))
73
+ (inc! l)))
74
+ (cljs/eval-str st " (def x 1)" nil
75
+ {:eval node-eval
76
+ :context :expr
77
+ :def-emits-var true }
78
+ (fn [{:keys [error value]}]
79
+ (is (nil? error))
80
+ (is (var? value))
81
+ (inc! l)))
82
+ (cljs/eval-str st " (fn [])" nil
83
+ {:eval node-eval
84
+ :context :expr
85
+ :def-emits-var true }
86
+ (fn [{:keys [error value]}]
87
+ (is (nil? error))
88
+ (is (fn? value))
37
89
(inc! l))))))
0 commit comments