11

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?

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.