nbb

2022-10-17T09:24:23.428309Z

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

borkdude 2022-10-17T09:24:54.564029Z

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

borkdude 2022-10-17T09:25:49.438539Z

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?

2022-10-17T09:28:39.214609Z

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

2022-10-17T09:29:19.997529Z

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

2022-10-17T09:29:39.912959Z

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

2022-10-17T09:30:31.375949Z

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

borkdude 2022-10-17T09:30:56.091169Z

Perhaps you could try:

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

borkdude 2022-10-17T09:31:15.195329Z

I suspect there is something weird with yarn --cwd

2022-10-17T09:32:16.846569Z

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

borkdude 2022-10-17T09:32:54.405979Z

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

borkdude 2022-10-17T09:34:59.730319Z

or perhaps you can make a repro that is public

borkdude 2022-10-17T09:35:40.460599Z

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

👍 1
2022-10-17T09:44:42.348149Z

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

2022-10-17T09:45:02.508489Z

thanks for having a look 🙏

borkdude 2022-10-17T09:46:37.809399Z

It tries to load a namespace called e2econfig

borkdude 2022-10-17T09:46:40.397929Z

which is not in the repo?

borkdude 2022-10-17T09:46:59.586269Z

oh I see

borkdude 2022-10-17T09:47:15.429239Z

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

2022-10-17T09:47:57.243219Z

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

borkdude 2022-10-17T09:50:14.408129Z

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

borkdude 2022-10-17T09:50:46.101729Z

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

borkdude 2022-10-17T09:52:12.139679Z

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

borkdude 2022-10-17T09:52:18.727449Z

so you're running two things in parallel

borkdude 2022-10-17T09:52:41.973689Z

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"))

borkdude 2022-10-17T09:52:55.025699Z

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

borkdude 2022-10-17T09:55:16.095269Z

Does this make sense?

borkdude 2022-10-17T09:56:19.647699Z

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

2022-10-17T10:01:37.444399Z

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

2022-10-17T10:12:54.180509Z

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

👍 1