Trying to get PhantomJs and ClojureScript.test working

841 views
Skip to first unread message

Creighton Kirkendall

unread,
Sep 1, 2013, 9:34:54 AM9/1/13
to clojur...@googlegroups.com
I am having some issues getting PhantomJs and ClojureScript.test working. While my setup seems to be correct(I don't get any errors), it does not run the tests, instead it drops me to what looks like a broken phantomjs prompt.

>lein cljsbuild test
Compiling ClojureScript.
Running all ClojureScript tests.
phantomjs>


Here is my project.clj:


(defproject chatter-box "0.1.0-SNAPSHOT"
:description "Example chat program to illustrate core.async and enfocus."
:url "http://ckirkendall.github.io/enfocus-site"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.5.1"]
[compojure "1.1.5"]
[org.clojure/core.async "0.1.0-SNAPSHOT"]
[ring "1.2.0"]
[com.cemerick/clojurescript.test "0.0.5-SNAPSHOT"]]
:source-paths ["src/client" "src/common" "src/server"]
:test-paths ["src/client" "src/server"
;add source paths for cross compiled code
".generated/clj" ".generated/cljs"]
:plugins [[lein-cljsbuild "0.3.2"]
[com.keminglabs/cljx "0.3.0"]]
; Enable the lein hooks for: clean, compile, test, and jar.
:hooks [leiningen.cljsbuild cljx.hooks]
:main chatter-box.core
:cljsbuild {
; Configure the REPL support; see the README.md file for more details.
:repl-listen-port 9000
:repl-launch-commands {
"phantom" ["phantomjs"
"phantom/repl.js"
:stdout ".repl-phantom-out"
:stderr ".repl-phantom-err"]}
:test-commands
; Test command for running the unit tests in "test-cljs" (see below).
; $ lein cljsbuild test
{"unit" ["phantomjs"
:cljs.testrunner
"resources/private/js/unit-test.js"]}
:builds
[{:id "dev"
:source-paths ["src/client"]
:compiler {:output-to "resources/public/js/main-debug.js"
:optimizations :whitespace
:pretty-print true}}
; This build has the highest level of optimizations, so it is
; efficient when running the app in production.
{:id "prod"
:source-paths ["src/client"]
:compiler {:output-to "resources/public/js/main.js"
:optimizations :advanced
:pretty-print false}}
; This build is for the ClojureScript unit tests that will
; be run via PhantomJS. See the phantom/unit-test.js file
; for details on how it's run.
{:id "test"
:source-paths ["src/client" "test/client"]
:compiler {:output-to "resources/private/js/unit-test.js"
:optimizations :whitespace
:pretty-print true}}]}

;cross compiling code for both clojurescript and clojure
:cljx {:builds [{:source-paths ["src/common" "test/common"]
:output-path "target/generated/clj"
:rules :clj}

{:source-paths ["src/common" "test/common"]
:output-path "target/generated/cljs"
:rules :cljs}]}
:ring {:handler chatter-box.core})

David Nolen

unread,
Sep 1, 2013, 4:15:24 PM9/1/13
to clojur...@googlegroups.com
Might want to ping Chas Emerick, he's had some experience wrangling Phantom.

David



--
Note that posts from new members are moderated - please be patient with your first post.
---
You received this message because you are subscribed to the Google Groups "ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojurescrip...@googlegroups.com.
To post to this group, send email to clojur...@googlegroups.com.
Visit this group at http://groups.google.com/group/clojurescript.

Shantanu Kumar

unread,
Sep 1, 2013, 4:26:21 PM9/1/13
to clojur...@googlegroups.com
Hi Creighton,

I got it working using the following entry (cljx + clojurescript.text + lein-cljsbuild) under :cljsbuild in project.clj:

:test-commands {"unit-tests" ["runners/phantomjs.js" "target/cljs/testable.js"]}

Got the runner script from here:
https://github.com/cemerick/clojurescript.test/blob/master/resources/cemerick/cljs/test/runner.js

The file testable.js is auto generated.

Shantanu

Mimmo Cosenza

unread,
Sep 1, 2013, 4:28:29 PM9/1/13
to clojur...@googlegroups.com
I Creighton,
perhaps it could be helpful to read the first part of the tutorial-16 of the modern-cljs series.


