kaocha

Official support channel: https://clojureverse.org/c/projects/kaocha
plexus 2020-08-27T10:22:16.152300Z

an example of how to set up kaocha-cljs2 with shadow and node in a fully self-contained way, this is how I set things up at the moment for nextjournal. - Add the funnel wrapper script to your repo (https://github.com/lambdaisland/funnel/blob/master/bin/funnel_wrapper) this auto downloads funnel if it's not present yet. - Create a hooks file for orchestration,

(ns com.nextjournal.test.kaocha-hooks
  (:require [clojure.java.shell :as sh]
            [shadow.cljs.devtools.api :as shadow-api]
            [shadow.cljs.devtools.server.runtime :as shadow-runtime]
            [shadow.cljs.devtools.server :as shadow-server]))

(defn spawn
  "Start a process, connecting its stdout/stderr to the parent so we see what's
  going on. Returns the Process object so you can call .pid, .destroy,
  .destroyForcibly."
  [& args]
  (.start (doto (ProcessBuilder. args)
            (.inheritIO))))

(defn ensure-funnel [& args]
  ;; If funnel is already running then this is a no-op
  (sh/sh "bin/funnel" "-vv" "--daemonize")
  (first args))

(defn ensure-shadow-instance [& args]
  (when (nil? @shadow-runtime/instance-ref)
    (shadow-server/start!)
    (loop []
      (Thread/sleep 250)
      (when (nil? @shadow-runtime/instance-ref)
        (recur))))
  (first args))

(defn shadow-dev-build [testable config]
  (shadow-api/compile (:shadow/build testable))
  testable)

(defn shadow-release-build [testable config]
  (shadow-api/release (:shadow/build testable))
  testable)

(defn start-node [testable config]
  (assoc testable ::node-process (spawn "node" (:node/main-js testable))))

(defn kill-node [testable config]
  (.destroyForcibly (::node-process testable))
  testable)
- Set up your shadow-cljs build
{:target :node-test
   :output-to "out/node-tests.js"
   :main kaocha.cljs2.shadow-runner/start
   :closure-defines {goog.debug.LOGGING_ENABLED false}
   :namespaces
   [com.nextjournal.tests.browser.article-test
    com.nextjournal.tests.devcards.editor.article.article-view-test]}
- Set up your test suite
{:id :node
             :type :kaocha.type/cljs2
             :node/main-js "out/node-tests.js"
             :shadow/build :id-of-shadow-build
             :kaocha.hooks/pre-load-test [com.nextjournal.test.kaocha-hooks/ensure-funnel
                                          com.nextjournal.test.kaocha-hooks/ensure-shadow-instance
                                          com.nextjournal.test.kaocha-hooks/shadow-dev-build
                                          com.nextjournal.test.kaocha-hooks/start-node]
             :kaocha.hooks/post-test [com.nextjournal.test.kaocha-hooks/kill-node]}
Now you can do bin/kaocha node and it will invoke shadow for the compilation, boot up node, run the tests (via chui-remote/funnel), and kill the node process when it's done.

plexus 2020-08-27T10:28:32.153200Z

Also a heads-up, I'm going to be largely offline the next ~12 days. Please help each other out in my absence 🙏:skin-tone-2:

👍 4