Fork me on GitHub
#shadow-cljs
<
2020-08-14
>
Aron05:08:33

If I want to compile some tests for puppeteer or similar, to be ran both with watch and a single test with return 0 if tests pass, which build target is the best? After 2 days of trying everything and nothing working out, I am inclined to believe that I should either use jvm (i.e. etaoin) or none of the -test builds, but node-script. Is this correct?

thheller07:08:26

@ashnur node-test should be fine

Aron07:08:59

thanks, I will try that again then : )

Aron07:08:33

One thing I am really confused about is that it seems the process exists before the go blocks finish running.

thheller07:08:33

well you need to use the async test helper. otherwise the tests finish without waiting for async stuff and exit the process.

Aron07:08:24

Ok, that sounds reasonable but I am looking here https://shadow-cljs.github.io/docs/UsersGuide.html#target-node-test and I am not really sure what would be the 'helper' that you refer to. The whole page doesn't have this word on it : )

thheller07:08:08

because its not shadow-cljs related. it is cljs.test/async

Aron07:08:13

sorry, this is embarrassing. thanks again

Samuel McHugh11:08:09

Hello, I'm trying to get a test build working with devcards test. My working devcards build has a option

:build-options {:ns-aliases {devcards-marked cljsjs.marked, devcards-syntax-highlighter cljsjs.highlight}}
specified. The problem is that this :build-options key is not available when setting up a :test build. So any files in devcards which match the -test$ regex will try to compile with this test build, but they will also end up including devcard.core leading to the marked issue.

thheller11:08:32

@smchugh230395 I'm not sure what you mean by :build-options key is not available ...

Samuel McHugh11:08:01

{:test
  {:target    :node-test
   :output-to "out/node-tests.js"
   :ns-regexp "-spec$"
   :autorun   true
   :main      optional}}}
This is the list of config options according to the docs. It does not list :build-options as a valid config option. I thought maybe it is valid, but unlisted in the docs, so I tried including it in the test config options. This did not solve the issue though as opposed to my :mycards build which works fine.

thheller11:08:35

:build-options can be used in any build, the docs just don't mention it. just like :compiler-options and :js-options.

Samuel McHugh11:08:48

That was indeed my suspicion. When I ran previously I was still getting the same issues with regards to "devcards-marked" but now it's compiling. I must have made an error when compiling. Sorry about that. Thanks for the help.

jeff tang20:08:03

Hello, I'm currently building a cljs electron app. I'm finding some difficulty accessing node.js APIs from renderer application namespaces. For instance, I can access fs fine from main, but not from the application code. I can access npm modules fine from the application as well, such as @material-ui/icons. Most of my code is based off of https://github.com/ahonn/shadow-electron-starter, and I have enabled nodeIntegration.

jeff tang21:08:26

Interestingly, when I add (:require ["electron" :as elec :refer [ipcRenderer]]) to the top of a renderer file, and print elec, it is an empty js object.

jeff tang21:08:57

Verified: from the electron console, module$node_modules$electron$index returns an empty object

jeff tang21:08:23

Whoo. I'm able to (js/require "fs") . I need to understand the difference between :require and js/require ...

jeff tang21:08:18

Appears that js/require is commonJS require('') whereas :require is fancy ES6 import * from "" https://clojureverse.org/t/guide-on-how-to-use-import-npm-modules-packages-in-clojurescript/2298

jeff tang21:08:19

I wonder if this has something to do with :target :browser for the renderer code. Perhaps shadow-cljs doesn't expect this code to also have node.js access in the case of electron?

Pavel Klavík21:08:09

@thheller So the strange error with incorrect UTF-8 start byte started occuring to me again:

Pavel Klavík21:08:09

Exception in thread "XNIO-1 I/O-3" java.lang.RuntimeException: com.fasterxml.jackson.core.JsonParseException: Invalid UTF-8 start byte 0xf8
 at [Source: java.io.ByteArrayInputStream@21c7c0c2; line: 1, column: 92]
        at com.cognitect.transit.impl.ReaderFactory$ReaderImpl.read(ReaderFactory.java:114)
        at cognitect.transit$read.invokeStatic(transit.clj:319)
        at cognitect.transit$read.invoke(transit.clj:315)
        at shadow.cljs.devtools.server.common$fn__14808$fn__14809.invoke(common.clj:47)
        at clojure.core$map$fn__5862$fn__5863.invoke(core.clj:2742)
        at clojure.core.async.impl.channels$chan$fn__872.invoke(channels.clj:300)
        at clojure.core.async.impl.channels.ManyToManyChannel.put_BANG_(channels.clj:83)
        at clojure.core.async$put_BANG_.invokeStatic(async.clj:199)
        at clojure.core.async$put_BANG_.invoke(async.clj:187)
        at shadow.undertow$fn$reify__16240$handler_fn__16241.invoke(undertow.clj:314)
        at shadow.undertow.WsTextReceiver.onFullTextMessage(WsTextReceiver.java:20)
        at io.undertow.websockets.core.AbstractReceiveListener$2.complete(AbstractReceiveListener.java:156)
        at io.undertow.websockets.core.AbstractReceiveListener$2.complete(AbstractReceiveListener.java:152)
        at io.undertow.websockets.core.BufferedTextMessage.read(BufferedTextMessage.java:105)
        at io.undertow.websockets.core.AbstractReceiveListener.readBufferedText(AbstractReceiveListener.java:152)
        at io.undertow.websockets.core.AbstractReceiveListener.bufferFullMessage(AbstractReceiveListener.java:90)
        at io.undertow.websockets.core.AbstractReceiveListener.onText(AbstractReceiveListener.java:70)
        at io.undertow.websockets.core.AbstractReceiveListener.handleEvent(AbstractReceiveListener.java:44)
        at io.undertow.websockets.core.AbstractReceiveListener.handleEvent(AbstractReceiveListener.java:33)
        at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92)
        at io.undertow.server.protocol.framed.AbstractFramedChannel$FrameReadListener.handleEvent(AbstractFramedChannel.java:952)
        at io.undertow.server.protocol.framed.AbstractFramedChannel$FrameReadListener.handleEvent(AbstractFramedChannel.java:932)
        at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92)
        at org.xnio.conduits.ReadReadyHandler$ChannelListenerHandler.readReady(ReadReadyHandler.java:66)
        at org.xnio.nio.NioSocketConduit.handleReady(NioSocketConduit.java:89)
        at org.xnio.nio.WorkerThread.run(WorkerThread.java:591)
Caused by: com.fasterxml.jackson.core.JsonParseException: Invalid UTF-8 start byte 0xf8
 at [Source: java.io.ByteArrayInputStream@21c7c0c2; line: 1, column: 92]
        at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1702)
        at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:558)
        at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._reportInvalidInitial(UTF8StreamJsonParser.java:3544)
        at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._reportInvalidChar(UTF8StreamJsonParser.java:3538)
        at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._finishString2(UTF8StreamJsonParser.java:2543)
        at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._finishAndReturnString(UTF8StreamJsonParser.java:2469)
        at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.getText(UTF8StreamJsonParser.java:315)
        at com.cognitect.transit.impl.JsonParser.parseVal(JsonParser.java:60)
        at com.cognitect.transit.impl.JsonParser.parseMap(JsonParser.java:112)
        at com.cognitect.transit.impl.JsonParser.parseArray(JsonParser.java:128)
        at com.cognitect.transit.impl.JsonParser.parseVal(JsonParser.java:56)
        at com.cognitect.transit.impl.JsonParser.parse(JsonParser.java:46)
        at com.cognitect.transit.impl.ReaderFactory$ReaderImpl.read(ReaderFactory.java:112)
        ... 25 more

Pavel Klavík21:08:09

So I was digging little bit through my data and I found that the problem is with using non-ascii characters in strings. Evaluating the following form in REPL will throw the error:

"Křápová"
Was something changed recently in using transit in Shadow-cljs? My version is 10.18.

thheller22:08:38

@pavel.klavik works fine for me

s$ shadow-cljs node-repl
shadow-cljs - config: /mnt/c/Users/thheller/code/shadow-cljs/shadow-cljs.edn
shadow-cljs - connected to server
cljs.user=> "Křápová"
"Křápová"
cljs.user=>

thheller22:08:53

@tangj1122 :browser by default will try to bundle all js requires which isn't what you want in case of electron. so you can either set :js-options {:js-provider :require} or :js-options {:keep-as-require #{"fs" ...}}

thheller22:08:34

:require will make everything go through require (so via nodeIntegration). :keep-as-require lets you select whichever packages but defaults to bundling all others

Pavel Klavík22:08:15

so it works with node-repl

Pavel Klavík22:08:05