HIH

mimmo



Creighton Kirkendall

unread,
Sep 2, 2013, 8:59:15 AM9/2/13
to clojur...@googlegroups.com
What version of clojurescript.test are you using. I think the setup change recently and I was trying to get the new setup to work. Should have probably said that.

CK

Shantanu Kumar

unread,
Sep 2, 2013, 9:06:08 AM9/2/13
to clojur...@googlegroups.com
On Monday, 2 September 2013 18:29:15 UTC+5:30, Creighton Kirkendall wrote:
> What version of clojurescript.test are you using. I think the setup change recently and I was trying to get the new setup to work. Should have probably said that.

I am using clojurescript.test 0.0.4 with cljx 0.3.0 and lein-cljsbuild 0.3.2.

Shantanu

Creighton Kirkendall

unread,
Sep 2, 2013, 9:06:40 AM9/2/13
to clojur...@googlegroups.com
I think it may be an issue with either the phantom version or a bug in the new setup. I can't even get clojurescript.test to pass its own tests. I cloned clojurescript.test down and ran 'lein cljsbuild test' and it drops me the same broken prompt.

Creighton Kirkendall

unread,
Sep 2, 2013, 9:13:23 AM9/2/13
to clojur...@googlegroups.com
mimmo,

I did actually look at that but I was trying to get the new setup to work. Looks like it has issues. Also, great job on the modern-cljs! Any chance of adding enfocus to the mix? I bias clearly but I think your enlive tutorial could be move to enfocus with little to no changes. :)

http://ckirkendall.github.io/enfocus-site/

CK

Andrew Mcveigh

unread,
Sep 2, 2013, 9:32:06 AM9/2/13
to clojur...@googlegroups.com
Hi Creighton,

Today, I've been having the same problem as you, I've just an hour ago managed to get it working on a library. Feel free to check out my repo/project.clj if it helps.

https://github.com/andrewmcveigh/cljs-time
https://github.com/andrewmcveigh/cljs-time/blob/master/project.clj

Mimmo Cosenza

unread,
Sep 2, 2013, 1:08:44 PM9/2/13
to clojur...@googlegroups.com

On Sep 2, 2013, at 3:13 PM, Creighton Kirkendall <ckirk...@gmail.com> wrote:

> mimmo,
>
> I did actually look at that but I was trying to get the new setup to work. Looks like it has issues.

Have you checked the cljs version? If I remember well clojurescript.test requires a CLJS version >= 1835….

> Also, great job on the modern-cljs!

thanks!

> Any chance of adding enfocus to the mix?

It's exactly what I want to add ad a next tutorial!!!

> I bias clearly but I think your enlive tutorial could be move to enfocus with little to no changes. :)

Yes, I'll be back from vacation in the middle of this week and I'll dedicate my weekend in studying enfous and trying to port the enlive code from the server side to the client side.

Thanks a lot for the great work you're doing with enfocus!!!

Mimmo

>
> http://ckirkendall.github.io/enfocus-site/
>
> CK

Chas Emerick

unread,
Sep 2, 2013, 2:52:08 PM9/2/13
to clojur...@googlegroups.com
A couple of issues I see:

* You're attempting to use version 0.0.5-SNAPSHOT of clojurescript.test,
which AFAIK, does not exist anywhere (the latest release is 0.0.4, and I
haven't published an 0.0.5-SNAPSHOT). Maybe you have a local install of
git master?

* You're attempting to use the (not-yet-released) functionality where
some clojurescript.test Leiningen middleware will inject into your
lein-cljsbuild test "spec" the location to the test runner script (which
clojurescript.test will begin bundling, rather than requiring you to
copy the runner into every one of your projects). That's cool (I'm glad
people are pushing to use the newest stuff!), but the feature is very
new, only on master (not in any released build), and I can't say it's
baked yet at all. You can track this issue for progress:

https://github.com/cemerick/clojurescript.test/issues/11

Creighton, I'd suggest using the released 0.0.4 version, and matching
the cljsbuild test configuration described in the clojurescript.test
README; that'll get you home.

Cheers,

- Chas

Creighton Kirkendall

unread,
Sep 2, 2013, 8:01:05 PM9/2/13
to clojur...@googlegroups.com
I went back to 0.0.4 and all is good. Thank you for all your hard work!

