scittle

Chris McCormick 2025-11-11T09:18:28.104159Z

Figured out how to run fully interactive Reagent forms in Node via Scittle and happy-dom. Planning to use this to verify Eucalypt behaviour in tests matches Reagent. https://gist.github.com/chr15m/204f645c56a22aa39f2cdaab6a80bd66

const cljs =`
(ns updater
  (:require
    [reagent.core :as r]
    [reagent.dom :as rdom]))
(def state (r/atom nil))
(defn app []
  [:div "Hello world!"]
  [:button {:on-click #(swap! state update :val inc)} "Counter: " (:val @state)])
(rdom/render [app] (.getElementById js/document "app"))
`

const fs = require("fs")
const hd = require("happy-dom")
globalThis.ReactDOM = require("react-dom")
globalThis.React = require("react")

const window = new hd.Window()
globalThis.document = window.document
globalThis.window = window

const appDiv = document.createElement("div")
appDiv.id = "app"
document.body.appendChild(appDiv)

eval.call(globalThis, (fs.readFileSync("node_modules/scittle/dist/scittle.js", "utf8")))
eval.call(globalThis, (fs.readFileSync("node_modules/scittle/dist/scittle.reagent.js", "utf8")))
scittle.core.eval_string(cljs)
document.querySelector("button").click();
setTimeout(() => {
  console.log(document.body.toString());
}, 0);

// $ node node-scittle-reagent.js
// 

πŸ‘ 2
Gregory Bleiker 2025-11-12T08:01:45.878519Z

@chris358 I meant instead of using the js code above use nbb (and also call squint from nbb). The question is just out of curiosity.

πŸ‘ 1
Gregory Bleiker 2025-11-11T09:32:21.592859Z

Cool! Hadn't heard of happy-dom yet, always used jsdom. But this seems a lot more light weight

Gregory Bleiker 2025-11-11T09:35:17.301069Z

do you do all tests in js, or have you considered using nbb for the test code?

borkdude 2025-11-11T09:40:24.593169Z

I’m using JSDom in reagami tests. I looked at happydom but ChatGPT said JSDom conformed more to the spec or so?

Gregory Bleiker 2025-11-11T09:41:45.427159Z

probably true, but jsdom is also a monster. It's basically a full blown browser without the ui as far as I understand

borkdude 2025-11-11T09:45:19.346309Z

Why is this a problem? It’s not like I experience any slowness while running tests

Gregory Bleiker 2025-11-11T09:51:22.801309Z

not a problem, just maybe an overkill. I haven't seen any performance problems either.

Gregory Bleiker 2025-11-11T09:51:57.056019Z

(but then again I'm not running loads of tests ;)

Chris McCormick 2025-11-12T00:34:30.108109Z

Have used jsdom before and I can't remember why I opted for happy-dom. Probably I was convinced by some piece of marketing.

Chris McCormick 2025-11-12T00:35:31.292679Z

@gregorybleiker I haven't used nbb for the tests in Eucalypt because it's Squint. I'm currently trying to puzzle how to get the same tests to run in both environments so I can compare. It's tricky because vittest wants to wrap everything.