shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
zendevil 2021-01-17T07:06:47.043900Z

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

zendevil 2021-01-17T07:06:57.044200Z

How did you integrate the tests?

janezj 2021-01-17T14:49:13.047100Z

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

thheller 2021-01-17T15:23:56.047500Z

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

janezj 2021-01-17T16:29:24.056900Z

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]

nivekuil 2021-01-17T16:41:34.057Z

nivekuil 2021-01-17T16:41:35.057300Z

I see that one as the first row in the table

janezj 2021-01-17T16:52:17.061800Z

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?

thheller 2021-01-17T16:59:58.062200Z

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

thheller 2021-01-17T17:00:06.062500Z

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

thheller 2021-01-17T17:00:32.062800Z

can be anything

thheller 2021-01-17T17:01:03.063200Z

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

thheller 2021-01-17T17:01:47.063700Z

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

zendevil 2021-01-17T18:22:49.064Z

I’m getting the following error when running shadow watch

zendevil 2021-01-17T18:23:03.064200Z

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 2021-01-17T18:23:34.064600Z

{: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 2021-01-17T18:23:52.065Z

i’m running the command shadow-cljs watch test

thheller 2021-01-17T18:41:08.065800Z

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

zendevil 2021-01-17T18:45:28.066500Z

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

zendevil 2021-01-17T18:45:42.066800Z

not available

zendevil 2021-01-17T18:47:30.067300Z

I expect that the namespace would be available

zendevil 2021-01-17T18:47:52.067800Z

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

zendevil 2021-01-17T18:48:44.068200Z

the source path is “test”

zendevil 2021-01-17T18:57:31.068500Z

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

thheller 2021-01-17T19:29:52.069200Z

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

zendevil 2021-01-17T20:02:15.069700Z

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

janezj 2021-01-17T20:30:25.076800Z

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})))

borkdude 2021-01-17T20:31:50.077300Z

@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)

thheller 2021-01-17T20:34:46.078900Z

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

✅ 1
janezj 2021-01-17T21:53:57.081300Z

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

borkdude 2021-01-17T21:54:42.081500Z

:)