Skip to content

Instantly share code, notes, and snippets.

@henryw374
Last active July 14, 2023 10:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henryw374/6ba4359f540412baae4510d790fcf273 to your computer and use it in GitHub Desktop.
Save henryw374/6ba4359f540412baae4510d790fcf273 to your computer and use it in GitHub Desktop.
(ns com.widdindustries.kaocha-cljs2-ns-pattern-hook
"the only way I can find to filter kaocha-cljs2 tests by pattern. see comment block for usage"
(:require [kaocha.core-ext :as core-ext]
[kaocha.load :as load]))
(defn ns-filter [plan]
;(def plan plan)
;(println "About to start loading!")
(update plan :kaocha.test-plan/tests
(fn [tests]
(->> tests
(mapv (fn [testable]
(if (not= :kaocha.type/cljs2 (:kaocha.testable/type testable))
testable
(if-let [ns-patterns (some->> testable
:kaocha/ns-patterns
(mapv core-ext/regex))]
;(def testable testable)
(update testable :kaocha.test-plan/tests
(fn [tests]
(->> tests
(map (fn client-type [client-testable]
(update client-testable
:kaocha.test-plan/tests
(fn ns-tests [ns-testables]
(->> ns-testables
(filter (fn [ns-testable]
(load/ns-match? ns-patterns (:kaocha.testable/name ns-testable))))))))))))
testable))))))
))
(comment
; example tests.edn content
; #kaocha/v1
; {:plugins [:hooks]
; :kaocha.hooks/post-load [com.widdindustries.kaocha-cljs2-ns-pattern-hook/ns-filter]
; :tests [{:id :browser-tests
; :type :kaocha.type/cljs2
; :kaocha.cljs2/timeout 30000
; :ns-patterns ["demo-app"]}]}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment