shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
lokirrationalis 2021-01-09T08:52:48.413700Z

hi! is there a best practice on how to write tests for functions used in a react native environment? i tried targeting :node-test and :karma but β€” i guess one could have expected that β€” they throw syntax errors because i include react native modules written in / with flow for the type checks done in that module. as a disclaimer, i’m still in the early phases of clojure(script) development and also react native, so i guess i took on quite a challenge combining both from the start. πŸ™‚ i’d say my ideal scenario would be to test all my pure functions within the clojurescript side of things and i also think that’s the way to go. i’m not really after testing my ui modules / interactions. however, even with a minimal example for a test namespace that doesn’t include any of the namespaces using react native stuff i still get that syntax error, so i’m kinda out of ideas right now. maybe my only choice is to run my tests at runtime in the repl…?

thheller 2021-01-09T11:05:21.414400Z

@moledur best ask in #cljsrn I don't do react-native development myself and don't have a clue about testing πŸ˜›

lokirrationalis 2021-01-09T11:09:16.414600Z

okay thanks πŸ™‚

aratare 2021-01-09T13:40:19.416800Z

Hi there. I'm having some problems with importing JS file inside CLJS file. Specifically, when using the normal (:require ["blah" :refer [blah]]) I'm getting this error TypeError: $jscomp.inherits is not a function. I'm currently using [org.clojure/clojurescript "1.10.773"] and [thheller/shadow-cljs "2.11.11"]. Has anyone seen anything like this and can point me to the right direction? Thanks.

JAtkins 2021-01-11T19:29:39.459100Z

I have the same issue actually. Last time it was removed by bumping compiler support from default to :es5 then bumping again to :es6. But now, even on :es6 it has appeared 😐. IIRC this is an issue with polyfills

aratare 2021-01-12T00:47:23.460500Z

So I "solved" it by bumping to es6, but right now I have the exact opposite problem where I can't reproduce the problem even if I put it back to default. Everything else stays the same afaict.

aratare 2021-01-12T00:49:26.460700Z

I created a small pet project to try to reproduce the problem so @thheller can have a look at it. In the end I couldn't reproduce the error with the exact same configs and everything :mind_blown:

JAtkins 2021-01-12T00:59:59.461100Z

Yup. It's weird. I've had the issue several times. Never ever has it occurred on my local machine - only ever with my GH action build server. It's very, very random - I think the issue only randomly appears depending on some very pesudo-random build state inside of shadow.

aratare 2021-01-12T01:37:18.461300Z

Chaos engineering gone wrong πŸ˜„

thheller 2021-01-12T12:29:02.461700Z

please post any thoughts you have on the subject there πŸ™‚

πŸ‘ 1
aratare 2021-01-12T13:44:17.463600Z

Will do thanks

aratare 2021-01-09T13:49:48.417600Z

Update: Setting the compiler feature set to es6 makes it work. I guess es5 is not an option.

thheller 2021-01-09T15:46:11.418500Z

@rextruong unfortunately I haven't been able to reproduce this issue. es5 is the default and should be an option but breaks on some code. I don't know why, would help if you can make a reproducible repo

aratare 2021-01-12T00:50:46.460900Z

Sorry unfortunately I can't reproduce this anymore by some magical reasons πŸ˜…

william 2021-01-09T18:11:18.421400Z

good morning! I'm trying to use the expound library to pretty-print spec failures. Here's how expound is supposed to work in cljs:

$ clj -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "1.10.773"} expound {:mvn/version "0.8.7"}}}' -M -m cljs.main -re node

