shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
2021-01-19T00:53:28.095600Z

I am using this dependency: [cljsjs/react-input-autosize “2.2.1-1”]

2021-01-19T00:53:54.096Z

and when run npx shadow-cljs compile app, it errs: The required namespace “cljsjs.react-input-autosize” is not available, it was required by “understanding_re_frame/hiccup.cljs”

2021-01-19T00:54:56.096500Z

However, I do see a ~/.m2/repository/cljsjs/react-input-autosize/2.2.1-1/react-input-autosize-2.2.1-1.jar file

2021-01-19T00:55:09.096900Z

what’s the further steps should I verify to see what’s going wrong?

dpsutton 2021-01-19T00:56:41.097200Z

> shadow-cljs does not support CLJSJS at all to avoid conflicts in your code https://shadow-cljs.github.io/docs/UsersGuide.html#_why_not_use_cljsjs

2021-01-19T13:19:21.097400Z

Thanks for that info.

Schpaa 2021-01-19T13:28:11.097800Z

Does shadow support this? http://clojurescriptmadeeasy.com/blog/refactoring-with-deprecation.html

thheller 2021-01-19T13:30:24.098200Z

@schpaencoder in the latest version you can set :devtools {:ignore-warnings true} so this doesn't blow stuff up

thheller 2021-01-19T13:30:32.098600Z

or you can just turn off the warning completely

thheller 2021-01-19T13:31:03.099Z

:compiler-options {:warnings {:fn-deprecated false}} should work fine yes

Schpaa 2021-01-19T13:31:27.099500Z

there is this ^

Schpaa 2021-01-19T13:31:37.099700Z

(def ^:dynamic cljs-warn-fn-deprecated true)

Schpaa 2021-01-19T13:32:07.100100Z

If I can do this with a simple binding, I would rather…

thheller 2021-01-19T13:34:52.100500Z

pretty sure that code doesn't exist anymore

Schpaa 2021-01-19T13:38:50.100900Z

oh well, I guess I just have to slow down a little then

thheller 2021-01-19T13:39:10.101100Z

whats the problem?

Schpaa 2021-01-19T13:40:11.101700Z

The problem is I don’t want to turn off warnings, but shadow complains about deprecations

thheller 2021-01-19T13:41:34.102400Z

then turn off that warning if you dont want to see that warning

Schpaa 2021-01-19T13:42:18.103200Z

Oh, sorry, Didn’t see the {:fn-deprecated false}

thheller 2021-01-19T13:42:24.103600Z

unless you still want to see it but not prevent hot reload and stuff. for that you can set :devtools {:ignore-warnings true}

Schpaa 2021-01-19T13:42:27.103800Z

Yes of course!

Schpaa 2021-01-19T13:42:37.104Z

perfect!!

Margo 2021-01-19T14:30:33.106800Z

hello, everybody! I am relatively not new to clojureScript, but I am new to shadow-cljs, in particular how to configure testing properly. i have a 100% shadow-cljs project and I am struggling with the :node-test and :browser-test setups as they do not give me the desired output. Can maybe somebody give me an example of a project with shadow-cljs with properly configured testing? thank you in advance

2021-01-19T16:18:46.108500Z

Isn’t shadow supposed to automatically download the dependency? When I add https://github.com/day8/re-frame-10x as the project dependency, it errs: The required JS dependency “react-highlight.js” is not available, it was required by “day8/re_frame_10x/view/components.cljs”.

thheller 2021-01-19T16:18:48.108700Z

@marharyta.obraztsova what is the "desired output"?

thheller 2021-01-19T16:19:41.109500Z

@i did you restart after adding the dependency?

2021-01-19T16:23:01.109600Z

Yes. Now I manually add the dependency.

Margo 2021-01-19T18:17:51.110Z

So, I am currently configuring :browser-test and the way I understand it (correct me if I am wrong) that this is the best way to set up testing for atoms and re-agent components

Margo 2021-01-19T18:18:08.110200Z

Initially I was not able to see the UI in the browser

Margo 2021-01-19T18:18:53.110400Z

Margo 2021-01-19T18:19:14.110800Z

as you can see now, I do, yet the panel on top shows 0 tests, o assertions

Margo 2021-01-19T18:20:34.111Z

Margo 2021-01-19T18:20:38.111400Z

there it is

thheller 2021-01-19T18:25:06.111600Z

hmm not a clue about that. that display is from https://github.com/bhauman/cljs-test-display

Margo 2021-01-19T18:25:38.111900Z

yes, it is

Margo 2021-01-19T18:26:15.112100Z

according to the shadow-cljs docs I should not need it in the first place

Margo 2021-01-19T18:26:24.112300Z

because they have it intergrated

Margo 2021-01-19T18:26:29.112500Z

But I seem to need

thheller 2021-01-19T18:26:42.112700Z

need what?

Margo 2021-01-19T18:27:10.112900Z

... I seem to need it in my code to display the tests in the viasual way in the browser anyways

thheller 2021-01-19T18:27:47.113100Z

