Fork me on GitHub
#shadow-cljs
<
2021-01-09
>
lokirrationalis08:01:48

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…?

thheller11:01:21

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

lokirrationalis11:01:16

okay thanks 🙂

aratare13:01:19

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.

JAtkins19:01:39

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

aratare13:01:48

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

thheller15:01:11

@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

aratare18:01:43

I'll make an issue soon 🙂

Carlo18:01:18

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?

dvingo19:01:31

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.

thheller20:01:45

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

👍 3
royalaid21:01:40

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

royalaid22:01:58

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

GHvW23:01:43

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.

AJ Snow23:01:58

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