Skip to content

Commit

Permalink
improve documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
honzabrecka committed Dec 20, 2015
1 parent 7341219 commit 945cac9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,40 @@ 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))
```

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):
Expand Down
11 changes: 9 additions & 2 deletions src/jx/reporter/karma.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 945cac9

Please sign in to comment.