Skip to content

Instantly share code, notes, and snippets.

@realgenekim
Last active August 12, 2024 22:06

Revisions

  1. realgenekim revised this gist Aug 12, 2024. 1 changed file with 50 additions and 0 deletions.
    50 changes: 50 additions & 0 deletions shadow-cljs.edn
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    {:deps {:aliases [:dev :test]}
    :nrepl {:port 9000}
    :jvm-opts ["-Xmx2G"]
    :builds {:main {:target :browser
    :output-dir "resources/public/js/main"
    :asset-path "/js/main"
    :dev {:compiler-options {:external-config {:guardrails {:emit-spec? true :throw? false}}}}
    :modules {:main {:init-fn com.example.client/init}}
    ;:dev-http {8000 "public"}
    :js-options {:resolve
    {
    ;; for performance checking during dev
    ;;"react-dom" {:target :npm
    ;;:require "react-dom/cjs/react-dom.production.min.js"}
    ;;"react" {:target :npm
    ;;:require "react/cjs/react.production.min.js"}

    ;; Make js-joda-timezone a more reasonable build size
    "@js-joda/timezone"
    {:target :npm
    :require "@js-joda/timezone/dist/js-joda-timezone-10-year-range.min.js"}}}
    :build-hooks [#_(shadow.cljs.build-report/hook {:output-to "target/build_report.html"})
    (com.example.hyperfiddle/rcf-shadow-hook)
    #_(user/rcf-shadow-hook)]
    :devtools {:preloads [com.fulcrologic.fulcro.inspect.preload
    com.fulcrologic.fulcro.inspect.dom-picker-preload
    holyjak.fulcro-troubleshooting]
    :after-load com.example.client/refresh
    :watch-dir "resources/public"}}

    :test {:target :browser-test
    :test-dir "resources/public/js/test"
    :ns-regexp "-spec$"
    :compiler-options {:static-fns false
    :external-config {:guardrails {:throw? true :emit-spec? true}}}
    :js-options {:resolve {"react-dom" {:target :npm
    :require "react-dom/cjs/react-dom.production.min.js"}
    "react" {:target :npm
    :require "react/cjs/react.production.min.js"}}}
    :devtools {:http-port 8081
    :http-resource-root "public"
    :http-root "resources/public/js/test"}}

    :ci-tests {:target :karma
    :js-options {:js-provider :shadow}
    :compiler-options {:static-fns false ; required for mocking to work
    :external-config {:guardrails {:throw? true :emit-spec? true}}}
    :output-to "target/ci.js"
    :ns-regexp "-spec$"}}}

  2. realgenekim created this gist Aug 12, 2024.
    32 changes: 32 additions & 0 deletions hyperfiddle.cljc
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    (ns com.example.hyperfiddle
    (:require
    [hyperfiddle.rcf]
    [taoensso.timbre :as log]))


    ; wait to enable tests until after app namespaces are loaded
    (defn rcf-enable []
    (hyperfiddle.rcf/enable!))

    #?(:clj
    ;(def rcf-enable! (delay @(requiring-resolve 'hyperfiddle.rcf/enable!)))
    (def rcf-enable! hyperfiddle.rcf/enable!)
    :cljs
    (def rcf-enable! hyperfiddle.rcf/enable!))
    ;(def rcf-enable! nil))

    (defn rcf-shadow-hook
    {:shadow.build/stages #{:compile-prepare :compile-finish}}
    [build-state & args]
    ;; NOTE this won't prevent RCF tests to run during :require-macros phase
    (log/error :rcf "RCF tests enabled")
    (case (:shadow.build/stage build-state)
    :compile-prepare (rcf-enable! false)
    :compile-finish (rcf-enable!))
    build-state)

    ; subsequent REPL interactions will run tests

    ; prevent test execution during cljs hot code reload
    #?(:cljs (defn ^:dev/before-load stop [] (hyperfiddle.rcf/enable! false)))
    #?(:cljs (defn ^:dev/after-load start [] (hyperfiddle.rcf/enable!)))