Fork me on GitHub
#shadow-cljs
<
2021-01-17
>
zendevil.eth07:01:47

has anyone used react native testing library with shadow-cljs?

zendevil.eth07:01:57

How did you integrate the tests?

janezj14:01:13

I would like to import js-notications, the exact syntax is not in shadow-cljs doc

import ToastManager from 'js-notifications';
const toastManager = new ToastManager();
(:require ["js-notifications" :refer (ToastManager)] ) (.ToastManager. {}) -> module$node_modules$js_notifications$dist$ToastManager.ToastManager is not a constructor

thheller15:01:56

the exact syntax is in the docs, see the translation table https://shadow-cljs.github.io/docs/UsersGuide.html#_using_npm_packages

janezj16:01:24

The exact pattern is not in the docs. I tried them all, but after lunch I might found the solution, it looks promising - no errors (It is not logical to me at all)

import ToastManager from 'js-notifications';
-> 
["js-notifications" :default ToastManager]

nivekuil16:01:35

I see that one as the first row in the table

janezj16:01:17

this "default" is confusing to me. When npm exports some objects, is there one default? or defaultExport is just a name and :default just picks an object from map of all exported objects?

thheller16:01:58

import defaultExport from "module-name"; it is right there in the first example 😛

thheller17:01:06

the name is up to you. you choose it. defaultExport is the name

thheller17:01:32

can be anything

thheller17:01:03

default exports are "new" in ESM and are somewhat special

thheller17:01:47

technically you can also :as x and x/default but thats kinda lame

zendevil.eth18:01:49

I’m getting the following error when running shadow watch

zendevil.eth18:01:03

Invalid configuration -- Spec failed --------------------  {:target ...,   :output-dir ...,   :entries [],       ^^   :build-id ...} should satisfy  (<= 1 (count %) Integer/MAX_VALUE) -- Relevant specs ------- :shadow.build.targets.npm-module/entries:  (clojure.spec.alpha/coll-of   clojure.core/simple-symbol?   :distinct   true   :min-count   1   :kind   clojure.core/vector?) :shadow.build.targets.npm-module/target:  (clojure.spec.alpha/keys   :req-un   [:shadow.build.targets.shared/output-dir   :shadow.build.targets.npm-module/entries]   :opt-un   [:shadow.build.targets.npm-module/runtime   :shadow.build.targets.shared/devtools]) :shadow.build.config/build+target:  (clojure.spec.alpha/and   :shadow.build.config/build   (clojure.spec.alpha/multi-spec   shadow.build.config/target-spec   :target)) ------------------------- Detected 1 error

zendevil.eth18:01:34

{:deps true :source-paths [“src”] :dependencies [[reagent “0.10.0"] [re-frame “0.12.0”] [re-frame-steroid “0.1.1"] [rn-shadow-steroid “0.2.1”] [re-frisk-remote “1.3.3"] [cljs-ajax/cljs-ajax “0.8.1”] [day8.re-frame/http-fx “0.2.2"]] :builds {:test {:target :npm-module :output-dir “test-out” :entries []} :dev {:target :react-native :init-fn humboi.core/init :output-dir “app” :compiler-options {:closure-defines {“re_frame.trace.trace_enabled_QMARK_” true}} :devtools {:after-load steroid.rn.core/reload :build-notify steroid.rn.core/build-notify :preloads [re-frisk-remote.preload]}}}}

zendevil.eth18:01:52

i’m running the command shadow-cljs watch test

thheller18:01:08

the error tells you that :entries [] is not valid and requires at least one namespace

zendevil.eth18:01:28

I put in a namespace myapp.core-test but it says that the namespace wasn’t found

zendevil.eth18:01:30

I expect that the namespace would be available

zendevil.eth18:01:52

since the namespace is defined in one of the files in the source-paths

zendevil.eth18:01:44

the source path is “test”

zendevil.eth18:01:31

and the file with this namespace is found in the path ./test/myapp

thheller19:01:52

:deps true. do you have "test" added in :paths in deps.edn?

zendevil.eth20:01:15

I’ve added test in :source-paths in deps.edn

janezj20:01:25

What about clj->js? I was quite naive, that the npm import has magic powers and will also convert clojure stuctures to js. But I found that this is not the case and clj->js is still a must, It would be great id clj-kondo would be able to recognize cases like that. I spent at least an hour before I find out that my options are silently ignored without conversion. (def tm (ToastManager. (clj->js {:container log-container, :seconds 300})))

borkdude20:01:50

@jj974 this is impossible to know for clj-kondo I think, which JS libs accept data CLJS structures and which do not (even if most of them don't)

thheller20:01:46

@ps :source-paths is not a thing in deps.edn. it is :paths or :extra-paths

✅ 3
janezj21:01:57

@U04V15CAJ clj-kondo is great. I cleaned up my old project. Learned a few things, misplaced doc strings, way too many times.