Run Tests using Shadow CLJS

I want to run a simple ClojureScript test, but am getting an error:

$ npx shadow-cljs compile test
shadow-cljs - config: /Users/blah/cljslab/shadow-cljs.edn
[:test] Compiling ...
The required namespace "cljslab.core.actions.building-blocks" is not available, it was required by "cljslab/core/actions/building_blocks_test.cljs".

files:

package.json:

{
  "name": "cljslab",
  "version": "0.0.1",
  "private": true,
  "devDependencies": {
    "shadow-cljs": "2.22.9"
  }
}

shadow-cljs.edn:

;; shadow-cljs configuration
{:source-paths
 ["src/test"
  "src/cljslab"]

 :dependencies
 []

 :builds
 {:cli
  {:target :node-script
   :main cljslab.delivery.cli.cljslab/init
   :output-to "out/cljslab/cljslab.js"}

  :test
  {:target :node-test
   :output-to "out/test/cljslab/cljslab-test.js"
   :autorun true}}}

src/cljslab/core/actions/building_blocks.cljs:

(ns cljslab.core.actions.building-blocks)

(defn action [x] x)

src/test/cljslab/core/actions/building_blocks_test.cljs:

(ns cljslab.core.actions.building-blocks-test
  (:require [cljs.test :refer (deftest is testing)]
            [cljslab.core.actions.building-blocks :refer (action)]))

((deftest name-test
   (testing "Context of the test assertions"
     (is (= 2 (action 1))))))

What is missing?

You have added src/cljslab to :source-paths instead of src. It means that cljslab is not a part of namespaces anymore.

Instead, you should structure your project so that src and test are side by side and both are included in :source-paths.

1 Like

Thank you! This change (and changing the directory structure as you suggested) solved the problem:

{:source-paths
 ["test"
  "src"]
...
  • I do not see a button for “mark as answer” - or similar.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.