diff --git a/README.md b/README.md index 097daaa..a2cd2e9 100644 --- a/README.md +++ b/README.md @@ -38,19 +38,32 @@ module.exports = function(config) { // main function args: ['app.test_runner.run'] }, + + // singleRun set to false does not work! + singleRun: true }) } ``` -## Example +## Usage ```clojure (ns app.test-runner - (:require [jx.reporter.karma :refer-macros [run-tests]] + (:require [jx.reporter.karma :refer-macros [run-tests run-all-tests]] [foo.bar-test])) (enable-console-print!) +; runs all tests in all namespaces +(defn ^:export run-all [karma] + (run-all-tests karma)) + +; runs all tests in all namespaces - only namespaces with names matching +; the regular expression will be tested +(defn ^:export run-all-regex [karma] + (run-all-tests karma #".*-test$")) + +; runs all tests in the given namespaces (defn ^:export run [karma] (run-tests karma 'foo.bar-test)) ``` @@ -58,7 +71,7 @@ module.exports = function(config) { To execute tests from command line: ```bash -./node_modules/.bin/karma start karma.conf.js --single-run +./node_modules/.bin/karma start ``` To execute tests from REPL (will use `:cljs.test/default` reporter): diff --git a/src/jx/reporter/karma.clj b/src/jx/reporter/karma.clj index a5a1eeb..3f2717b 100644 --- a/src/jx/reporter/karma.clj +++ b/src/jx/reporter/karma.clj @@ -3,20 +3,27 @@ [cljs.analyzer :as ana] [cljs.analyzer.api :as api])) -(defmacro tests-count [& namespaces] +(defmacro tests-count + [& namespaces] `(+ ~@(map (fn [[quote ns]] (count (filter #(true? (get-in % [1 :test])) (cljs.analyzer.api/ns-publics ns)))) namespaces))) -(defmacro run-tests [karma & namespaces] +(defmacro run-tests + "Runs all tests in the given namespaces." + [karma & namespaces] (if (nil? karma) `(cljs.test/run-tests ~@namespaces) `(do (jx.reporter.karma/start ~karma (tests-count ~@namespaces)) (cljs.test/run-tests (cljs.test/empty-env ::karma) ~@namespaces)))) (defmacro run-all-tests + "Runs all tests in all namespaces. + Optional argument is a regular expression; only namespaces with + names matching the regular expression (with re-matches) will be + tested." ([karma] `(run-all-tests ~karma nil)) ([karma re] (if (nil? karma)