项目作者: nfisher

项目描述 :
Run CLJS tests in nashorn using cljs.test report hooks.
高级语言: Clojure
项目地址: git://github.com/nfisher/lein-nashtest.git
创建时间: 2017-11-07T06:19:03Z
项目社区:https://github.com/nfisher/lein-nashtest

开源协议:Eclipse Public License 1.0

下载


lein-nashtest Clojars Project

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.

  1. $ lein nashtest
  2. Testing jbx.events-test
  3. Ran 1 tests containing 12 assertions.
  4. 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.

  1. $ lein nashtest watch
  2. Watching for changes to test.js
  3. Testing jbx.events-test
  4. Ran 1 tests containing 12 assertions.
  5. 0 failures, 0 errors.

Installation

1) Add the plugin to your leiningen project.clj file.

  1. :plugins [[lein-nashtest "0.1.3"]]

2) Configure your cljsbuild test target in project.clj.

  1. :cljsbuild [{:id "test"
  2. :source-paths ["src/cljs" "src/cljc" "test/cljs"]
  3. :figwheel true
  4. :compiler {:language-in :ecmascript5-strict
  5. :language-out :ecmascript5-strict
  6. :optimizations :whitespace
  7. :main jbx.runner
  8. :asset-path "js/test"
  9. :output-to "target/cljsbuild/public/js/test.js"
  10. :cache-analysis true}]

Note: Whitespace optimisation is required because document.write().

3) Create a cljs.test runner.

  1. (ns jbx.runner
  2. (:require
  3. [cljs.test :as t :include-macros true]
  4. [jbx.events-test]))
  5. (defn ^:export run
  6. []
  7. (enable-console-print!)
  8. (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.

  1. :nashtest {:load-js "test.js"
  2. :test-main "jbx.runner/run"}

Planned Work

  1. Introduce :test-main which would use Clojure style references (e.g. jbx.runner/run). #1
  2. File watcher. #2
  3. Inject cljs.test/report defmethod from runner. #3
  4. Allow for multiple nashtest ids/targets.
  5. JUnit XML output.
  6. Naive document.write and