This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-10-20
Channels
- # aws-lambda (7)
- # beginners (113)
- # boot (17)
- # cider (4)
- # cljs-dev (4)
- # clojure (65)
- # clojure-greece (3)
- # clojure-italy (7)
- # clojure-russia (10)
- # clojure-spec (37)
- # clojure-uk (20)
- # clojurescript (76)
- # community-development (2)
- # cursive (24)
- # data-science (9)
- # datomic (9)
- # emacs (1)
- # fulcro (2)
- # graphql (11)
- # hoplon (13)
- # juxt (15)
- # leiningen (1)
- # off-topic (36)
- # om (1)
- # onyx (59)
- # parinfer (41)
- # pedestal (7)
- # portkey (60)
- # protorepl (4)
- # re-frame (345)
- # reagent (7)
- # ring-swagger (16)
- # shadow-cljs (121)
- # spacemacs (30)
- # sql (6)
- # uncomplicate (2)
- # unrepl (9)
- # vim (13)
- # yada (2)
how can I require all namespaces that match a regex? (all-ns)
isn't a thing in clojurescript, right?
you'd ask why? it seems honzabrecka/karma-reporter
's run-all-tests
doesn't work like clojure.test/run-all-test
- the former requires test ns' be required explicitly. That's tedious.
good observation I once tried to create a macro for this, but doo didn't accept it (gave me some opaque error)
I'm not using doo explicitly - I'd like to try using karma-reporter directly (which doo does anyway). I'd like to have karma server running in background and a separate task to run the tests
I've been trying to make sense of our testing setup. But it's been painful, (partly because we use boot) Ideally I want: 1) Karma server running chrome-headless in a container 2) watch task that would poke Karma to run the tests whenever the code changes 3) Since Karma already running browser, theoretically there has to be a way to get a repl
right now it's too slow; it is a pain to get it running on CI; you still need a repl to write the tests, but using clojure.test/run-tests in browser repl is kinda wanky
As for requires, you can explore the macro path. Ultimately you always can write a little program which builds and writes my_test_runner.cljs
with all the boilerplate
As for need for repl, I switch between chrome
and chrome-headless
which doo makes easy. I leave these doo tests running in auto
mode; that's my L
part of the 'REPL' experience
occasionally I need to inspect the DOM, in those cases I (<! (timeout 100000000000))
in the middle of a test
the (timeout 100000000000)
could be changed for something more sophisticated, my setup isn't quite refined yet. But overall happy with it
is there a crypto api wrappers for CLJS ?
@vemv @ag I always thought that doo-all-tests
also needs the ns-es already required
hi 👋 Having a spot of trouble with a JS module under advanced compilation. I feel like I've solved this exact problem before, but it's eluding me atm
I'm using https://www.npmjs.com/package/viz.js successfully in figwheel REPLs, but its module usage isn't being recognized/adapted when minified into a single JS file
it's a little wonky to my eye, and specifying a :module-type in a deps.cljs file doesn't help: if (typeof module === "object" && module.exports) { module.exports = Viz; } else { global.Viz = Viz; }
ofc, I can reach in and grab the Viz object and everything's fine, but if there's a better way, do tell 🙂
@cemerick you mean using js/window.Viz
? That's the normal (classic) way of using JS dependencies
what's your concern with that?
@pesterhazy well, I'm testing under node using doo, so it'd actually be js/module.exports.Viz, but that isn't going to fly for the same code in the REPL
won't js/goog.global.Viz
work in both cituations?
I have this in my deps.cljs, so (:require vizjs) and js/Viz works nicely in the REPL: {:file "viz.js/viz-lite.js" :provides ["vizjs"]}
@pesterhazy I'll give goog.global.Viz a try
though I have a number of npm deps with entries in deps.cljs that do get transformed as I'd expect...though they're all es6 style, it seems
--- node_modules/viz.js/viz.js:47
Object literal contains illegal duplicate key "stackAlloc", disallowed in strict mode
--- node_modules/viz.js/viz.js:47
Object literal contains illegal duplicate key "stackSave", disallowed in strict mode
--- node_modules/viz.js/viz.js:47
Object literal contains illegal duplicate key "stackRestore", disallowed in strict mode
--- node_modules/viz.js/viz.js:47
Object literal contains illegal duplicate key "establishStackSpace", disallowed in strict mode
--- node_modules/viz.js/viz.js:47
Object literal contains illegal duplicate key "setThrew", disallowed in strict mode
@pesterhazy goog.global.Viz doesn't work. goog.global is the same as this
in the single-file testing case, so it's actually no different than js/Viz
@thheller so are you thinking that that's what's tripping up the module transform. I don't have any strict mode on atm BTW
lein-cljsbuild's {:compiler {:closure-defines {my.ns.myvar "asdf"}}}
a la https://www.martinklepsch.org/posts/parameterizing-clojurescript-builds.html just doesn't seem to work for me
@martinklepsch ^^ is there a trick to it? does it work with simple optimizations?
@pesterhazy not sure about simple
@martinklepsch advanced also doesn't seem to work for me
@pesterhazy have you tried my.ns.myvar
as a string? "my.ns.myvar"
this usually works for me
I found the problem
my actual variable was called my.ns/app-url
- this needs to be mangled into "my.ns.app_url"
I found working with :external-config is much saner than using goog defines
@metametadata interesting - could you elaborate?
yeah, I'm googling 🙂
I first saw it in @darwin's libs
Anyways. From my project.clj
:
:compiler {... :external-config {:myapp {:debug? false}}}
then in code:
(ns app.config
"Compilation time app configuration."
(:require [cljs.env :as env]
[schema.core :as s]))
(s/defschema Env
{:debug? s/Bool})
(s/defn ^:always-validate -config :- Env
[]
(when (some? env/*compiler*)
(get-in @env/*compiler* [:options :external-config :myapp])))
(defmacro if-debug
"Emits expression based on the value of debug flag in project's compiler options."
([then]
`(if-debug ~then nil))
([then else]
(if (:debug? (-config))
then
else)))
(defmacro when-debug
[& body]
`(if-debug (do ~@body)))
And then usage:
(defn main
[]
(app-config/when-debug
(.warn js/console "App debug mode is ON.")
(s/set-fn-validation! true))
,,,)
Interesting! that looks like CLJS compiler internals. Is "external-config" a public API?
AFAIU yes, e.g. figwheel validator allows it
I'll check it out, thanks @metametadata
@martinklepsch I think mentioning the name mangling problems would be a useful addition to your blog post (also simple optimizations work fine, as well as advanced)
@pesterhazy the compiler mangles for you but you have to pass in the correct symbol
@pesterhazy good point
**Note:** Sometimes for debugging you may want to pass the the Closure
define as a string. If you decide to do so make sure it matches the
string in the `goog.define` call in your emitted Javascript
(i.e. account for name mangling).
like this?I just tried again and it looks like @thheller is right - the names are mangled correctly if you pass a symbol
@martinklepsch I think that's very clear, yes!
s/the the/the/ though
my debugging was flawed because lein cljsbuild
sometimes doesn't rebuild even though I ran lein clean just before that
For years I have had the habit of removing all build artifacts like out/* as well as the main compiled JavaScript file by deleting at the shell before compiling an optimized build. I just never found any other way to ensure a proper build.
thanks for the feedback, post has been updated 👍
For years I have had the habit of removing all build artifacts like out/* as well as the main compiled JavaScript file by deleting at the shell before compiling an optimized build. I just never found any other way to ensure a proper build.