Skip to content

Commit 9e765a4

Browse files
committed
Html formatter do output
1 parent 7d3e761 commit 9e765a4

File tree

5 files changed

+62
-36
lines changed

5 files changed

+62
-36
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
target
22
.cpcache
3+
output/*
34
core
45
classes
56
pom.xml

src/stresty/core.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
(prn "---------------------------------------------")
3838
(-main "--path=/Users/aitem/Work/HS/ssty/t" "--format=stdout" "--ns=rmis" "tests")
3939
(prn "---------------------------------------------")
40-
(def p (-main "--path=/Users/aitem/Work/HS/ssty/t" "--format=report" "--ns=rmis" "tests"))
40+
(def p (-main "--path=/Users/aitem/Work/HS/ssty/t" "--format=report" "--output=output" "--ns=rmis" "tests"))
4141
))
4242

4343
(def ctx (-main "server" "--port=8888"))

src/stresty/format/core.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
(merge-with concat acc)))
2323
{} (:result @ztx))]
2424

25-
(println "\nSummary:"
25+
(str "\nSummary:"
2626
(count cases) "cases,"
2727
steps "steps,"
2828
(count (:error res)) "error,"
@@ -109,7 +109,7 @@
109109

110110

111111
(= tp 'sty/tests-summary)
112-
(summary ztx)
112+
(println (summary ztx))
113113

114114

115115
(= tp 'sty.http/request)

src/stresty/format/report.clj

Lines changed: 56 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,78 @@
11
(ns stresty.format.report
22
(:require [stresty.format.core :as fmt]
3+
[hiccup.core :as hiccup]
34
[clojure.string :as str]))
45

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+
517
(defmethod fmt/do-format
618
'sty/report-fmt
719
[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+
1144

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)))))))
2045

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))]])
2348

24-
(= tp 'sty/on-case-start)
25-
(print "(")
2649

27-
(= tp 'sty/on-step-start)
28-
:nop
50+
(= tp 'sty/on-step-start)
51+
:nop
2952

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 ".")
3255

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")
3558

36-
;;(= tp 'sty/tests-summary)
37-
;;(summary ztx)
59+
(= tp 'sty/tests-summary)
60+
[:div (fmt/summary ztx)]
3861

39-
(= tp 'sty/on-step-exception)
40-
(print "!")
62+
(= tp 'sty/on-step-exception)
63+
(print "!")
4164

42-
(= tp 'sty/on-case-end)
43-
(print ")")
65+
(= tp 'sty/on-case-end)
66+
(print ")")
4467

45-
(= tp 'sty/on-env-end)
46-
(print "}\n")
68+
(= tp 'sty/on-env-end)
69+
(print "}\n")
4770

4871

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)))))
5175

52-
)
76+
))
5377

5478
)

src/stresty/operations/core.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@
102102
(fmt/emit ztx {:type 'sty/on-env-end :env env}))
103103

104104
(defmethod call-op 'sty/run-tests
105-
[ztx op {params :params}]
105+
[ztx op {params :params :as p}]
106+
(fmt/emit ztx {:type 'sty/on-tests-start})
106107
(doseq [env-ref (zen/get-tag ztx 'sty/env)]
107108
(let [env (zen/get-symbol ztx env-ref)]
108109
(run-env ztx env)))

0 commit comments

Comments
 (0)