Fork me on GitHub
#shadow-cljs
<
2017-11-22
>
thheller11:11:36

@mitchelkuijpers what does your :http-handler do? what kind of assets? css I presume?

mitchelkuijpers11:11:21

@thheller

(ns dev.test-handler
  (:require [ring.middleware.resource :as ring-resource]))

(defn not-found [req]
  {:status 404
   :headers {"content-type" "text/plain"}
   :body "Not found."})

(defn wrap-dir-index [handler]
  (fn [req]
    (handler
     (update-in req [:uri]
                #(if (= "/" %) "/index.html" %)))))

(def handler (-> not-found
                 (ring-resource/wrap-resource "public")
                 (wrap-dir-index)))

mitchelkuijpers11:11:07

Also pre-compiled js

thheller11:11:19

I can probably add an option for that as well.

thheller11:11:53

I fixed the most annoying part first. all those damn macros in cljs.test

mitchelkuijpers11:11:54

Cool, I also hadd to add a public dir or it wouldn't start up a http server

thheller11:11:23

yes, I’ll make :http-root optional if :http-handler is set.

thheller11:11:17

test are now queryable at runtime so you can probably build some fancy UIs out of that

thheller11:11:54

just need to figure out how to configure all of this from a build perspective

mitchelkuijpers11:11:03

Maybe give a test filename regex or something

thheller11:11:26

{:target :browser
   :asset-path "/js/test"
   :modules {:common {:entries []}
             :devcards {:entries [atlas-crm.cards] :depends-on #{:common}}
             :test {:entries [atlas-crm.client-test-main] :depends-on #{:common}}}
   :output-dir "resources/public/js/test/"
   :compiler-options {:devcards true}
   :devtools {:http-port 8600
              :http-root "public" ;; We don't use this but our handler, but this makes shadow start a http server
              :http-handler dev.test-handler/handler
              :after-load atlas-crm.client-test-main/client-tests
              :preloads [shadow.cljs.devtools.client.hud devtools.preload]}}

thheller11:11:33

needs way more options that just a regex though

thheller11:11:03

shadow-cljs browser-test some-regexp can probably spin up a http server and open it

thheller11:11:38

but how would you configure the :http-handler

thheller11:11:38

shadow-cljs browser-test --test-match some-regexp --port 1234 --handler some.ns/handler --runner atlas-crm.client-test-main etc

thheller11:11:04

you end up with a whole bunch of optionas

mitchelkuijpers11:11:32

Hmm yes but most probably don't need the handler option

thheller11:11:33

yes but what do you do if you need it?

thheller11:11:32

do you ever use the karma test server thing?

colindresj16:11:29

I’m having a little troubling with shadow and namespaces

colindresj16:11:45

I keep getting filename violation statements

colindresj16:11:46

For example:

INFO: filename violation for ns paper.components.tooltip, got: cljs/paper/components/tooltip.cljs expected: paper/components/tooltip.cljs (or .cljc)

colindresj17:11:59

My shadow-cljs.edn file has :source-paths set to ["src/cljs"]

thheller18:11:11

@colindresj thats odd, can you run shadow-cljs --cli-info?

thheller18:11:45

are you using :lein in your config? when embedding inside boot or lein their classpath will be used and :source-paths has no effect.

colindresj18:11:02

The lein source path looks like this ["src/cljs" "src/cljc"]

thheller18:11:19

somehow "src" ends up in your classpath as well

colindresj18:11:32

Let me dig around some more, the project.clj source paths vector looked different earlier (and had “src” in it)

thheller18:11:19

btw its fine to use one source path. I put my cljs/cljc files into the same dir

colindresj18:11:07

Yeah, I keep going back and forth on which organizational style I prefer

colindresj18:11:29

Kind of related question: I’m currently using lein: true because I want to manage my clojure dependencies via project.clj (for cursive support)

colindresj18:11:13

Is the lein option a full opt-in, or can I just use lein for dependency management, and shadow for classpath building via the .edn file’s source path vector?

thheller18:11:15

wow I never thought of that

thheller18:11:31

currently the process is just launched through lein

thheller18:11:54

but I could maybe just use it to get the classpath and then add the define :source-paths

thheller18:11:15

you can however also use shadow-cljs pom to generate a pom.xml and use that for cursive

colindresj18:11:22

Oh sweet, didn’t realize that, will give it a try and see if it works

thheller18:11:46

project.clj still gives you more features so its not 100%

colindresj18:11:18

It’s ok to have a shadow-cljs.edn file that just lists out :lein true and :builds ..., nothing else

thheller18:11:39

as soon as cursive supports the new deps.edn I’ll add support for that which should remove some of the lein oddities

colindresj18:11:52

Thanks for the help

thheller18:11:02

@mitchelkuijpers I’m fighting karma I don’t really understand what its doing

thheller18:11:42

22 11 2017 19:36:28.744:WARN [web-server]: 404: /js/cljs-runtime/goog.debug.error.js
22 11 2017 19:36:28.744:WARN [web-server]: 404: /js/cljs-runtime/goog.dom.nodetype.js
22 11 2017 19:36:28.745:WARN [web-server]: 404: /js/cljs-runtime/goog.string.string.js
22 11 2017 19:36:28.747:WARN [web-server]: 404: /js/cljs-runtime/goog.asserts.asserts.js

thheller18:11:56

I assume thats because of the include: false from your config

thheller18:11:12

but when I add them it will add them to the page itself which just breaks

thheller18:11:27

do I need to compile to one file only?

thheller18:11:03

I seem to have the correct basePath but the js file can’t include anything else

thheller18:11:32

it loads all the js weirdly, guess it really wants one file only

thheller18:11:53

HeadlessChrome 0.0.0 (Mac OS X 10.12.6) LOG: '0 failures, 0 errors.'

22 11 2017 19:47:59.079:WARN [HeadlessChrome 0.0.0 (Mac OS X 10.12.6)]: Disconnected (1 times), because no message in 10000 ms.
HeadlessChrome 0.0.0 (Mac OS X 10.12.6) ERROR
  Disconnected, because no message in 10000 ms.

thheller18:11:16

works, just needs some karma interop I guess

mitchelkuijpers18:11:59

Ah you still need help @thheller

mitchelkuijpers18:11:14

The include stuff is really annoying not sure why it works that way..

thheller18:11:39

I think we really don’t want to run tests through karma at dev time

thheller18:11:00

:test-dummy
  {:target :browser-test
   :output-dir "out/demo-test-dummy/public/js"
   :devtools
   {:http-root "out/demo-test-dummy/public"
    :http-port 8606}}

thheller18:11:03

I have this for now

thheller18:11:35

all the necessary hooks will be generated

thheller18:11:38

still need a way to filter the namespaces but by default all namespaces that require cljs.test will be included

thheller18:11:54

which probably won’t work for fulcro

mitchelkuijpers18:11:06

It does use cljs.test under the hood

mitchelkuijpers18:11:16

But does it simply inspects all the files?

thheller18:11:34

no it must have a require for cljs.test itself to trigger this

thheller18:11:44

but I guess the regexp you where using is more flexible

thheller18:11:17

since its just about including the file in the build nothing more

mitchelkuijpers18:11:32

Yes that is pretty much the only thing

mitchelkuijpers18:11:55

Ahh now I see the browser-test target.. took me a while. I like that solution ^^

thheller19:11:10

can specify :runner for a custom runner

thheller19:11:52

still messing with the details but the test one I’m using currently looks like

thheller19:11:53

(ns shadow.test.browser
  "generic browser test runner"
  (:require [shadow.test :as st]
            [shadow.dom :as dom]))

;; FIXME: implement custom reporter instead
(defonce log-node (dom/by-id "log"))
(when log-node
  (set-print-fn!
    (fn [s]
      (dom/append log-node (str s "\n")))))

(defn start []
  ;; (js/console.log "test env" @st/tests-ref)
  (st/run-all-tests))

(defn stop [done]
  (set! (.-innerText log-node) "")

  ;; FIXME: determine if async tests are still running
  ;; and call done after instead
  ;; otherwise a live reload might interfere with running tests by
  ;; reloading code in the middle
  (done))

;; not sure we need to do something once?
(defn ^:export init []
  (start))

thheller19:11:22

could build something cooler but it’ll do for now

mitchelkuijpers19:11:00

Ah cool, if I would build a custom runner then how would I get a hold of all the test namespaces?

mitchelkuijpers19:11:23

With shadow.test somehow?

thheller19:11:13

yep, shadow.test/tests-ref is an atom with all the tests

thheller19:11:18

its all cljs.test as usual, the only thing I added is that deftest is registered at runtime

thheller19:11:31

so you can query everything and don’t need a macro to do that

thheller19:11:55

ie. it gets very easy to just run tests that were live reloaded

thheller19:11:44

all this info was previously reserved for macro which is why anything involving tests also had to use macros

thheller19:11:49

that takes care of that problem

thheller19:11:54

much more flexibel

mitchelkuijpers20:11:12

Damn thats awesome will def try this out tommorow