Fork me on GitHub
#cherry
<
2022-11-04
>
alex15:11:10

👋 What's the story for REPL usage w/ Cherry? Can I spin up an nREPL? Thinking about how I'd go about developing Playwright tests via REPL in Cherry :)

borkdude15:11:19

@rahx1t This isn't yet there. It's the first thing I'm going to work on after further extracting the common code into compiler-common. Squint does have a console REPL at the moment

thanks3 1
alex21:11:09

Is there a p/do or p/let-like macro floating around for use with Cherry? Seeing what's out there before writing my own 🙂

borkdude21:11:57

@rahx1t there isn't currently and there probably won't be one since async/await works in cherry :)

alex21:11:33

I do love await but feel like there's still value in abstracting that away with a macro. Lazy and trying to type as little as possible 🙂 My code atm is await everywhere lol

borkdude21:11:51

haha I see :)

alex21:11:12

(pw-test "auth via sign-in"
         (w/allPagesWrapper
          ^:async
          (fn [^:js {:keys [page context]}]
            (js/await (.goto page index))
            (js/await (wait-for-client-side-rendered page))

            (js/await (.click (.locator page "data-testid=sign-in >> visible=true")))

            (js/await
             (js/Promise.all [(.waitForNavigation page #js {:url "**/groups/new"})
                              (let [[new-page] (js/await
                                                (js/Promise.all [(.waitForEvent context "page")
                                                                 (.click (.locator page "data-testid=sign-in-with-google-button"))]))]
                                (js/await (.waitForLoadState new-page))
                                (js/await (.click (.locator new-page "'Add new account'")))
                                (js/await (.click (.locator new-page "'Auto-generate user information'")))
                                (js/await (.click (.locator new-page "#sign-in"))))]))
            (js/await (wait-for-user-loaded page)))))

alex21:11:37

I haven't audited this to ensure there aren't any unnecessary awaits, but you catch my drift

borkdude21:11:55

you can currently write macros if you have them in file under . or src , e.g. src/my_macros.cljc and then require it with (:require-macros [my-macros :refer [foo]])

alex21:11:34

Great, I'll give that a try

borkdude21:11:57

there is one such example in the nextjournal cherry playwright one

👍 1
alex21:11:12

I recall, yes - with assert right?

borkdude21:11:29

that one yes

borkdude21:11:41

the macros are interpreted with SCI during compilation

borkdude21:11:52

and then the expansion is compiled to JS

blob_thumbs_up 1
alex03:11:01

Nothing fancy but I'm appreciating the quality of life improvement 🙂 The js/await makes async macros soooo much easier to write thanks3

(defmacro do! [& exprs]
  (let [[first-expr & rest-exprs] exprs]
    (reduce
       (fn [acc# next#]
         `(.then ~acc# (fn [_#] ~next#)))
       `(js/Promise. (fn [resolve#] (resolve# ~first-expr)))
       rest-exprs)))

(defmacro do! [& exprs]
  `(do
     ~@(map (fn [expr#] `(js/await ~expr#)) exprs)))

🎉 1
jackrusher14:11:14

await-> coming? 🙂