I am using clj-webdriver to do some Selenium based testing on a Clojurescript web app. Sometimes, there is something in the app itself that I want to be able to fiddle with while the test are running. I see that clj-webdriver has something called (execute-script js args)
that takes a string of Javascript code and runs it on the current testing browser. I have tested this and it seems to work. I would like to pass clojurescript code to execute-script
though. I need something that will compile my Clojure form into Clojurescript code.
I see the following question that sort of relates. It says to use the js/emit function from clutch. I searched clutch and found it mentioned only in (view) in cljs-views.clj I have attempted the following in a repl:
user> (use 'com.ashafa.clutch.cljs-views)
nil
user> view
<core$comp$fn__4034 clojure.core$comp$fn__4034@ebd3f80>
user> js/emit
CompilerException java.lang.RuntimeException: No such namespace: js, #compiling (NO_SOURCE_PATH:1)
user>
This isn't terribly surprising, how could js be in a regular clojure namesapce? But how do I use this (or any other) system to generate Clojurescript (javascript) code that I can pass to execute-script
?
Use the cljs.closure/build
function:
(use '[cljs.closure :only [build]])
(build '(print "hello") {:optimizations :simple :pretty-print true})
There are more examples in a comment at the bottom of closure.clj. There are options for outputting to a file as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With