cherry

alex 2022-11-04T15:35:10.275779Z

👋 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 :)

borkdude 2022-11-04T15:37:19.266499Z

@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

1
alex 2022-11-04T21:05:09.542649Z

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 🙂

borkdude 2022-11-04T21:07:57.408689Z

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

alex 2022-11-04T21:09:33.494709Z

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

borkdude 2022-11-04T21:09:51.032709Z

haha I see :)

alex 2022-11-04T21:10:12.450809Z

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

alex 2022-11-04T21:10:37.669759Z

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

borkdude 2022-11-04T21:10:55.491949Z

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

alex 2022-11-04T21:11:34.041569Z

Great, I'll give that a try

borkdude 2022-11-04T21:11:57.056929Z

there is one such example in the nextjournal cherry playwright one

👍 1
alex 2022-11-04T21:12:12.375069Z

I recall, yes - with assert right?

borkdude 2022-11-04T21:12:29.765749Z

that one yes

borkdude 2022-11-04T21:12:41.581299Z

the macros are interpreted with SCI during compilation

borkdude 2022-11-04T21:12:52.101539Z

and then the expansion is compiled to JS

1
alex 2022-11-05T03:02:01.919579Z

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
2022-11-25T14:30:14.393979Z

await-> coming? 🙂