Fork me on GitHub
#shadow-cljs
<
2023-05-24
>
itaied07:05:35

hey guys, im running the example from https://shadow-cljs.github.io/docs/UsersGuide.html#target-node-test and receive a npe error:

yarn shadow-cljs compile test
yarn run v1.23.0-20220130.1630
$ /h/node_modules/.bin/shadow-cljs compile test
shadow-cljs - config: /h/shadow-cljs.edn
shadow-cljs - connected to server
[:test] Compiling ...
NullPointerException: 
	shadow.build.node/configure (node.clj:59)
	shadow.build.node/configure (node.clj:45)
	shadow.build.targets.node-script/configure (node_script.clj:37)
	shadow.build.targets.node-script/configure (node_script.clj:32)
	shadow.build.targets.node-script/process (node_script.clj:71)
	shadow.build.targets.node-script/process (node_script.clj:67)
	shadow.build.targets.node-test/process (node_test.clj:96)
	shadow.build.targets.node-test/process (node_test.clj:86)
	clojure.lang.Var.invoke (Var.java:384)
	shadow.build/process-stage/fn--14074 (build.clj:163)
	shadow.build/process-stage (build.clj:160)
	shadow.build/process-stage (build.clj:152)
	shadow.build/configure (build.clj:420)
	shadow.build/configure (build.clj:305)
	shadow.cljs.devtools.api/compile* (api.clj:295)
	shadow.cljs.devtools.api/compile* (api.clj:292)
	shadow.cljs.devtools.cli-actual/do-build-command (cli_actual.clj:34)
	shadow.cljs.devtools.cli-actual/do-build-command (cli_actual.clj:25)
	shadow.cljs.devtools.cli-actual/do-build-commands (cli_actual.clj:49)
	shadow.cljs.devtools.cli-actual/do-build-commands (cli_actual.clj:38)
	shadow.cljs.devtools.cli-actual/main/body-fn--16426--auto----17092 (cli_actual.clj:166)
	shadow.cljs.devtools.cli-actual/main (cli_actual.clj:165)
	shadow.cljs.devtools.cli-actual/main (cli_actual.clj:132)
	clojure.core/apply (core.clj:671)
	clojure.core/apply (core.clj:662)
	shadow.cljs.devtools.cli-actual/from-remote (cli_actual.clj:210)
	shadow.cljs.devtools.cli-actual/from-remote (cli_actual.clj:201)
	clojure.lang.Var.invoke (Var.java:393)
	shadow.cljs.devtools.cli/from-remote (cli.clj:79)
	shadow.cljs.devtools.cli/from-remote (cli.clj:77)
	shadow.user/eval94951 (NO_SOURCE_FILE:1)
	shadow.user/eval94951 (NO_SOURCE_FILE:1)
	clojure.lang.Compiler.eval (Compiler.java:7194)
	clojure.lang.Compiler.eval (Compiler.java:7184)
	clojure.lang.Compiler.eval (Compiler.java:7149)
	clojure.core/eval (core.clj:3215)
	clojure.core/eval (core.clj:3211)
	shadow.cljs.devtools.server.socket-repl/repl/fn--17007 (socket_repl.clj:61)
	clojure.main/repl/read-eval-print--9206/fn--9209 (main.clj:437)
	clojure.main/repl/read-eval-print--9206 (main.clj:437)
	clojure.main/repl/fn--9215 (main.clj:458)
	clojure.main/repl (main.clj:458)
	clojure.main/repl (main.clj:368)
	shadow.cljs.devtools.server.socket-repl/repl (socket_repl.clj:28)
	shadow.cljs.devtools.server.socket-repl/repl (socket_repl.clj:26)
	shadow.cljs.devtools.server.socket-repl/connection-loop (socket_repl.clj:102)
	shadow.cljs.devtools.server.socket-repl/connection-loop (socket_repl.clj:72)
	shadow.cljs.devtools.server.socket-repl/start/fn--17022/fn--17023/fn--17025 (socket_repl.clj:142)
error Command failed with exit code 1.
Any idea where to start looking?
:builds {:app {:target     :browser
                :output-dir "public/js"
                :asset-path "/js"
                :modules    {:main ; becomes public/js/main.js
                             {:init-fn main/init}}}
          :test {:target :node-test
                 :test-dir "out/tests.js"
                 :ns-regexp  "-test$"
                 :autorun true}}
And I have a single test file
(ns h-test
  (:require [cljs.test :refer (deftest is)]))

(deftest a-failing-test
  (is (= 1 2)))

thheller07:05:50

:node-test does not take a :test-dir. it takes an :output-to filename

itaied07:05:36

ohh I see, perfect thanks!

itaied07:05:56

do you know how can i set a watch to run the tests on every test or source file changes?

thheller07:05:20

npx shadow-cljs watch test

itaied07:05:01

although i have the :autorun true, it just compiles and build, but doesn't run. when executing npx shadow-cljs compile test it does compile and run the tests

thheller07:05:36

it runs the tests in the process where shadow-cljs was initially started

thheller07:05:45

so if you have it running in another terminal they might be running there?

thheller07:05:03

when you tun the command does it say "connected to server" in the beginning?

thheller07:05:36

but I basically always recommend to not use :autorun at all

thheller07:05:48

I think its very pointless to run tests after every compile

thheller07:05:13

instead create a keybinding in your editor or something and then run them manually through that when you actually want to see the results

thheller07:05:54

there are also other tools to execute the tests

thheller07:05:02

all give you much more control over tests than :autorun true

itaied07:05:17

I found the results, it was in the other terminal, thanks.

itaied07:05:34

Ill take a look at the opencli tools

thheller07:05:38

note that the output of :node-test takes extra command line options

thheller07:05:14

try node that-output.js --help

thheller07:05:30

lets you pick specific tests for example, so not all run all the time

zackteo09:05:30

Hello! Is there a way to set repositories, plugin-repositories and mirrors in shadow-cljs? Similar to leiningen https://github.com/technomancy/leiningen/blob/github/sample.project.clj#L104-L143. Am in an environment where I can't connect to https://repo1.maven.org/maven2/ and https://repo.clojars.org/ so will get stuck when I currently run npx shadow-cljs watch app

thheller09:05:31

same as in lein, but in a :maven map. so :maven {:repositories ...}. either in shadow-cljs.edn or ~/.shadow-cljs/config.edn

👍 2
thheller09:05:43

or just use leiningen

zackteo09:05:14

So if I use a shadow-cljs project with leiningen, this is handled already?

thheller09:05:16

if you tell shadow-cljs to use leiningen to launch yes

2
zackteo09:05:03

Also just trying my luck, but do you happen to know what else I need to configure leiningen to allow lein templates to work in an environment that can't access https://repo1.maven.org/maven2/ and https://repo.clojars.org/ I get errors like Failed to resolve version for re-frame:leiningen-template:jar:RELEASE: Could not find metadata re-frame:lein-template/maven-metadata.xml in local (/Users/.../.m2/repository)

thheller09:05:46

no clue. I don't use templates

zackteo09:05:04

no worries 🙂 thanks for your help!