Fork me on GitHub
#shadow-cljs
<
2018-08-21
>
urbanslug06:08:06

Oh really? I didn't know about that second part

thheller07:08:43

anyone with access to s3 repos around?

chrisetheridge09:08:22

➜  Manage git:(shadow-cljs) ✗ shadow-cljs browser-repl app
shadow-cljs - config: /Users/chrisetheridge/code/Cognician/Manage/shadow-cljs.edn  cli version: 2.6.2  node: v10.8.0
shadow-cljs - connected to server
ClassNotFoundException shadow.cljs.devtools.cli  java.net.URLClassLoader.findClass (URLClassLoader.java:381)
on the new version?

chrisetheridge09:08:01

hmm nvm. doing a new build sorted it out

thheller09:08:21

ah maybe you had the server running and deleted some .m2 files or .shadow-cljs?

chrisetheridge09:08:25

don’t think so, but highly possible

this.rob10:08:35

Hey all. Having some trouble with express using advanced optimizations. Error handling middleware (4 arity functions) are being compiled to 3 arity functions if the last arg (`next`) is not used e.g. in the case where we want to finish handling the request and send the response from within that middleware function. Because express uses the arity of the middleware to determine that it is an error handling middleware, when we are running the app with advanced optimizations this middleware is not being called as it should when an error is thrown from one of our routes.

this.rob10:08:01

we are wondering what the best way to prevent the dropping of the last arg would be...

kwladyka12:08:33

example of code will help a lot to understand you issue

kwladyka12:08:10

I have this error when try to load namespace in Cursive: CompilerException java.lang.RuntimeException: No such var: s/explain-data, compiling: with code

(defn- value->spec-msg [specs->msg spec value]
  "Check value with spec.
  If fail return msg error."
  (-> (s/explain-data spec value)
      (get-in [:cljs.spec.alpha/problems 0 :via])
      (last)
      specs->msg))
But I have it in :require and it works in webbrowser
(ns services.form
  (:require [cljs.spec.alpha :as s]
            [reagent.core :as r]
            [taoensso.timbre :as l]))
How can I use REPL cljs in Cursive in friendly way?

thheller12:08:59

@kwladyka remember that the REPL you connect to in Cursive starts as a Clojure REPL. you need to switch it to CLJS first.

kwladyka12:08:45

But what can be important I am in node-test REPL

thheller12:08:55

@rs the only thing I can think of at the moment is using goog.reflect. You can call (gr/sinkValue next) as the first thing in the function. it doesn't actually do anything besides telling the compiler that the next should be kept and not removed.

thheller12:08:41

@kwladyka CompilerException java.lang.RuntimeException: No such var: s/explain-data, compiling: pretty sure that you get this error when in a Clojure REPL

kwladyka12:08:42

What I want to achieve: during write tests I often use REPL to check code during write tests / code of functions

thheller13:08:18

I assume you connected to the REPL remotely

thheller13:08:41

then called (shadow/repl :your-build)

thheller13:08:46

then eval'd whatever

kwladyka13:08:18

hmm you are right, for some reason I am not in CLJS REPL…. hmm I was in :app instead :node-test REPL

kwladyka13:08:03

thank you, the simplest things always make the harder issues 🙂

thheller13:08:03

yeah the REPL UI in Cursive it not that obvious unfortunately

thheller13:08:12

easy to confuse which state you are in

kwladyka13:08:13

No application has connected to the REPL server. Make sure your JS environment has loaded your compiled ClojureScript code.
Oh but I see I can’t use node-test with cljs REPL ?

kwladyka13:08:59

this appear when i try to run a code

thheller13:08:46

:node-test isn't really meant for REPL development since its supposed to exit after running your tests

thheller13:08:53

you can use (shadow/node-repl) instead

kwladyka13:08:23

(shadow/node-repl)
To quit, type: :cljs/quit
=> [:selected :node-repl]
Loading test/services/form_test.cljs... repl/require failed { Error: ENOENT: no such file or directory, open '/Users/kwladyka/Library/Mobile Documents/com~apple~CloudDocs/storage/Projects/content-manager-fe/.shadow-cljs/builds/node-repl/dev/out/cljs-runtime/shadow.test.env.js'
    at Object.openSync (fs.js:443:3)
    at Object.readFileSync (fs.js:348:35)
    at global.SHADOW_IMPORT ([stdin]:45:15)
    at Object.shadow$cljs$devtools$client$node$closure_import [as closure_import] (/Users/kwladyka/Library/Mobile Documents/com~apple~CloudDocs/storage/Projects/content-manager-fe/.shadow-cljs/builds/node-repl/dev/out/cljs-runtime/shadow/cljs/devtools/client/node.cljs:33:4)
    at Object.shadow$cljs$devtools$client$node$repl_require [as repl_require] (/Users/kwladyka/Library/Mobile Documents/com~apple~CloudDocs/storage/Projects/content-manager-fe/.shadow-cljs/builds/node-repl/dev/out/cljs-runtime/shadow/cljs/devtools/client/node.cljs:61:7)
    at shadow$cljs$devtools$client$node$process_message (/Users/kwladyka/Library/Mobile Documents/com~apple~CloudDocs/storage/Projects/content-manager-fe/.shadow-cljs/builds/node-repl/dev/out/cljs-runtime/shadow/cljs/devtools/client/node.cljs:122:6)
    at Object.shadow$cljs$devtools$client$env$process_ws_msg [as process_ws_msg] (/Users/kwladyka/Library/Mobile Documents/com~apple~CloudDocs/storage/Projects/content-manager-fe/.shadow-cljs/builds/node-repl/dev/out/cljs-runtime/shadow/cljs/devtools/client/env.cljs:148:10)
    at WebSocket.<anonymous> (/Users/kwladyka/Library/Mobile Documents/com~apple~CloudDocs/storage/Projects/content-manager-fe/.shadow-cljs/builds/node-repl/dev/out/cljs-runtime/shadow/cljs/devtools/client/node.cljs:159:12)
    at WebSocket.emit (events.js:182:13)
    at Receiver._receiver.onmessage (/Users/kwladyka/Library/Mobile Documents/com~apple~CloudDocs/storage/Projects/content-manager-fe/node_modules/ws/lib/WebSocket.js:141:47)
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path:
   '/Users/kwladyka/Library/Mobile Documents/com~apple~CloudDocs/storage/Projects/content-manager-fe/.shadow-cljs/builds/node-repl/dev/out/cljs-runtime/shadow.test.env.js' }
Not so easy

thheller13:08:04

ah which version are you on? I broke node-repl in 2.4.33 I think

thheller13:08:08

might have been .32

thheller13:08:12

is fixed in 2.6.2

kwladyka13:08:45

(shadow/node-repl)
To quit, type: :cljs/quit
=> [:selected :node-repl]
Loading src/services/form.cljs... done
Loading test/services/form_test.cljs... done
(-> {:names->value {:email ""
                              :password ""}
               :names->validations {:email [::spec-email]
                                    :password [::spec-password test-fn]}
               :specs->msg {::spec-email "Typo? It doesn't look valid."
                            ::spec-password "Password is required."}}
              (form/init-form))
(node:9656) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
<eval>:1
form.init_form(new cljs.core.PersistentArrayMap(null, 3, [new cljs.core.Keyword(null,"names->value","names->value",-1214004968),new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"email","email",1415816706),"",new cljs.core.Keyword(null,"password","password",417022471),""], null),new cljs.core.Keyword(null,"names->validations","names->validations",-1835037433),new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"email","email",1415816706),new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword("cljs.user","spec-email","cljs.user/spec-email",1595736430)], null),new cljs.core.Keyword(null,"password","password",417022471),new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword("cljs.user","spec-password","cljs.user/spec-password",1742175166),cljs.user.test_fn], null)], null),new cljs.core.Keyword(null,"specs->msg","specs->msg",1137057203),new cljs.core.PersistentArrayM

ReferenceError: form is not defined
    at <eval>:1:1
    at Script.runInThisContext (vm.js:91:20)
    at runInThisContext (vm.js:298:38)
    at global.SHADOW_NODE_EVAL ([stdin]:74:30)
    at Object.shadow$cljs$devtools$client$node$node_eval [as node_eval] (/Users/kwladyka/Library/Mobile Documents/com~apple~CloudDocs/storage/Projects/content-manager-fe/.shadow-cljs/builds/node-repl/dev/out/cljs-runtime/shadow/cljs/devtools/client/node.cljs:25:16)
    at /Users/kwladyka/Library/Mobile Documents/com~apple~CloudDocs/storage/Projects/content-manager-fe/.shadow-cljs/builds/node-repl/dev/out/cljs-runtime/shadow/cljs/devtools/client/node.cljs:48:30
    at Object.shadow$cljs$devtools$client$env$repl_call [as repl_call] (/Users/kwladyka/Library/Mobile Documents/com~apple~CloudDocs/storage/Projects/content-manager-fe/.shadow-cljs/builds/node-repl/dev/out/cljs-runtime/shadow/cljs/devtools/client/env.cljs:91:16)
    at Object.shadow$cljs$devtools$client$node$repl_invoke [as repl_invoke] (/Users/kwladyka/Library/Mobile Documents/com~apple~CloudDocs/storage/Projects/content-manager-fe/.shadow-cljs/builds/node-repl/dev/out/cljs-runtime/shadow/cljs/devtools/client/node.cljs:48:13)
    at shadow$cljs$devtools$client$node$process_message (/Users/kwladyka/Library/Mobile Documents/com~apple~CloudDocs/storage/Projects/content-manager-fe/.shadow-cljs/builds/node-repl/dev/out/cljs-runtime/shadow/cljs/devtools/client/node.cljs:116:6)
    at Object.shadow$cljs$devtools$client$env$process_ws_msg [as process_ws_msg] (/Users/kwladyka/Library/Mobile Documents/com~apple~CloudDocs/storage/Projects/content-manager-fe/.shadow-cljs/builds/node-repl/dev/out/cljs-runtime/shadow/cljs/devtools/client/env.cljs:148:10)

kwladyka13:08:26

When shift + cmd + p to run code in REPL

thheller13:08:29

probably in the wrong namespace

thheller13:08:11

I don't know if thats my mistake or cursive but for CLJS you need to manually switch the ns

thheller13:08:20

(in-ns 'whatever) or the REPL hotkey

kwladyka13:08:06

with manual switch it works, thx

kwladyka13:08:25

BTW @thheller I will be 6-10 in Berlin. Would you like to have a bear / tea if you are somewhere around?

thheller13:08:28

bit too busy for a trip to berlin. thats still 400km away for me 😛

kwladyka13:08:31

Oh I had hope maybe you live somewhere around

heyarne13:08:16

is it possible to set up rebel-readline with a shadow-cljs cljs-repl?

thheller13:08:34

I don't know. Didn't look into it yet.

thheller13:08:45

CLJ should work out of the box but CLJS is a bit more complicated

👍 4
kwladyka14:08:30

How to simulate webbrowser input changes in shadow-cljs? I just described my needs on #clojurescript

this.rob15:08:42

@thheller thanks for the suggestion re: using goog.reflect. Its a shame the removal of unused args can't be turned off in the closure compiler to preserve arity!

thheller15:08:17

well its rather weird for JS functions to check arities of the declared function

this.rob15:08:27

yes agreed. That's express...

justinlee17:08:23

yea it’s actually not that unusual to check arities. there’s a whole style of programming that will, for example, return a promise if you pass 2 args but use a callback if you pass 3. 🙂

thheller17:08:23

well thats different. that checks if the third arg was passed in at all which is normal

thheller17:08:02

but checking the arity of the function that was passed is rather weird imho

urbanslug18:08:57

Hey so I have a dir structure like

├── shadow-cljs.edn
├── src
├── test
└── yarn.lock
and according to the shadow-edn has:
:source-paths ["src" "test"]
:test {:target    :browser-test
         :test-dir  "resources/public/js/test"
         :ns-regexp "-test$"
         :devtools  {:http-port          8021
                     :http-root          "resources/public/js/test"}}

urbanslug18:08:25

and then I have test.app.core_test.cljs

urbanslug18:08:55

However, when I try to run my tests I keep getting a TBD

urbanslug18:08:02

basically my tests don't run

urbanslug18:08:09

I want to keep my tests out of src

urbanslug18:08:50

also I don't have a test runner because from the docs, shadow will use the default cljs one(s)?

urbanslug18:08:13

What am I missing?

urbanslug19:08:04

there's no /js/test.js

thheller19:08:58

@urbanslug I have trouble understanding what you are saying

thheller19:08:05

> However, when I try to run my tests I keep getting a TBD

thheller19:08:09

what? :browser-test you run by opening ?

thheller19:08:50

test.app.core_test.cljs would be in test/test/app/core_test.cljs right?

urbanslug19:08:49

I have app.core-test in` test/app/core_test.cljs`

urbanslug19:08:56

I am opening it in the browser now

urbanslug19:08:16

and get the 404 on js/test.js

thheller19:08:37

did you compile the tests?

urbanslug19:08:43

I wasn't doing this before > what? :browser-test you run by opening http://localhost:8021?

thheller19:08:52

shadow-cljs compile test

thheller19:08:58

or shadow-cljs watch test

thheller19:08:02

or shadow-cljs release test

urbanslug19:08:17

test i ran shadow-cljs watch test``

urbanslug19:08:21

but not compile

urbanslug19:08:28

let me run compile test and see

thheller19:08:29

watch is fine

urbanslug19:08:59

well I think compilation of the test failed becuse one of the required namespaces is missing

urbanslug19:08:05

in my src...

urbanslug19:08:18

makes sense now that I know that the test had to compile

thheller19:08:42

it should compile even without a single test

urbanslug19:08:17

ya I've been rewriting in re-frame and moving things about

urbanslug19:08:33

it won't compile

urbanslug19:08:38

missing namespaces and what not

thheller19:08:45

whats the error?

urbanslug19:08:02

the error is on my end

thheller19:08:07

I don't know what missing namespaces and what not means

urbanslug19:08:10

I'm renaming namespaces

urbanslug19:08:13

and moving them around

thheller19:08:13

I'm confused. So the only problem is that the watch didn't finish compiling? which explains why the js/test.js doesn't exist and your tests will only run once it completes

thheller19:08:45

everything around testing isn't exactly user friendly currently. it'll get better soon I hope.

urbanslug19:08:05

ya! > So the only problem is that the watch didn't finish compiling?

urbanslug19:08:16

I appreciate the effort

urbanslug19:08:27

I've done cljs with om now before figwheel and all

urbanslug19:08:32

this is a huge leap for me

urbanslug19:08:04

This should run successfully though, right?

(ns app.core-test
  (:require-macros [cljs.test :refer-macros [deftest testing is]])
  (:require [cljs.test :as t]
            [app.core :as core]))

(deftest fake-test
  (testing "fake description"
    (is (= 1 2))))

thheller19:08:38

assuming that the rest of your build compiles properly yes

urbanslug19:08:39

Uncaught TypeError: Cannot read property 'cljs$core$IFn$_invoke$arity$1' of undefined

urbanslug19:08:52

it compiled with many warnings

urbanslug19:08:02

but somehow seems not to have = defined

urbanslug19:08:05

from the error

urbanslug19:08:38

that's an error in the js console

urbanslug19:08:53

> Ran 0 tests containing 0 assertions. > 0 failures, 0 errors.

thheller19:08:55

what are the warnings

urbanslug19:08:50

ok sorry again

Use of undeclared Var app.core-test/deftest 

urbanslug19:08:00

I'm clearly missing the dep cljs.test

urbanslug19:08:09

and should add it to my edn

urbanslug19:08:04

wasted enough of your time lol

thheller19:08:35

no you shouldn't

thheller19:08:36

its on there

thheller19:08:53

here is all the example code you posted

thheller19:08:14

npx shadow-cljs watch test and open . runs totally fine without warnings

thheller19:08:21

I have no idea whatever else you are doing though

thheller19:08:50

Testing app.core-test

FAIL in (fake-test) (at http:438:85)
fake description
expected: (= 1 2)
  actual: (not (= 1 2))

Ran 1 tests containing 1 assertions.
1 failures, 0 errors.

thheller19:08:14

I used different source paths but that doesn't really matter

thheller19:08:43

also tweaked the requires a bit since :require-macros isn't necessary.

thheller19:08:46

(ns app.core-test
  (:require [cljs.test :as t :refer [deftest testing is]]
            [app.core :as core]))

urbanslug19:08:05

OK it has to be on my side

urbanslug19:08:21

I have 48 warnings so...

urbanslug19:08:17

gotta step away from this for a bit. It seems moving to re-frame won't be a quick thing haha

urbanslug19:08:22

I appreciate you testing that out for me

urbanslug19:08:27

that's a ton of help

urbanslug20:08:15

stashed my changes and redid it with just the tests (without all the move-to-reframe-code) and it works

urbanslug20:08:25

gotta stop crying wolf 😬

urbanslug20:08:47

and now I see this will likely not work in CI

thheller20:08:54

thats where karma comes into play

thheller20:08:19

or just :node-test

urbanslug20:08:00

have you used any for react?

urbanslug20:08:29

and btw I thought I saw warning when not explicitly using require-macros

urbanslug20:08:35

or it being deprecated

urbanslug20:08:51

I mean using refer-macros

thheller20:08:22

ah that was the problem yes

thheller20:08:31

you used :require-macros with :refer-macros

thheller20:08:49

its supposed to be :require-macros + :refer

thheller20:08:02

or :require + :require-macros

thheller20:08:11

but :require + :refer is just fine too

thheller20:08:39

I guess that could be considered a nsform bug if it doesn't complain about the combo of :require-macros + :refer-macros

thheller20:08:57

totally didn't see that at all

thheller20:08:35

the "automatic" :refer of macros doesn't always work as it depends on the namespace that declares the macro

thheller20:08:52

but it definitely works for cljs.test

urbanslug21:08:11

haha my messing around was good for something