|
1 | 1 | (ns stresty.format.report
|
2 | 2 | (:require [stresty.format.core :as fmt]
|
| 3 | + [hiccup.core :as hiccup] |
3 | 4 | [clojure.string :as str]))
|
4 | 5 |
|
| 6 | +(defn report-layout [body] |
| 7 | + [:html |
| 8 | + [:head |
| 9 | + [:meta {:charset "utf-8"}] |
| 10 | + [:meta {:content "width=device-width, initial-scale=1, shrink-to-fit=no" :name "viewport"}] |
| 11 | + [:meta {:content "Stresty test report", :name "description"}] |
| 12 | + [:meta {:content "HealthSamurai", :name "author"}] |
| 13 | + [:title "Stresty test report"] |
| 14 | + [:link {:href "https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" :rel "stylesheet"}]] |
| 15 | + [:body body]]) |
| 16 | + |
5 | 17 | (defmethod fmt/do-format
|
6 | 18 | 'sty/report-fmt
|
7 | 19 | [ztx _ state {tp :type ts :ts :as event}]
|
8 |
| - (cond |
9 |
| - (= tp 'sty/on-tests-start) |
10 |
| - (swap! state assoc :start ts) |
| 20 | + (let [b #(swap! state update :body conj %)] |
| 21 | + (when-not (:body @state) |
| 22 | + (swap! state assoc :body [:div.content])) |
| 23 | + (cond |
| 24 | + (= tp 'sty/on-tests-start) |
| 25 | + (do (swap! state assoc :start ts) |
| 26 | + (b [:div [:b "Start"]])) |
| 27 | + |
| 28 | + (= tp 'sty/on-zen-errors) |
| 29 | + (do |
| 30 | + (println "Syntax errors:") |
| 31 | + (println (str/join "\n" |
| 32 | + (->> |
| 33 | + (:errors event) |
| 34 | + (mapv (fn [{msg :message res :resource pth :path}] |
| 35 | + (str ">> " msg " in " res " at " pth))))))) |
| 36 | + |
| 37 | + (= tp 'sty/on-env-start) |
| 38 | + (print (get-in event [:env :zen/name]) "{") |
| 39 | + |
| 40 | + (= tp 'sty/on-case-start) |
| 41 | + (b [:div [:h2 (or (get-in event [:case :title]) |
| 42 | + (get-in event [:case :zen/name]))]] ) |
| 43 | + |
11 | 44 |
|
12 |
| - (= tp 'sty/on-zen-errors) |
13 |
| - (do |
14 |
| - (println "Syntax errors:") |
15 |
| - (println (str/join "\n" |
16 |
| - (->> |
17 |
| - (:errors event) |
18 |
| - (mapv (fn [{msg :message res :resource pth :path}] |
19 |
| - (str ">> " msg " in " res " at " pth))))))) |
20 | 45 |
|
21 |
| - (= tp 'sty/on-env-start) |
22 |
| - (print (get-in event [:env :zen/name]) "{") |
| 46 | + (= tp 'sty.http/request) |
| 47 | + (b [:div [:b (str tp (:method event) (:url event) (dissoc event :method :url :type :ts))]]) |
23 | 48 |
|
24 |
| - (= tp 'sty/on-case-start) |
25 |
| - (print "(") |
26 | 49 |
|
27 |
| - (= tp 'sty/on-step-start) |
28 |
| - :nop |
| 50 | + (= tp 'sty/on-step-start) |
| 51 | + :nop |
29 | 52 |
|
30 |
| - (tp (set ['sty/on-step-success 'sty/on-match-ok])) |
31 |
| - (print ".") |
| 53 | + (tp (set ['sty/on-step-success 'sty/on-match-ok])) |
| 54 | + (print ".") |
32 | 55 |
|
33 |
| - (tp (set ['sty/on-step-fail 'sty/on-match-fail])) |
34 |
| - (print "x") |
| 56 | + (tp (set ['sty/on-step-fail 'sty/on-match-fail])) |
| 57 | + (print "x") |
35 | 58 |
|
36 |
| - ;;(= tp 'sty/tests-summary) |
37 |
| - ;;(summary ztx) |
| 59 | + (= tp 'sty/tests-summary) |
| 60 | + [:div (fmt/summary ztx)] |
38 | 61 |
|
39 |
| - (= tp 'sty/on-step-exception) |
40 |
| - (print "!") |
| 62 | + (= tp 'sty/on-step-exception) |
| 63 | + (print "!") |
41 | 64 |
|
42 |
| - (= tp 'sty/on-case-end) |
43 |
| - (print ")") |
| 65 | + (= tp 'sty/on-case-end) |
| 66 | + (print ")") |
44 | 67 |
|
45 |
| - (= tp 'sty/on-env-end) |
46 |
| - (print "}\n") |
| 68 | + (= tp 'sty/on-env-end) |
| 69 | + (print "}\n") |
47 | 70 |
|
48 | 71 |
|
49 |
| - (= tp 'sty/tests-done) |
50 |
| - (print "done \n") |
| 72 | + (= tp 'sty/tests-done) |
| 73 | + (do (b [:div [:b "End"]]) |
| 74 | + (spit "output/index.html" (hiccup/html (report-layout (:body @state))))) |
51 | 75 |
|
52 |
| - ) |
| 76 | + )) |
53 | 77 |
|
54 | 78 | )
|
0 commit comments