Fork me on GitHub
#nbb
<
2022-10-17
>
Luke Zeitlin09:10:23

noobish question: What's the right way to require another cljs file / script into an nbb script? Do i need to load-file and also add it to the ns definition require form? Want to have some util functions defined in a separate (adjacent) file and pull them in. For some reason this is working locally but doesn't when running in a node docker image in CI

borkdude09:10:54

@larzeitlin Just require or via :require in the ns form

borkdude09:10:49

Node docker image in CI: What does the directory look like of the project and are you executing it from the local directory of that project?

Luke Zeitlin09:10:39

so I'm calling yarn nbb from the root of the project specifying the cwd in the yarn command eg: yarn --cwd test/e2e nbb run_tests.cljs . Doing this both locally and in CI

Luke Zeitlin09:10:19

If I do this locally it works fine but only if I (load-file ...) as well as require

Luke Zeitlin09:10:39

In CI i get could not find namespace ... regardless

Luke Zeitlin09:10:31

all nbb script files are in test/e2e/ along with a package.json

borkdude09:10:56

Perhaps you could try:

( cd test/2e2 && yarn nbb run_tests.cljs )

borkdude09:10:15

I suspect there is something weird with yarn --cwd

Luke Zeitlin09:10:16

even locally running from e2e directory I get could not find namespace

borkdude09:10:54

is this a public project so I can have a look?

borkdude09:10:59

or perhaps you can make a repro that is public

borkdude09:10:40

is nbb also installed in the package.json in the e2e directory?

👍 1
Luke Zeitlin09:10:42

you can get the error by running yarn install and then yarn nbb run_tests.cljs

Luke Zeitlin09:10:02

thanks for having a look 🙏

borkdude09:10:37

It tries to load a namespace called e2econfig

borkdude09:10:40

which is not in the repo?

borkdude09:10:15

namespace names should be called according to the directory structure you are in

Luke Zeitlin09:10:57

oh yeah, sorry - i just pulled it out of the project. Can rename the root directory e2e and it should match up

borkdude09:10:14

What I mean is that when you are in directory $cwd and your namespace is called e2e.foobar , then the source should look like this: $cwd/e2e/foobar.cljs , not $cwd/foobar.cljs

borkdude09:10:46

But you can probably "fix" this by adding the parent directory to the classpath with nbb --classpath ..

borkdude09:10:12

Another issue is that load-file isn't "awaited" automatically

borkdude09:10:18

so you're running two things in parallel

borkdude09:10:41

So it's better to do this:

(ns e2e.run-tests
  (:require [nbb.core :refer [load-file await]]))

(require '[login-test])
(require '[map-test])

;; or:

(await (load-file "login_test.cljs"))
(await (load-file "map_test.cljs"))

borkdude09:10:55

I can make load-file auto-awaited though, please file an issue for that

borkdude09:10:16

Does this make sense?

borkdude09:10:19

Maybe nbb could support (:require ["./foo.cljs"]) as well ;) But that would be similar to load-file

Luke Zeitlin10:10:37

makes sense. Just checking that the ns renames (and not running load-file in parallel) fixes things

Luke Zeitlin10:10:54

all fixed! Many thanks @U04V15CAJ 🙏 will file an issue for load-file auto-await

👍 1