# Kaocha-cljs not seeing test cases

**URL:** https://clojureverse.org/t/kaocha-cljs-not-seeing-test-cases/4537
**Category:** Kaocha
**Created:** [July 14, 2019, 8:23pm UTC](https://clojureverse.org/t/kaocha-cljs-not-seeing-test-cases/4537 "2019-07-14T20:23:31Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![jkrasnay](https://clojureverse.org/user_avatar/clojureverse.org/jkrasnay/32/2212_2.png) [@jkrasnay](https://clojureverse.org/u/jkrasnay)
#### Post date: [July 14, 2019, 8:23pm UTC](https://clojureverse.org/t/kaocha-cljs-not-seeing-test-cases/4537/1 "2019-07-14T20:23:31Z")

</div>

Hi,  
I’m having trouble getting kaocha-cljs working. My `tests.edn` is as follows:

```
﻿#kaocha/v1
{:tests [{:id :unit
          :source-paths ["src/main/clj"]
          :test-paths ["src/test/clj"]}
         {:id :unit-cljs
          :type :kaocha.type/cljs
          :cljs/repl-env cljs.repl.browser/repl-env
          :source-paths ["src/main/clj"]
          :test-paths ["src/test/clj"]}]}

```

I have only a single file in my source tree, `src/test/clj/my_ns/core_test.cljc`:

```
(ns my-ns.core-test
  (:require
    [clojure.test :refer [deftest is]]))

(deftest basic-test
  (is (= 1 1)))

```

I’m using Leiningen configured as per the docs. Running `lein kaocha unit` works fine. I get a single test run successfully. But running `lein kaocha unit-cljs` produces an exception:

```
No such namespace: my-ns.core-test, could not locate my_ns/core_test.cljs, my_ns/core_test.cljc, or...

```

Any thoughts on what might be going wrong?

---

<div class="post-metadata">

### Author: ![plexus](https://clojureverse.org/user_avatar/clojureverse.org/plexus/32/6_2.png) [@plexus](https://clojureverse.org/u/plexus)
#### Post date: [July 15, 2019, 7:11am UTC](https://clojureverse.org/t/kaocha-cljs-not-seeing-test-cases/4537/2 "2019-07-15T07:11:44Z")

</div>

Kaocha is not able to dynamically add directories to the classpath in such a way that ClojureScript “sees” them, so I’m your project.clj you’ll have to add `src/test/clj` to :test-paths or :source-paths.

---

<div class="post-metadata">

### Author: ![jkrasnay](https://clojureverse.org/user_avatar/clojureverse.org/jkrasnay/32/2212_2.png) [@jkrasnay](https://clojureverse.org/u/jkrasnay)
#### Post date: [July 15, 2019, 11:27am UTC](https://clojureverse.org/t/kaocha-cljs-not-seeing-test-cases/4537/3 "2019-07-15T11:27:49Z")

</div>

Ah, I see, thanks. It does seem weird that CLJS needs source directories on the classpath, especially when CLJ doesn’t. I guess I still have more to learn about how the CLJS compiler works.

On to my second question. My `:unit-cljs` test now works, but if I add `:focus [my-ns.core-test]` to the `:unit-cljs` clause Kaocha does not run the test. The `:unit` test works fine with or without the same `:focus` setting. Any thoughts on this one?

---

<div class="post-metadata">

### Author: ![plexus](https://clojureverse.org/user_avatar/clojureverse.org/plexus/32/6_2.png) [@plexus](https://clojureverse.org/u/plexus)
#### Post date: [July 15, 2019, 11:55am UTC](https://clojureverse.org/t/kaocha-cljs-not-seeing-test-cases/4537/4 "2019-07-15T11:55:25Z")

</div>

ClojureScript test ids are prefixed to distinguish them from CLJ test ids. Try this

```auto
bin/kaocha --plugin kaocha.plugin.alpha/info --print-test-ids 

```

This will show you all the identifiers of the tests you have.

> [@jkrasnay](#):
>
> Ah, I see, thanks. It does seem weird that CLJS needs source directories on the classpath, especially when CLJ doesn’t. I guess I still have more to learn about how the CLJS compiler works.

This is a shortcoming of kaocha-cljs. We add the directories you put in `tests.edn` to the classpath at runtime, but somehow ClojureScript doesn’t pick that up. I haven’t had a chance to look into that, I’m sure it’s fixable, but someone needs to investigate how exactly ClojureScript does its lookup. It might be looking at a different `ClassLoader` than the one we’re modifying.

---

<div class="post-metadata">

### Author: ![jkrasnay](https://clojureverse.org/user_avatar/clojureverse.org/jkrasnay/32/2212_2.png) [@jkrasnay](https://clojureverse.org/u/jkrasnay)
#### Post date: [July 15, 2019, 12:15pm UTC](https://clojureverse.org/t/kaocha-cljs-not-seeing-test-cases/4537/5 "2019-07-15T12:15:16Z")

</div>

Perfect. Changing it to `:focus [cljs:my-ns/core-test]` does the trick.

One last question, though not directly to do with Kaocha. Running my CLJS unit tests with a Node back-end fails when it runs across something that touches a browser API, e.g. the DOM or xmlhttprequest. I think I can fix that by installing `global-jsdom` with npm and running something like `(js/require "global-jsdom")` before my tests. Would a pre-load hook be the best place to run that code?

---

<div class="post-metadata">

### Author: ![plexus](https://clojureverse.org/user_avatar/clojureverse.org/plexus/32/6_2.png) [@plexus](https://clojureverse.org/u/plexus)
#### Post date: [July 15, 2019, 1:04pm UTC](https://clojureverse.org/t/kaocha-cljs-not-seeing-test-cases/4537/6 "2019-07-15T13:04:59Z")

</div>

No, that won’t work as the JS environment won’t be spun up yet by that time.

You could try doing it with a `pre-test`. This will run before every suite/ns/test. As soon as you have a `:kaocha.type.cljs/eval` key in your testable you can try using that to eval clojurescript

Something like this (completely untested)

```clojure
(defn pre-test-hook [testable test-plan]
  (when-let [eval (:kaocha.type.cljs/eval] ;; maybe add some global state to do this only the first time
    (eval '(js/require "global-jsdom"))
  testable)

```

That said if your tests heavily rely on the DOM you probably should run them against a (headless) browser rather than Node.

---

<div class="post-metadata">

### Author: ![jkrasnay](https://clojureverse.org/user_avatar/clojureverse.org/jkrasnay/32/2212_2.png) [@jkrasnay](https://clojureverse.org/u/jkrasnay)
#### Post date: [July 15, 2019, 1:22pm UTC](https://clojureverse.org/t/kaocha-cljs-not-seeing-test-cases/4537/7 "2019-07-15T13:22:34Z")

</div>

Yeah, I suppose you’re right. A headless browser would be better. As far as I could see, Kaocha just uses CLJS to start the REPL, which in turn just uses the default configured browser for the system. Is there a way to configure this?

---

<div class="post-metadata">

### Author: ![plexus](https://clojureverse.org/user_avatar/clojureverse.org/plexus/32/6_2.png) [@plexus](https://clojureverse.org/u/plexus)
#### Post date: [July 15, 2019, 1:54pm UTC](https://clojureverse.org/t/kaocha-cljs-not-seeing-test-cases/4537/8 "2019-07-15T13:54:52Z")

</div>

Not really… this uses `clojure.java.browse` under the hood, which uses `xdg-open` (or on mac: `/usr/bin/open`), which then uses your system default.

Seems like there’s a dynamic binding you can set (`*open-url-script*`), but it expects an atom, which you can’t readily do with Kaocha’s `:bindings` because it doesn’t eval its values.

You can try binding it inside a `wrap-run` hook though, that should work.

Something like this (again, untested)

```auto
(defn wrap-run-hook [run test-plan]
  (fn [& args]
    (binding [clojure.java.browse/*open-url-script* (atom "/path/to/your/browser")]
      (apply run args))))

```

See [https://github.com/clojure/clojure/blob/ef00c7cffad10e6104d333f7f71a29163b06cd0a/src/clj/clojure/java/browse.clj#L66](https://github.com/clojure/clojure/blob/ef00c7cffad10e6104d333f7f71a29163b06cd0a/src/clj/clojure/java/browse.clj#L66)

---

<div class="post-metadata">

### Author: ![jkrasnay](https://clojureverse.org/user_avatar/clojureverse.org/jkrasnay/32/2212_2.png) [@jkrasnay](https://clojureverse.org/u/jkrasnay)
#### Post date: [July 15, 2019, 10:49pm UTC](https://clojureverse.org/t/kaocha-cljs-not-seeing-test-cases/4537/9 "2019-07-15T22:49:15Z")

</div>

OK, I’ll give that a try. Thanks for your help and thanks for building Kaocha!
