Run CLJS tests in nashorn using cljs.test report hooks.
nashtest has two primary goals;
- eliminate external dependencies (e.g. node, phantomjs, etc).
- "clean" instrumentation of cljs.test/no third-party macros (e.g. deftest, defrunner, etc).
- ECMAScript support is limited to Nashorns capabilities.
- DOM support is not available (e.g. document.* is absent).
- XMLHTTPRequest is not available.
- Timers are not available.
- Optimal target is ECMAScript 5.1.
Happy to accept PR's if people want to provide shims.
- Java 8.
- Leiningen 2.7.1+.
- lein-cljsbuild 1.1.7+. (whitespace optimised target)
Single execution is intended for use in CI or as a precommit verification. If there are test failures the exit code will be 1, if all is green it will be 0.
$ lein nashtest
Testing jbx.events-test
Ran 1 tests containing 12 assertions.
0 failures, 0 errors.
Watch loop execution is intended for continuous feedback during development. A change to the :load-js file will result in automatic execution of the whole test suite.
$ lein nashtest watch
Watching for changes to test.js
Testing jbx.events-test
Ran 1 tests containing 12 assertions.
0 failures, 0 errors.
- Add the plugin to your leiningen
project.clj
file.
:plugins [[lein-nashtest "0.1.3"]]
- Configure your cljsbuild test target in
project.clj
.
:cljsbuild [{:id "test"
:source-paths ["src/cljs" "src/cljc" "test/cljs"]
:figwheel true
:compiler {:language-in :ecmascript5-strict
:language-out :ecmascript5-strict
:optimizations :whitespace
:main jbx.runner
:asset-path "js/test"
:output-to "target/cljsbuild/public/js/test.js"
:cache-analysis true}]
Note: Whitespace optimisation is required because document.write().
- Create a cljs.test runner.
(ns jbx.runner
(:require
[cljs.test :as t :include-macros true]
[jbx.events-test]))
(defn ^:export run
[]
(enable-console-print!)
(t/run-all-tests #"jbx.*-test"))
Note: nashtest uses :test-main or :runner and will call your exported function as part of the test cycle. Do not include a call to the function at the bottom of your runner file.
- Configure nashtest with a root key in
project.clj
.
:nashtest {:load-js "test.js"
:test-main "jbx.runner/run"}