https://github.com/nfisher/lein-nashtest
Run CLJS tests in nashorn using cljs.test report hooks.
https://github.com/nfisher/lein-nashtest
clojurescript lein-plugin leiningen testing
Last synced: 6 months ago
JSON representation
Run CLJS tests in nashorn using cljs.test report hooks.
- Host: GitHub
- URL: https://github.com/nfisher/lein-nashtest
- Owner: nfisher
- License: epl-1.0
- Created: 2017-11-07T06:19:03.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-12-04T16:14:25.000Z (over 7 years ago)
- Last Synced: 2024-08-16T19:17:35.765Z (9 months ago)
- Topics: clojurescript, lein-plugin, leiningen, testing
- Language: Clojure
- Homepage:
- Size: 27.3 KB
- Stars: 9
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lein-nashtest [](https://clojars.org/lein-nashtest)
Run CLJS tests in nashorn using cljs.test report hooks.
## Motivation
nashtest has two primary goals;1. eliminate external dependencies (e.g. node, phantomjs, etc).
2. "clean" instrumentation of cljs.test/no third-party macros (e.g. deftest, defrunner, etc).## Limitations
* 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.
## Requirements
* Java 8.
* Leiningen 2.7.1+.
* lein-cljsbuild 1.1.7+. (whitespace optimised target)## Basic Usage
#### Single Execution
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 nashtestTesting jbx.events-test
Ran 1 tests containing 12 assertions.
0 failures, 0 errors.
```#### Watch Loop Execution
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.jsTesting jbx.events-test
Ran 1 tests containing 12 assertions.
0 failures, 0 errors.
```## Installation
1) Add the plugin to your leiningen `project.clj` file.
```clj
:plugins [[lein-nashtest "0.1.3"]]
```2) Configure your cljsbuild test target in `project.clj`.
```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().3) Create a cljs.test runner.
```clj
(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.
4) Configure nashtest with a root key in `project.clj`.
```clj
:nashtest {:load-js "test.js"
:test-main "jbx.runner/run"}
```## Planned Work
1. ~~Introduce `:test-main` which would use Clojure style references (e.g. `jbx.runner/run`).~~ [#1](https://github.com/nfisher/lein-nashtest/issues/1)
1. ~~File watcher.~~ [#2](https://github.com/nfisher/lein-nashtest/issues/2)
1. ~~Inject cljs.test/report defmethod from runner.~~ [#3](https://github.com/nfisher/lein-nashtest/issues/3)
1. Allow for multiple nashtest ids/targets.
1. JUnit XML output.
1. Naive document.write and to allow an unoptimised CLJS build.