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
// @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.
Cool! Hadn't heard of happy-dom yet, always used jsdom. But this seems a lot more light weight
do you do all tests in js, or have you considered using nbb for the test code?
Iβm using JSDom in reagami tests. I looked at happydom but ChatGPT said JSDom conformed more to the spec or so?
probably true, but jsdom is also a monster. It's basically a full blown browser without the ui as far as I understand
Why is this a problem? Itβs not like I experience any slowness while running tests
not a problem, just maybe an overkill. I haven't seen any performance problems either.
(but then again I'm not running loads of tests ;)
Have used jsdom before and I can't remember why I opted for happy-dom. Probably I was convinced by some piece of marketing.
@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.