This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-06-01
Channels
- # announcements (7)
- # babashka (72)
- # beginners (62)
- # biff (1)
- # calva (9)
- # cider (8)
- # clj-kondo (35)
- # clj-otel (8)
- # cljsrn (11)
- # clojure (98)
- # clojure-europe (25)
- # clojure-germany (1)
- # clojure-norway (9)
- # clojure-uk (2)
- # clojured (3)
- # clojurescript (12)
- # conjure (3)
- # core-logic (4)
- # cursive (18)
- # datalevin (9)
- # datomic (5)
- # defnpodcast (2)
- # exercism (1)
- # graalvm (5)
- # gratitude (6)
- # hyperfiddle (3)
- # interop (12)
- # jobs (1)
- # joyride (34)
- # lsp (22)
- # meander (14)
- # missionary (16)
- # nbb (88)
- # off-topic (4)
- # pathom (20)
- # podcasts-discuss (1)
- # polylith (13)
- # portal (10)
- # re-frame (6)
- # releases (2)
- # remote-jobs (2)
- # rewrite-clj (3)
- # shadow-cljs (3)
- # spacemacs (6)
- # vim (24)
I changed the orginal ns
and put it into a test
folder
(ns modulr-test
(:require
[cljs.test :as t :refer [async deftest is testing]]
[promesa.core :as p]))
(deftest awesome-test
(testing "one equals one"
(is (= 1 1)))
(testing "this test will fail"
(is (= 1 2))))
;; run this function with: nbb -m example/run-tests
(defn run-tests []
(t/run-tests 'modulr-test))
@raymcdermott Which version of nbb are you using?
Message: Cannot find module '/home/ray/xxx/repos/ops-modulr/signature' imported from /home/ray/xxx/repos/ops-modulr/script.cljs
@raymcdermott CLJS files aren't imported through string
$ ls -R src test *js *.json *.edn
auth.mjs aws.mjs borrowers.mjs deps.edn package.json package-lock.json pending.mjs
src:
auth.cljs aws_secrets.cljs borrowers.cljs config.cljs modulr.cljs pending.cljs signature.js
test:
auth_test.cljs modulr_test.cljs
@raymcdermott I recommend doing it like this. A test_runner.cljs
in the root which sets the classpath to src:test
and then requires your test namespaces and runs them
I'll try to make a public version over the weekend cos the signature code is public and so it wouldn't break any confidences
yeah, or just minimal repro repository with some silly functions and one JS file that you want to load
@raymcdermott I figured it out. So:
$ find .
.
./test
./test/runner.cljs
./init.cljs
./package.json
./src
./src/dude.mjs
./src/foo.cljs
$ cat src/foo.cljs
(ns foo
(:require ["./src/dude.mjs$default" :as dude]))
(defn doit [_]
(prn :done))
(defn -main [& _]
(js/console.log dude))
$ cat src/dude.mjs
export default {"hello": true};
$ cat test/runner.cljs
(ns runner
(:require
["./src/dude.mjs$default" :as dude]
[foo]))
(defn -main [_]
(println "Testing")
(foo/doit {})
(prn dude))
$ nbb -cp src:test -m runner
Testing
:done
#js {:hello true}
$ nbb -cp src -m foo
{ hello: true }
The crux is to, when using the classpath option, do not invoke nbb -cp .. src/foo.cljs
but use nbb -cp .. -m foo
and JS files have to be loaded via the full path relative to the working directory, since the classpath only affects loading of CLJS namespaces
Now that I think about it, it would perhaps be more intuitive if, when requiring js files like ./foo.js
it would be relative to the script
it can make it work for both cases if I cd test && npx nbb --classpath ../src -m auth-test/run-tests
@U04V15CAJ I'll try to produce a smaller though representative version of what I have for your experimentation
actually this is how I'm doing it now cd src && npx nbb --classpath ../test -m auth-test/run-tests
@raymcdermott nbb 0.5.104 is now building with the fix
Well, the only fix I applied was:
(path/resolve (path/dirname @sci/file) libname)
So I don't think I'm adding or removing any .js
or .mjs
extensions, just modifying the relative dir to an absolute dir