Running ClojureScript tests with Karma
This repository demonstrates how to use Karma to run ClojureScript tests in Chrome with JUnit output and slow test reporting.
First of all, if doo fits your needs, by all means use it. Doo can run Karma just fine. The trouble is that you can't really configure Karma with doo. Here are some reasons for why I've wanted to configure Karma:
- I wanted to get JUnit output for the tests.
Luckily it's straightforward to use Karma directly!
How to build and run the tests
Start the Karma server:
npm install ./node_modules/karma-cli/bin/karma start
In another terminal, start cljsbuild:
lein cljsbuild auto
Now go and edit some of the
.cljs files. The tests should be automatically
run. You can also manually start a test run with
./trigger-karma.sh. The JUnit
files are under
How does this work?
package.jsonlists the Karma components we need to install from npm.
karma_demo/runner.cljsis our test runner namespace. It requires all the test namespaces and calls
project.cljconfigures cljsbuild to compile the test runner.
I've included some comments into the files to draw attention to the interesting parts.
We do not use Karma's autowatch feature, because it tends to re-run the tests
while cljsbuild is still compiling them. Instead we set cljsbuild's
:notify-command to trigger the tests when the build is ready. I've tried to
autoWatchBatchDelay option, but it's hard to get right.