Skip to content

Instantly share code, notes, and snippets.

@plexus
Forked from rgm/kaocha_notifier.clj
Created January 18, 2019 06:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plexus/e5befecc5b3f950d67944dd63401c580 to your computer and use it in GitHub Desktop.
Save plexus/e5befecc5b3f950d67944dd63401c580 to your computer and use it in GitHub Desktop.
{:paths ["."]}
(ns rgm.kaocha-notifier
(:require [clojure.java.shell :refer [sh]]
[kaocha.plugin :refer [defplugin]]
[kaocha.result :as result]))
;; special thanks for terminal-notify stuff to
;; https://github.com/glittershark/midje-notifier/blob/master/src/midje/notifier.clj
(defmacro exists?
[program]
`(= 0 (:exit (sh "which" ~program))))
(defonce notification-type
(cond
(exists? "notify-send") :notify-send
(exists? "terminal-notifier") :terminal-notifier))
(def app-icon
"https://upload.wikimedia.org/wikipedia/commons/thumb/5/5d/Clojure_logo.svg/200px-Clojure_logo.svg.png")
(defmacro notify-send
[title body]
(case notification-type
:notify-send `(sh "notify-send" ~title ~body)
:terminal-notifier `(sh "terminal-notifier"
"-message" ~body
"-title" ~title
"-appIcon" app-icon)))
(defplugin rgm/kaocha-notifier
"kaocha post-run hook that sends a thumbs-up or thumbs-down notification
on the whole suite, so a `kaocha --watch` terminal process can be hidden
and generally ignored until it goes red.
Requires https://github.com/julienXX/terminal-notifier on mac
or `libnotify` on linux."
(post-run [result]
(let [{:keys [kaocha.result/pass
kaocha.result/fail
kaocha.result/error] :as summary}
(result/testable-totals result)]
(if (result/failed? summary)
(let [total-fails (+ fail error)
message (str total-fails
(if (= 1 total-fails) " assertion " " assertions ")
"failed, " pass " succeeded")]
(notify-send "⛔️ Failing" message))
(let [message (str pass
(if (= 1 pass) " assertion " " assertions ")
"succeeded")]
(notify-send "✅ Passing" message))))
result))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment