Fork me on GitHub
#clojurescript
<
2016-10-30
>
keatondunsford00:10:18

Hey y’all. 🙂 Quick non-scientific poll question: I’m starting a new ClojureScript project with Om Next, and haven’t really been able to find any new blog posts, Reddit threads or tweets on the best Clojure server-side framework for React/React-Native CLJS apps as of late 2016. I did see both the Om Next demo, CircleCi’s frontend and the Precursor app now open-sourced all use Ring. But I’m not sure if there’s a general consensus now given all the activity in the community as of late, if one were to start a new Om Next project from scratch, what the simplest (in Rich Hickey/David Nolen terms) framework of choice is now. Pedestal has the backing of Cognitect, Arachne is almost ready for alpha, and new things like Duct and Luminus have popped up, etc. Thoughts on if Ring is still the way to go? Would seriously appreciate any input for a newbie. 🙂 Thanks in advance!

richiardiandrea02:10:44

@keatondunsford it is really tough to answer to these kind of questions, there is a mix of things in it. Probably the first thing to understand for you would be if you want to go for a pre-packaged solution or not. By pre-packaged I mean luminus or pedestal mainly, which are super battle tested. The other option is to just adding libs to a bare-bone project, which might be scary but for sure more rewarding in terms of understanding what the moving parts are. Additionally, if you are going for a REST app, ring can be a good choice if you want to take the super safe way. An alternative to the ring architecture is yada. I am sure I am forgetting many other alternatives actually but these are the ones I went for in the last two years+ of my Clojurism 🙂 Last piece of advice I can give is to ask as well to #beginners.

keatondunsford02:10:13

I’ll totally do that. 🙂 My intuition is to trust whatever Cognitect is backing. Counterargument I guess would be to use whatever is the most composable, which sounds like it’s Ring. Kind of like the Boot > Leiningen argument for long-term projects.

richiardiandrea02:10:31

@keatondunsford right, that's a good analogy 😄 It also depends on what is the scope of your app and many other things, I kept my answer very short 😉

keatondunsford02:10:37

Haha yeah for sure. 🙂 If this project does go well, which is the intention, I am hoping to scale it and take it on as a startup. The high-level concept I’m working on is to essentially build “Reddit meets Snapchat stories and Tinder” for creating project-based communities around video tutorials on any subject (like building flying cars, or making rap beats, or a new VR video game), and then try and connect people physically who are near each other’s locations and want to make the same cool things together in person. So architecture wise, I’ve been looking into separating a lot of the different backend pieces via microservices in Dockerized containers all connected by RESTful APIs. Which it sounds like Pedestal is sort of designed for out-of-the-box.

richiardiandrea02:10:48

I have not used pedestal yet in a project so I can't comment on that. Just one thing I would suggest, as Rich said, not everything is awesome..so I'd evaluate very very deeply how it has been designed before a buy-in. Of course, if it matches your requirements above, then it is the right choice for you 😉

keatondunsford02:10:37

Sounds good. 🙂 Thanks so much for the help!

richiardiandrea02:10:32

you're welcome! 🙂

cl0jurian06:10:27

Hi guys; I would be glad to know if there is a non interop method to load css or js resourses ?

thedavidmeister07:10:35

is it possible to eval cljs from js?

cl0jurian07:10:17

@thedavidmeister I'm not sure we can. I've used only "^:export" though.

thedavidmeister08:10:32

mmm that’s cool

thedavidmeister08:10:47

i just wanted to be able to run some cljs with selenium >.<

cl0jurian08:10:41

@thedavidmeister ya it would be redundant to use klipse plugin. I wonder you could use selenium cljs plugins to do that. It's just a suggestion infact I haven't done that.

thedavidmeister08:10:02

not sure, i know that i can execute js

thedavidmeister08:10:50

i wondered if i could do something like (execute-script “cljs.core.eval(‘(prn 1)’)”)

thedavidmeister08:10:03

but that doesn’t work

darwin08:10:33

@thedavidmeister: there is no cljs.core.eval, think about this: macros in ClojureScript are written in Clojure, so you need JVM+Clojure to translate arbitrary ClojureScript snippets to Javascript code snippets. You could use Bootstrapped ClojureScript, but as you pointed out, this might be an overkill. Why don’t you compile the code snippets you want to run the usual way via leiningen or boot and then execute them in selenium as Javascript?

thedavidmeister09:10:07

@darwin i’m trying to test some code i wrote that relies on the js/window object, do you think this is a good way to approach that?

darwin09:10:13

@thedavidmeister I’m sorry, I don’t understand your question. What is “this way”? And how is code which relies on js/window different from any other code from the testing point of view?

thedavidmeister09:10:31

@darwin well, normally when i test some clj or cljs i can pass data to the functions i’m testing and see what comes back

thedavidmeister09:10:39

but js/window comes from the browser the js runs in

thedavidmeister09:10:48

so not sure how to “get at” it

darwin09:10:31

I assume you are using something like phantomjs or selenium. Your tests written in cljs are compiled into Javascript. And you are executing that Javascript code when running phantom/selenium. Nothing is preventing you writing cljs code working with js/window, because resulting generated Javascript will run in an environment where js/window is available.

darwin09:10:34

Or am I missing something?

thedavidmeister09:10:46

tests are written in clj

darwin09:10:22

aha, so you are using clj-webdriver to automate chrome, that is a different story

thedavidmeister09:10:59

actually it’s just a bit slow and tests can be flaky

thedavidmeister09:10:12

so i wanted to start looking at alternatives, for at least some of the tests i wrote this way

darwin09:10:57

you have to use clj-webdriver’s api to query browser state, I’m not aware of any way how to inspect js/window properties without writing Javascript, which would be sent to chrome instance (e.g. via clj-webdriver)

thedavidmeister09:10:23

was looking at execute-script

thedavidmeister09:10:47

which led to me needing to write js, which led to me asking if i could eval cljs from js...

darwin09:10:37

as I wrote above, you could write a separate cljs project, which will compile your cljs to js, and then you can execute that js

darwin09:10:14

for inspiration, here is my phantomjs setup: a) I have a separate cljsbuild for tests project[1] b) I use cljs.test to write my tests (compiles to Javascript), record test failures here [2] c) use this minimal phantom.js boilerplate [3] [1] https://github.com/binaryage/cljs-devtools/blob/305325de0208a91f44702b32f3441154d2caca5d/project.clj#L53-L60 [2] https://github.com/binaryage/cljs-devtools/blob/305325de0208a91f44702b32f3441154d2caca5d/test/src/tests/devtools/runner.cljs#L70 [3] https://github.com/binaryage/cljs-devtools/blob/305325de0208a91f44702b32f3441154d2caca5d/test/resources/phantom.js#L24

darwin09:10:51

If you wanted to stay using clj-webdriver, you could do something what I did in dirac. You could automate chrome via clj-webdriver to open a page with your tests (again those tests must be in cljs) and then somehow check results via clj-webdriver, it could be as simple as a flag with result code, or something fancy like sending some kind of transcript back and comparing it to expected results: (for inspiration) https://github.com/binaryage/dirac/blob/767bff32d143fb5977d4ca8a6fc204ec33f5a8e6/test/browser/src/browser_tests/dirac/tests/browser/tasks/transcript.clj#L71 https://github.com/binaryage/dirac/tree/767bff32d143fb5977d4ca8a6fc204ec33f5a8e6/test/browser/transcripts/expected

thedavidmeister09:10:02

@darwin thanks 🙂 lots for me to look at

thedavidmeister09:10:38

@darwin i’m not wedded to clj-webdriver, it just seemed like a straightforward way to get up and running for testing my app

darwin09:10:52

think about your clj code (clj-webdriver) just as “glue code” for automating chrome, not as real tests, real tests must be written in cljs and compiled to javascript

thedavidmeister09:10:28

what do you mean by “real tests”?

darwin09:10:32

real test for example goes and checks if js/window has expected properties you added to it, you cannot do this from clj-webdriver without writing javascript

darwin09:10:27

clj-webdriver allows you to check if DOM has some selector present, or retrieve content of the page, you can do some testing this way, but it is not matching full power of javascript running inside the page

thedavidmeister09:10:27

oh right, as in, tests that aren’t treating the cljs being run as a “black box"

thedavidmeister09:10:23

@darwin well, i guess it’s time for me to look at upgrading my test suite then 😉

thedavidmeister09:10:38

i am starting to hit walls with what i have atm

darwin09:10:43

if you don’t need latest chrome features, I would pick phantomjs, it is easier than selenium (and head-less)

thedavidmeister09:10:38

if i’m just testing individual components of the app, which i will be able to, i don’t think i need chrome

jell10:10:06

@thedavidmeister you might want to look at lein-doo to run front-end unit tests (https://github.com/bensu/doo)

thedavidmeister10:10:54

thanks, i’m using boot-cljs-test atm for unit tests

jell10:10:52

and for integration test, I use a fixture that compiles our app using cljs.build.api/build together with clj-webdriver

jell10:10:05

(if that doesn’t help at least maybe I get feedback on our own setup :p)

thedavidmeister10:10:40

i’m not having any troubles building my app and running clj-webdriver against it with boot 🙂

jell10:10:21

oh then sorry misunderstood the question :s

thedavidmeister10:10:23

the thing i’m not doing is running my tests alongside the code run in the browser then exporting the results of the tests back to boot

thedavidmeister10:10:41

so i have the same access to the code that i have when running the unit tests, but i’m interacting with the code within the browser @jell

p-himik15:10:13

In production I'm using :optimizations :advanced and in one of my cljs files I'm using .getBrowserEvent on an instance of goog.events.BrowserEvent. I've added goog.events.BrowserEvent to :import in my namespace definition, but .getBrowserEvent is still referred by its full name, whereas in goog libraries it's being minificated. Is there anything I can do to force this minification on .getBrowserEvent?

darwin15:10:50

@p-himik: aren't you referring to getBrowserEvent by string name?

p-himik15:10:44

Nope, regular dot operator.

darwin15:10:43

another theory: there could be an extern covering getBrowserEvent, but that should cause goog libraries to behave the same as your own code, I think

p-himik15:10:27

Indeed it should, as far as I understand the externs.

p-himik15:10:43

A piece of code that I use:

(fn [evt]
  (prevent-default evt)
  (stop-propagation evt)
  (h (oget (.getBrowserEvent (raw-event evt)) :dataTransfer))
  ;(h (-> evt raw-event .getBrowserEvent (oget :dataTransfer)))
  )
neither of the two last lines work - both calls to .getBrowserEvent are not minificated.

p-himik15:10:37

Oh wow, please disregard all that. My stupidity doesn't know its limits.