This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-08-27
Channels
- # admin-announcements (1)
- # announcements (11)
- # babashka (17)
- # beginners (26)
- # calva (6)
- # cider (2)
- # circleci (1)
- # clojure (41)
- # clojure-dev (1)
- # clojure-europe (31)
- # clojure-france (2)
- # clojure-italy (10)
- # clojure-nl (7)
- # clojure-norway (5)
- # clojure-spec (15)
- # clojure-uk (42)
- # clojurescript (4)
- # code-reviews (12)
- # conjure (10)
- # datalog (2)
- # datascript (15)
- # datomic (37)
- # emacs (1)
- # events (5)
- # fulcro (19)
- # jobs (1)
- # jobs-discuss (9)
- # kaocha (2)
- # luminus (14)
- # meander (4)
- # membrane (39)
- # off-topic (26)
- # other-languages (2)
- # re-frame (13)
- # reitit (6)
- # rewrite-clj (39)
- # sci (6)
- # shadow-cljs (33)
- # test-check (15)
- # vrac (17)
- # xtdb (7)
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.