and I tested everything from scretch and I get the same error with this output in REPL:

Connecting to remote nREPL server...
Clojure 1.10.1
"Křápová"
=> "Křápová"
(shadow/repl :client)
To quit, type: :cljs/quit
=> [:selected :client]
"Křápová"

thheller22:08:28

don't know what to tell you. works fine in node-repl and browser-repl for me.

thheller22:08:51

maybe your browser encoding is messed up?

thheller22:08:22

also works fine over nrepl

(shadow/repl :browser)
To quit, type: :cljs/quit
=> [:selected :browser]
"Křápová"
=> "Křápová"

Pavel Klavík23:08:39

no idea, but it is broken in both firefox and chrome

Pavel Klavík23:08:15

maybe something in my shadow-cljs.edn?

{:source-paths ["src"]
 :dependencies [[reagent "0.10.0"]
                [reagent-utils "0.3.3"]
                [re-frame "0.12.0"]
                [com.cognitect/transit-cljs "0.8.264"]
                [day8.re-frame/http-fx "v0.2.0"]
                [hickory "0.7.1"]
                [binaryage/devtools "0.9.10"]
                [bidi "2.1.6"]
                [com.taoensso/sente "1.15.0"]
                [venantius/accountant "0.2.5"]
                [com.cemerick/url "0.1.2-SNAPSHOT"]
                [com.taoensso/timbre "4.10.0"]
                [cljc.java-time "0.1.8"]
                [bouncer "1.0.1"]
                [orgpad/volcano "0.1.2"]
                [macchiato/core "0.2.17"]
                [macchiato/env "0.0.6"]
                [mount "0.1.16"]]
 :nrepl        {:port 9000}
 :builds       {:client     {:target           :browser
                             :output-dir       "resources/public/js/compiled"
                             :asset-path       "/js/compiled"
                             :modules          {:shared {:entries []}
                                                :main   {:init-fn    orgpad.client.core/init
                                                         :depends-on #{:shared}}
                                                :layout {:entries    [orgpad.client.layout.webworker.core]
                                                         :depends-on #{:shared}
                                                         :web-worker true}}
                             :compiler-options {:infer-externs      :auto
                                                :output-feature-set :es6}
                             :devtools         {:after-load     orgpad.client.core/mount-root
                                                :before-load    orgpad.client.core/stop-web-workers
                                                :watch-dir      "resources/public"
                                                :browser-inject :main
                                                :loader-mode    :script}}
                :landing    {:target     :browser
                             :output-dir "landing/resources/js"
                             :asset-path "/js"
                             :modules    {:main {:init-fn orgpad.landing.dev/init}}
                             :devtools   {:http-root      "landing/resources"
                                          :http-port      3500
                                          :after-load     orgpad.landing.dev/mount-root
                                          :watch-dir      "landing/resources"
                                          :browser-inject :main}}
                :emails     {:target     :browser
                             :output-dir "emails/js"
                             :asset-path "/js"
                             :modules    {:main {:init-fn orgpad.server.email.dev/init}}
                             :devtools   {:http-root      "emails"
                                          :http-port      3600
                                          :after-load     orgpad.server.email.dev/mount-root
                                          :watch-dir      "emails"
                                          :browser-inject :main}}
                :screenshot {:target           :node-script
                             :main             orgpad.screenshot.core/main
                             :output-to        "screenshot/screenshot.js"
                             :devtools         {:autoload true}
                             :compiler-options {:optimizations :simple}}}}

Pavel Klavík23:08:22

it fails in client project

thheller23:08:10

can't think of anything that would affect this in shadow-cljs. maybe a bad charset encoding in your editor/terminal? should be utf-8

Pavel Klavík23:08:40

I am using Cursive nREPL

Pavel Klavík23:08:03

how can I access REPL from terminal?

thheller23:08:10

try <meta charset="utf-8"> if its not in your HTML. wouldn't be the first time this fixed something.

thheller23:08:25

shadow-cljs cljs-repl client or just shadow-cljs node-repl or browser-repl

Pavel Klavík23:08:20

it works fine from cljs-repl from terminal

thheller23:08:06

maybe weird encoding in cursive then? I don't have a clue, the nrepl I tested was also in cursive.

Pavel Klavík23:08:27

I have this in my HTML:

<meta charset='utf-8'>

Pavel Klavík23:08:45

I will try to update Cursive to see whether it won't fix it