Fork me on GitHub
#nbb
<
2024-01-29
>
Chris McCormick14:01:40

Hi, I am building some e2e tests using nbb, which involves spawning a server, sending requests to it, and checking the responses. It's working great. I am running the tests with cljs.test like this (t/run-tests 'sitefox.e2etests.nbbauth) and that works fine. I would like to generate a report at the end so I am following the instructions on https://clojurescript.org/tools/testing#detecting-test-completion-success but creating this method doesn't seem to do anything. Am I doing something wrong or is this an nbb issue?

(deftest basic-site-test
  (t/testing "Basic test of Sitefox on nbb."
    (async done
           (p/let [server (run-server "examples/nbb" "npm i --no-save; npm run serve" 8000)
                   res (js/fetch "")
                   text (.text res)]
             (is (j/get-in server [:process :pid]) "Server is running?")
             (is (j/get server :open) "Server port is open?")
             (is (j/get res :ok) "Was server response ok?")
             (is (includes? text "Hello") "Server response includes 'Hello' text?")
             (log "Test done. Killing server.")
             (j/call server :kill)))))

(defmethod cljs.test/report [:cljs.test/default :end-run-tests] [m]
  (log "Generating test report.")
  (if (cljs.test/successful? m)
    (println "Success!")
    (println "FAIL")))

(t/run-tests 'sitefox.e2etests.nbbauth)
Let me know if there is any further info I can provide. Thanks!

Chris McCormick14:01:23

Just to clarify "doesn't do anything" - I don't see the output "Generating test report." so it seems the method is not getting called.

borkdude14:01:22

Can you test if any of the other methods are called?

borkdude14:01:04

This seems to work:

$ ./cli.js -e "(require '[cljs.test :as t]) (t/deftest foo (prn :hello)) (defmethod t/report [:cljs.test/default :end-run-tests] [_] (prn :end)) (t/run-tests *ns*)"

Testing user
:hello

Ran 1 tests containing 0 assertions.
0 failures, 0 errors.
:end: 

borkdude14:01:23

if you have a minimal counter-repro, happy to look

Chris McCormick15:01:27

Thank you will investigate further.

Chris McCormick15:01:15

PEBCAK. I forgot to call (done) on the async test. Working now, thanks.

cldwalker16:01:56

Hi. Has anyone tried using rewrite-edn with nbb? When I try requiring borkdude-write.edn, I get an exception Could not resolve symbol: IWithMeta which is coming from https://github.com/clj-commons/rewrite-clj/blob/main/src/rewrite_clj/interop.cljc. I can try to patch nbb’s implements? but figured I’d ask in case there are other reasons why rewrite wouldn’t work with nbb

borkdude16:01:54

It does work with bb but only because bb includes rewrite-clj

cldwalker17:01:04

Gotcha. Would you be interested in a contribution to similarly include it with nbb?

borkdude17:01:44

yeah I'd be fine with that

borkdude17:01:39

joyride has it here: https://github.com/BetterThanTomorrow/joyride/blob/02660dba6f476f79ae2bc4abc21aa2825a8c90d9/src/joyride/sci.cljs#L91 we could move that config to sci.configs and then use that from nbb

borkdude17:01:11

also, if you're just interested in logseq-nbb having this, you can do that without changing nbb

cldwalker17:01:20

True. When I get to this I’ll timebox contributing joyride’s config upstream but if I exceed it I’ll fallback to logseq-nbb

borkdude17:01:08

upstreaming the config to sci.configs should directly benefit logseq-nbb as well righ

borkdude17:01:11

so why timebox it

borkdude17:01:22

anyway, do what you need to do 👍