Chris Zheng

unread,
Feb 14, 2014, 3:54:41 PM2/14/14
to clojur...@googlegroups.com
Is there a way of doing autotesting of clojurescript code?

I'm using 0.2.2 and when I run lein cljsbuild test, it only seems to test once.

My settings are:

:cljsbuild {:builds [{:source-paths ["src" "test"]
:compiler {:output-to "target/cljs/testable.js"
:optimizations :whitespace
:pretty-print true}}]
:test-commands {"unit-tests" ["phantomjs" :runner
"this.literal_js_was_evaluated=true"
"target/cljs/testable.js"]}}

Chas Emerick

unread,
Feb 14, 2014, 4:11:51 PM2/14/14
to clojur...@googlegroups.com
No, `cljsbuild auto` only compiles. There's a PR for this for v2.x, but
I haven't gotten to it yet.

https://github.com/emezeske/lein-cljsbuild/pull/222

- Chas

Joel Holdbrooks

unread,
Feb 14, 2014, 5:26:25 PM2/14/14
to clojur...@googlegroups.com

I wrote a short blog post on a technique I use to get "auto testing" for ClojureScript.

Joel Holdbrooks

unread,
Feb 14, 2014, 5:26:57 PM2/14/14
to clojur...@googlegroups.com
On Friday, February 14, 2014 12:54:41 PM UTC-8, Chris Zheng wrote:

Forgot the link, whoops! Here it is: http://noprompt.github.io/clojurescript/testing/ruby/2014/01/25/autotesting-clojurescript.html

Chas Emerick

unread,
Feb 15, 2014, 7:00:01 AM2/15/14
to clojur...@googlegroups.com
You don't need external tools for this kind of workflow; lein-cljsbuild
provides a :notify-command option that will shell out to whatever you
want (including a phantomjs/node/whatever process to run your tests):

https://github.com/emezeske/lein-cljsbuild/blob/master/sample.project.clj#L73

I was reminded of this via
https://github.com/cemerick/clojurescript.test/issues/26 (which is re:
the fact that :runner, :node-runner, etc are currently only replaced
within :test-commands). I'll get that into clojurescript.test right
after 0.3.0 (async support) is done.

- Chas

Chas Emerick

unread,
Feb 15, 2014, 7:32:27 AM2/15/14
to clojur...@googlegroups.com
OK, so I decided to bring a fix for clojurescript.test issue #26 into
v0.2.3 straight away. So, using [com.cemerick/clojurescript.test
"0.2.3-SNAPSHOT"], you can put references to your desired test runners
anywhere in the project map (including :notify-command lein-cljsbuild
command vectors), so you can trigger tests on `cljsbuild auto` builds
easily. The one wrinkle is that I decided that swapping out
unnamespaced keywords throughout the project map was a bit impolite, so
*outside of `:test-commands`, you need to namespace test runner keyword
placeholders*, like so:

:notify-command ["phantomjs" :cljs.test/runner "target/cljs/testable.js"]

...and so on.

Cheers,

- Chas

Joel Holdbrooks

unread,
Feb 15, 2014, 12:26:33 PM2/15/14
to clojur...@googlegroups.com
Awesome. I didn't think to use :notify-command. I'll update the post today.

Chris Zheng

unread,
Feb 15, 2014, 3:31:37 PM2/15/14
to clojur...@googlegroups.com
Thanks Chas and Joel.

Looking forward to trying the new version!

Ps. In the meantime... I started writing jasmine tests in javascript and it was very painful.

On 16/02/2014, at 4:26, Joel Holdbrooks <cjhold...@gmail.com> wrote:

> Awesome. I didn't think to use :notify-command. I'll update the post today.
>
> --
> Note that posts from new members are moderated - please be patient with your first post.
> ---
> You received this message because you are subscribed to a topic in the Google Groups "ClojureScript" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojurescript/QFLGxDVCelc/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to clojurescrip...@googlegroups.com.

Joel Holdbrooks

unread,
Feb 16, 2014, 5:16:29 AM2/16/14
to clojur...@googlegroups.com
Thanks for the feedback Chas. I've updated the post.
Reply all
Reply to author
Forward
0 new messages