Last active
August 29, 2015 14:19
-
-
Save bhauman/34a3b258eec521b6e456 to your computer and use it in GitHub Desktop.
figwheel test runner with red/green favicon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:cljsbuild { | |
:builds [{:id "dev" | |
:source-paths ["src" "dev_src"] | |
:compiler {:output-to "resources/public/js/compiled/slides.js" | |
:output-dir "resources/public/js/compiled/out" | |
:optimizations :none | |
:main slides.dev | |
:asset-path "js/compiled/out" | |
:source-map true | |
:source-map-timestamp true | |
:cache-analysis true }} | |
{:id "test" | |
:source-paths ["src" "test"] | |
:compiler {:output-to "resources/public/js/tests/test.js" | |
:output-dir "resources/public/js/tests/out" | |
:optimizations :none | |
:main slides.test-runner | |
:recompile-dependents true | |
:asset-path "js/tests/out" | |
:source-map true | |
:source-map-timestamp true | |
:cache-analysis true }}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<link href="css/style.css" rel="stylesheet" type="text/css"> | |
<!-- a grey favicon --> | |
<link id="favicon" rel="shortcut icon" type="image/png" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAIElEQVQ4T2NMS0v7z0ABYBw1gGE0DBhGwwCYh4ZBOgAAcQUjIUXh8RYAAAAASUVORK5CYII=" /> | |
</head> | |
<body> | |
<script src="js/tests/test.js" type="text/javascript"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns slides.test-runner | |
(:require | |
[cljs.test :as test :include-macros true :refer [report]] | |
[slides.core-test] | |
[figwheel.client :as fw])) | |
(enable-console-print!) | |
(defn color-favicon-data-url [color] | |
(let [cvs (.createElement js/document "canvas")] | |
(set! (.-width cvs) 16) | |
(set! (.-height cvs) 16) | |
(let [ctx (.getContext cvs "2d")] | |
(set! (.-fillStyle ctx) color) | |
(.fillRect ctx 0 0 16 16)) | |
(.toDataURL cvs))) | |
(defn change-favicon-to-color [color] | |
(let [icon (.getElementById js/document "favicon")] | |
(set! (.-href icon) (color-favicon-data-url color)))) | |
(defmethod report [::test/default :summary] [m] | |
(println "\nRan" (:test m) "tests containing" | |
(+ (:pass m) (:fail m) (:error m)) "assertions.") | |
(println (:fail m) "failures," (:error m) "errors.") | |
(if (< 0 (+ (:fail m) (:error m))) | |
(change-favicon-to-color "#d00") | |
(change-favicon-to-color "#0d0"))) ;;<<-- change color | |
(defn runner [] | |
(test/run-tests | |
'slides.core-test)) | |
(fw/start { | |
:websocket-url "ws://localhost:3449/figwheel-ws" | |
;; :autoload false | |
:build-id "test" | |
:on-jsload (fn [] (runner))}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment