This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-10-09
Channels
- # announcements (23)
- # asami (25)
- # babashka (38)
- # beginners (53)
- # calva (17)
- # clara (5)
- # clj-commons (1)
- # clj-kondo (18)
- # clojure (11)
- # clojure-europe (17)
- # clojure-france (1)
- # clojure-germany (5)
- # clojure-nl (2)
- # clojure-sg (4)
- # conjure (3)
- # deps-new (6)
- # fulcro (16)
- # off-topic (46)
- # pedestal (11)
- # react (2)
- # reagent (5)
- # reclojure (7)
- # rewrite-clj (1)
- # sci (18)
- # shadow-cljs (75)
- # sql (3)
- # xtdb (12)
Howdy, I'm trying to use Jest as a test runner in conjunction with shadow-cljs and I'm running into problems Here's a minimal repro https://github.com/pesterhazy/shadow-jest
Essentially it bombs out with
ReferenceError: goog is not defined
at call (../.shadow-cljs/builds/test/dev/out/cljs-runtime/goog/debug/error.js:15:1)
at SHADOW_IMPORT (out.js:62:44)
at Object.<anonymous> (out.js:1522:1)
Not knowing which target was appropriate, I picked :target :node-test
because the tests are intended to run in node and jsdom (with Testing Library).
Any help appreciated!
@pesterhazy for jest you likely want to use :target :npm-module
instead. :node-test
is pretty specific to run cljs.test in node. you can use :ns-regexp "-test$"
to get similar behavior as :node-test
with regards to which files are included
ah, cool - let me give that a try
FAIL dist-test/todomvc.app_spec.js
● Test suite failed to run
Your test suite must contain at least one test.
at onResult (../node_modules/@jest/core/build/TestScheduler.js:175:18)
at Array.map (<anonymous>)
and using this build config
{:target :npm-module
:ns-regexp "-spec$"
:output-dir "dist-test"}
hehe I was just typing that....
out of curiosity, have you tried jest with shadow before?
we're experimenting with it at Pitch, where we want to improve our frontend testing story
several people have asked in the past but I never got around to it. thanks for the repo, made it really easy to try 🙂
we got it to work with the :browser-test
target but that felt hacky and I thought there must be a better way
FAIL dist-test/todomvc.app_spec.js
✕ arithmetic (5 ms)
● arithmetic
expect(received).toBe(expected) // equality
Expected: 5
Received: 4
at Object.<anonymous> (todomvc/app_spec.cljs:9:27)
awesome!
i'm going to hack on it some more
I don't like the test syntax all that much but a few helper functions/macros might make that bearable
going to try to implement todomvc based on tdd using Jest + React Testing Library
yeah, we already have a wip wrapper ns for jest assertions
there could totally be a :target :jest
if needed but AFAICT :npm-module
seems to do everything you'd need
would you be open to a PR to the user guide once the dust settles?
it's quite fast on incremental builds in this minimal repo
PASS dist-test/todomvc.app_spec.js
✓ arithmetic (2 ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 0.578 s, estimated 1 s
Ran all test suites.
yeah first run seems slow but after that it appears to use some cache and only process actually changed files
I'm surprised all of this works with node's require()
etc - the combination of node's require()
and goog.provide etc is not something I can claim to understand
well :npm-module
basically creates some glue code to pretend we still have everything in the same global scope but actually don't
quite hacky but make CLJS/Closure output look like commonjs for the tools that need that
btw a mini bug report while i'm here
steps
• in the repo, run cp src/test/todomvc/app_spec.cljs src/test/todomvc/another_spec.cljs
• in the shadow terminal Resource does not have expected namespace
• compilation stops
• ok fair enough, need to fix the ns decl
• open that file in emacs and rename to (ns todomvc.another-spec)
expected
• now that I've fixed the ns decl, compilation works again
actual
• it doesn't compile, I need to ^C
and restart
• then it works
Back to implementing TodoMVC using TDD!
do you mean nREPL'ing into shadow?
hehe, I'm lazy with REPLs, I'm a bad Clojurist, but using the UI will work nicely
in CLJS I mostly rely on reloading, which often gives me 80% of what a REPL would
in Clojure I use (cider-eval-buffer)
and that's it
but I type a lot of stuff into the terminal repl, I'm weird that way
$ shadow-cljs clj-repl
shadow-cljs - config: /Users/user/pitch/shadow-jest/shadow-cljs.edn
shadow-cljs - connected to server
shadow-cljs - REPL - see (help)
To quit, type: :repl/quit
shadow.user=>
whoa I had no idea!
I'll use that a lot
how is this so fast?
it's like 10x faster than lein repl :client ....
yeah it is, but using lein as a mere nrepl client is already slow as molasses
so it's not using nREPL then?
ah, so much better
(sometimes I wonder how much damage lein and nREPL, with their slowness and complexity, have done to Clojure)
omg I just added a watch for the app build via the socket repl
(shadow.cljs.devtools.api/watch :app)
[:app] Configuring build.
[:app] Compiling ...
shadow is so nicely decomplected!
@pesterhazy The slowness of lein just comes from loading many dependencies every time, I think. A comparable tools.build program with clj can be equally slow, if you're not mindful about which deps you are bringing in in your namespace form.
I think most people complaining about slow startup of lein just have a user.clj
sitting on the classpath that contributes most of the slowness. Otherwise IMHO its fine.
Well, I think an argument can be made that lein
tries to do too may things, so it ends up not doing any of these well.
But of course I shouldn't have said "damage". We owe a lot to lein's original authors, and I'm in no position to complain, having written little in the way of OSS
I think Stu Halloway has a talk out where he says "don't type stuff into the repl" - I beg to disagree