Fork me on GitHub
#nbb
<
2022-06-14
>
martinklepsch10:06:13

Hey hey 🙂 Could someone explain how await is a thing in nbb? Is that something that only exists in nbb? IIRC it doesn’t exist in CLJS itself so curious to learn more. Tried searching the docs but couldn’t find any more info 🙂

borkdude10:06:15

@martinklepsch It's a special op in nbb which is only possible if you evaluate expressions in a chained promise from top to bottom, which is not how the CLJS compiler compiles things

martinklepsch10:06:05

Interesting! It’s quite handy in the REPL I have to say!

borkdude10:06:30

it's exactly made for that :)

💯 1
martinklepsch11:06:20

Does someone have pointers on making t/is somewhat promise aware? We’re exploring using playwright with nbb more and noticed that code like this will always be passing since the promise returned by isVisible is truthy https://github.com/nextjournal/clerk/blob/29c5b31aef09a03a8b2d861ab34e9efa811e5501/ui_tests/playwright_tests.cljs#L69-L70

borkdude11:06:04

@martinklepsch I'd use p/let - thanks for spotting that

borkdude11:06:48

(p/let [visible? ... _ (is visible?)])

martinklepsch11:06:05

yeah that’ll work but also requires that the binding name is very descriptive. It’d be great if the playwright isVisible and locator would be part of the form that is reported by cljs.test

borkdude11:06:55

I've missed you at ClojureD btw!

❤️ 1
borkdude11:06:28

@martinklepsch since nbb supports macros, you might be able to write some macro stuff around this

martinklepsch11:06:04

Yeah I’m kind of realizing that but I’m too incompetent to be honest hahahahah

martinklepsch11:06:36

I’d have loved to come but had already made some other plans a while ago, next year again! Seemed like everyone had a blast though :hugging_face:

borkdude11:06:24

@martinklepsch FYI, Playwright also has Java bindings now, maybe it's easier for you to do it from Clojure JVM

borkdude11:06:54

There's also #etaoin (webdriver) which now works with #babashka

martinklepsch11:06:46

We’re 100% in JS-land so getting into JVM stuff doesn’t seem quite right

borkdude11:06:09

makes total sense. I'll try to whip up some macro

borkdude12:06:45

A macro:

(ns foo (:require [cljs.test]
                  [promesa.core :as p]))

(defmacro isp [form & [msg]]
  (let [[pred expected promise] form]
    `(promesa.core/let [~'result ~promise]
       (cljs.test/is (~pred ~expected ~'result) ~msg))))

(cljs.test/deftest foo
  (cljs.test/async
   done
   (p/do (isp (= :hello (p/delay 1000 :hellox)) "o noes")
         (done))))

(cljs.test/run-tests 'foo)
$ nbb /tmp/foo.cljs

FAIL in () (/tmp/foo.cljs:)
o noes
expected: (= :hello result)
  actual: (not (= :hello :hellox))
@martinklepsch ^

martinklepsch16:06:52

Thanks! that was actually super helpful! We kind of wanted the (p/delay 1000 :hellox) to show up in the expected/actual block but I think that’s a bit more tricky to achieve. Instead we’re now passing the stringified form as the msg argument to isp which means it’ll get printed right above the expected line — good enough!

🎉 1