Anna Pawlicka

Programmer. Hiker. Cook. Always looking for interesting problems to solve.

About | Archive | Talks

Travis CI and ClojureScript tests

21 Dec 2014 | cljs.test, clojure, ClojureScript

I have something to confess: I haven’t written any ClojureScript tests until this very morning. There were various reasons for that and often I would copy whatever was possible to Clojure namespace and test it there using clojure.test. So when a new ClojureScript with a port of the clojure.test namespace – cljs.test – was released, I could no longer ignore it.

I wrote some tests, I googled for information on how to actually run them, and I hit the wall. Most of the posts were outdated and if it weren’t for Andrew Keedle‘s post on basic cljs.test setup, I’d probably be still banging my head against the wall.

I like open source projects, and I like Travis CI (which is free for open source projects), so the next step was quite obvious:

Set up ClojureScript tests with Travis CI
  1. Add .travis.yml

    clojure lein: lein2 script: lein2 cljsbuild test

  2. Add test command to your project.clj

    clojure :test-commands {"test" ["phantomjs" "phantom/unit-test.js" "phantom/unit-test.html"]}

If you followed Andrew’s post you should have phantom directory in your project already, and unit-test.js and unit-test.html within it.

With this setup you can now either continuously test your project by running lein cljsbuild auto test (tests will be run whenever you save changes to your project) or you can run your tests manually by executing lein cljsbuild test. The latter option will be invoked by Travis.

For a real life, but tiny, example you can go to my is-it-time repository.

I hope this is of help!

Older · View Archive (25)

My first Conj

Thanks to good people at Cognitect and the sponsors of the Opportunity Grant I had an opportunity to speak at Clojure/conj 2014. It was the second time I’ve given a talk, and a fourth tech conference I attended. And it’s been amazing!


Spreading parentheses of love

Last weekend, with the help of 14 teachers and TAs, we brought the first ClojureBridge workshop to London. 20 students that showed up on a day had a wide range of experience levels from total beginners to experienced programmers in other languages.