ClojureScript 1.10.773
cljs.user=> (require '[clojure.spec.test.alpha :as stest])
nil
cljs.user=> (require '[clojure.spec.alpha :as s])
nil
cljs.user=> (require '[expound.alpha :as expound])
nil
cljs.user=> (defn add1 [x] (+ 1 x))
#'cljs.user/add1
cljs.user=> (s/fdef add1 :args number?)
cljs.user/add1
cljs.user=> (stest/instrument `add1)
[cljs.user/add1]
cljs.user=> (set! s/*explain-out* expound/printer)
#object[expound$alpha$printer]
cljs.user=> (add1 nil)
Execution error - invalid arguments to cljs.user/add1 at (<cljs repl>:1).
<filename missing>:<line number missing>
-- Spec failed --------------------
Function arguments
  (nil)
should satisfy
  number?
-------------------------
Detected 1 error
However, when I do this in a repl controlled by shadow (both in CIDER and in the command line) I get instead some raw error object:
#error {:message "Call to #'cljs.user/add1 did not conform to spec.", :data {:cljs.spec.alpha/problems [{:path [], :pred cljs.core/number?, :val (nil), :via [], :in []}], :cljs.spec.alpha/spec #object[cljs.spec.alpha.t_cljs$spec$alpha30168], :cljs.spec.alpha/value (nil), :cljs.spec.alpha/fn cljs.user/add1, :cljs.spec.alpha/args (nil), :cljs.spec.alpha/failure :instrument}}
Is there a way to control how a failing spec is printed out in shadow-cljs?

aratare 2021-01-09T18:27:43.421500Z

I'll make an issue soon πŸ™‚

2021-01-09T19:32:31.427Z

I have run into an odd issue trying to require a library (@emotion/styled) from npm, where the library works fine on its own, but fails to be required after adding an unrelated npm dependency (@storybook/react). I created a reproduction here: https://github.com/dvingo/shadow-cljs-requires-bug Based on the output from the shadow-cljs build screen ("Babel transform:" statements) I suspect that there is some babel transformation happening to @emotion/styled via a transitive dependency of @storybook/react, but I haven't been able to figure out what it is. I played around with js-options for @emotion/styled to try and force a certain file to be used, but nothing has worked.

thheller 2021-01-09T20:25:45.428100Z

@meditans please create a github issue, it'll get lost here. @danvingo you too please

πŸ‘ 1
william 2021-01-09T21:13:23.428500Z

@thheller done at https://github.com/thheller/shadow-cljs/issues/825

thheller 2021-01-09T21:16:27.428800Z

thx

2021-01-09T21:58:40.431200Z

@thheller hey I am trying to work on a better Kaocha hook to start a shadow build if it isn't already running. Currently the hook, running in clj, is using

(shadow-api/release (:shadow/build testable))
but this kinda crappy side effect of always starting a new shadow server even if one is running. Is there an easy way to mimic what the shadow-cljs npm package does when starting a build by connecting to a running server or starting a new one?

2021-01-09T22:00:58.432Z

I guess I could always just shell out to start the build but I would prefer use a proper shadow api if possible

GHvW 2021-01-09T23:07:43.436800Z

I'm getting a build error caused by an npm dependency issue

[:app] Build failure:
Failed to inspect file
  /mnt/c/Users/ghvw/projects/clojure/skedaddle/node_modules/@arcgis/core/chunks/pe.js

it was required from
  /mnt/c/Users/ghvw/projects/clojure/skedaddle/node_modules/@arcgis/core/geometry/projection.js

Errors encountered while trying to parse file
  /mnt/c/Users/ghvw/projects/clojure/skedaddle/node_modules/@arcgis/core/chunks/pe.js
  {:line 5, :column 231, :message "'}' expected"}
Does this look familiar to anyone? I'm new to both clojurescript and shadow-cljs and so I thought I'd ask if this might be caused by something a newbie like me would do that is obvious to veteran users. if it's of any use, characters 220-240 of the pe.js file looks like this "t(((e,t)=>{import("./" , so it looks like it doesn't like something somewhere right at the { and import . Anyone have any ideas what I might be doing wrong? I should mention the npm package is a beta package, its possible there's something wrong, I just doubt its them.

Mr. Savy 2021-01-09T23:25:58.437500Z

has anyone ever run into an erroneous no output for id error while using the repl?