Skip to content

Commit

Permalink
dev: include test context when running tests (#630)
Browse files Browse the repository at this point in the history
* dev: include test context when running tests

This should help especially with test-doc, but seems like a good thing
to report in general.

Closes #628

* address lint error, thanks clj-kondo!

* test: with context reported, printlns can go

* Windows does not like the bullet char

Switch to period char.
  • Loading branch information
lread authored Aug 17, 2024
1 parent 399436c commit b8d8d0e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
3 changes: 1 addition & 2 deletions test/etaoin/api_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@
(e/wait-visible driver {:id :document-end})
(binding [*driver* driver
test-report/*context* (name type)]
(testing (name type)
(f)))))))
(f))))))

(use-fixtures
:each
Expand Down
7 changes: 0 additions & 7 deletions test/etaoin/api_with_driver_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@
(let [test-page (api-test/test-server-url "test.html")]
(when (testing-driver? :chrome)
(testing "chrome"
(println "testing chrome")
;; with opts
(is (= my-agent
(e/with-driver :chrome {:user-agent my-agent} driver
Expand Down Expand Up @@ -186,7 +185,6 @@

(when (testing-driver? :firefox)
(testing "firefox"
(println "testing firefox")
;; with opts
(is (= my-agent
(e/with-driver :firefox {:user-agent my-agent} driver
Expand Down Expand Up @@ -244,7 +242,6 @@

(when (testing-driver? :edge)
(testing "edge"
(println "testing edge")
;; with opts
(is (= my-agent
(e/with-driver :edge {:user-agent my-agent} driver
Expand Down Expand Up @@ -302,7 +299,6 @@

(when (testing-driver? :safari)
(testing "safari"
(println "testing safari")
;; with opts
;; safari driver does supports neither user agent nor headless
;; not sure what other safari option is reflected in session... port?
Expand Down Expand Up @@ -344,23 +340,20 @@
(let [test-page (api-test/test-server-url "test.html")]
(when (testing-driver? :chrome)
(testing "chrome"
(println "testing chrome")
(util/with-tmp-file "chromedriver" ".log" path
;; chromedriver logs to stderr
(e/with-chrome {:driver-log-level "DEBUG" :log-stderr path} driver
(e/go driver test-page)
(is (re-find #"\[DEBUG\]:" (slurp path)))))))
(when (testing-driver? :edge)
(testing "edge"
(println "testing edge")
(util/with-tmp-file "edgedriver" ".log" path
;; edgedriver logs to stderr
(e/with-edge {:driver-log-level "DEBUG" :log-stderr path} driver
(e/go driver test-page)
(is (re-find #"\[DEBUG\]:" (slurp path)))))))
(when (testing-driver? :firefox)
(testing "firefox"
(println "testing firefox")
(util/with-tmp-file "firefoxdriver" ".log" path
;; geckodriver logs to stdout
(e/with-firefox {:driver-log-level "debug" :log-stdout path} driver
Expand Down
5 changes: 2 additions & 3 deletions test/etaoin/ide_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(:require
[clojure.edn :as edn]
[clojure.java.io :as io]
[clojure.test :refer [deftest testing use-fixtures]]
[clojure.test :refer [deftest use-fixtures]]
[etaoin.api :as e]
[etaoin.ide.flow :as ide]
[etaoin.test-report :as test-report]))
Expand Down Expand Up @@ -37,8 +37,7 @@
*base-url* base-url
*test-file-path* test-file-path
test-report/*context* (name type)]
(testing (name type)
(f)))))))
(f))))))

(use-fixtures
:each
Expand Down
18 changes: 17 additions & 1 deletion test/etaoin/test_report.clj
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
(ns etaoin.test-report
(:require [clojure.test]))
(:require [clojure.test :as t]))

(def ^:dynamic *context* nil)

(defmacro testing-with-report
"Replacement for clojure.testing macro that hooks into reporting"
[string & body]
`(let [context# ~string]
(binding [t/*testing-contexts* (conj t/*testing-contexts* context#)]
(t/do-report {:type :begin-testing :testing-contexts t/*testing-contexts*})
~@body)))

;; Replace the clojure.test/testing macro with our custom one
(alter-var-root #'t/testing (constantly #'testing-with-report))

(def platform
(if (System/getProperty "babashka.version") "bb" "jvm"))

Expand All @@ -11,3 +22,8 @@
(if *context*
(println (format "=== %s [%s][%s]" test-name platform *context*))
(println (format "=== %s [%s]" test-name platform)))))

(defmethod clojure.test/report :begin-testing [{:keys [testing-contexts]}]
(println (format "...%s %s"
(apply str (repeat (count testing-contexts) "."))
(first testing-contexts))))

0 comments on commit b8d8d0e

Please sign in to comment.