I'm confused. this is something you set up yourself?

Margo 2021-01-19T18:28:02.113300Z

yes, I did set it up myself

Margo 2021-01-19T18:28:28.113500Z

test.cljs

(ns mytherapy.test
  (:require [cljs.test :refer (deftest is use-fixtures)]
            [shadow.dom :as dom]
            [shadow.test :as st]
            [cljs-test-display.core :as ctd]
            ["react-testing-library" :as rtl]
            [cljs-time.core :as time]
            [mytherapy.state-utils :refer [state-app make-note]]
            ))


;; <https://gist.github.com/cdbkr/f195d7fbb600fae9655f37e7b2b4813e>
 
(use-fixtures :each
  {:after rtl/cleanup})

(def test-state {:notes []
                 :records []
                 :data []
                 :currentNote {}})

(deftest a-failing-test
  (is (= 2 2)))

(deftest a-failing-test-6
  (is (= 9 2)))

(deftest test-make-note
  (is (= (make-note "uhihy" "hello" "20210119T164619") {:note_id "uhihy"
                                      :note_title "hello"
                                      :note_type "note"
                                      :timestamp_created "20210119T164619"
                                      :timestamp_edited "20210119T164619"})))

(defn start []
  (st/run-all-tests (ctd/init! "test-root"))
  (a-failing-test)
  (a-failing-test-6)
  (test-make-note))

(defn stop[done]
  ; tests can be async. You must call done so that the runner knows you actually finished
  (done))

(defn ^:export init[]
  (dom/append [:div#test-root])
  (start))

thheller 2021-01-19T18:28:38.113700Z

why did you do that?

Margo 2021-01-19T18:28:56.113900Z

because otherwise I see blank page

Margo 2021-01-19T18:29:13.114100Z

if the test file looks like this:

thheller 2021-01-19T18:29:50.114300Z

the test file should just contain deftest and so on

Margo 2021-01-19T18:30:09.114500Z

(ns mytherapy.test
  (:require [cljs.test :refer (deftest is use-fixtures)]
            [shadow.dom :as dom]
            [shadow.test :as st]
            [cljs-test-display.core :as ctd]
            ["react-testing-library" :as rtl]
            [cljs-time.core :as time]
            [mytherapy.state-utils :refer [state-app make-note]]
            ))


;; <https://gist.github.com/cdbkr/f195d7fbb600fae9655f37e7b2b4813e>
 
(use-fixtures :each
  {:after rtl/cleanup})

(def test-state {:notes []
                 :records []
                 :data []
                 :currentNote {}})

(deftest a-failing-test
  (is (= 2 2)))

(deftest a-failing-test-6
  (is (= 9 2)))

(deftest test-make-note
  (is (= (make-note "uhihy" "hello" "20210119T164619") {:note_id "uhihy"
                                      :note_title "hello"
                                      :note_type "note"
                                      :timestamp_created "20210119T164619"
                                      :timestamp_edited "20210119T164619"})))

(defn start []
  (a-failing-test)
  (a-failing-test-6)
  (test-make-note))

(defn stop[done]
  ; tests can be async. You must call done so that the runner knows you actually finished
  (done))

(defn ^:export init[]
  (start))

thheller 2021-01-19T18:30:10.114700Z

nothing related to runner stuff. that is completely optional. I guess the docs should make that clearer.

Margo 2021-01-19T18:30:21.114900Z

then i see blank page

thheller 2021-01-19T18:30:23.115100Z

remove start/stop/init completely

Margo 2021-01-19T18:30:41.115300Z

It says I should do that in the docs

thheller 2021-01-19T18:30:52.115500Z

and do NOT specify a :runner-ns in your build config

Margo 2021-01-19T18:31:19.115900Z

hmm, I can try it

thheller 2021-01-19T18:31:26.116100Z

yeah I'll clear that up. :runner-ns (optional)

thheller 2021-01-19T18:31:31.116300Z

this is definitely not clear enough 😛

Margo 2021-01-19T18:33:53.116500Z

after deleting :runner-ns I see nothing

thheller 2021-01-19T18:34:56.116900Z

ok now you likely need to delete the index.html you created

thheller 2021-01-19T18:35:03.117100Z

shadow-cljs will generate a new one (when you start the watch)

Margo 2021-01-19T18:37:27.117400Z

Same here

thheller 2021-01-19T18:39:21.117800Z

{...
 :builds
 {:test
  {:target :browser-test
   :test-dir "test-out"
   :ns-regexp "-test$"
   :devtools {:http-port 8021
              :http-root "test-out"}}}}

thheller 2021-01-19T18:39:47.118Z

try this. just in case there are files or whatever in the old :test-dir interfering with stuff

thheller 2021-01-19T18:40:40.118200Z

note that the test ns likely needs to be changed as the regexp above is for files ending in -test so mytherapy.test wouldn't match that

Margo 2021-01-19T18:42:09.118400Z

perfect!

Margo 2021-01-19T18:42:35.118800Z

Thanks a lot @thheller!