From cef1308b3a897772ffdde2acec182046c2cc0c6d Mon Sep 17 00:00:00 2001 From: Icaro Motta Date: Wed, 24 Jul 2024 00:18:27 -0300 Subject: [PATCH] chore(tests): Allow test-watch-for-repl target to run while the app is running (#20827) Fix a long standing problem where we can't run in parallel the make target run-clojure and test-watch-for-repl, or in other words, we can't run tests via the REPL while the app is running. Details: I found out that shadow-cljs fails to build because it does not expand the environment variables SHADOW_OUTPUT_TO and SHADOW_NS_REGEXP if and only if the run-clojure target was executed. This is the top of the stacktrace, and it happens because it doesn't know where to output the test build because the env var wasn't expanded: [build] NullPointerException: [build] shadow.build.node/configure (node.clj:59) [build] shadow.build.node/configure (node.clj:45) [build] shadow.build.targets.node-script/configure (node_script.clj:37) The solution is to pass the option --config-merge to shadow-cljs and override both :ns-regexp and :output-to because CLI args override options from env vars in shadow-cljs. --- Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 1b117ca003..e912afca0b 100644 --- a/Makefile +++ b/Makefile @@ -353,13 +353,17 @@ test: export SHADOW_NS_REGEXP := .*-test$$ test: ##@test Run all Clojure tests test: _test-clojure +# Note: we need to override the :output-to and :ns-regexp options because +# shadow-cljs has a bug where it will not read from the env vars to expand the +# configuration when the shadow-cljs mobile target is already running. test-watch-for-repl: export TARGET := default test-watch-for-repl: export SHADOW_OUTPUT_TO := target/test/test.js test-watch-for-repl: export SHADOW_NS_REGEXP := .*-test$$ test-watch-for-repl: ##@test Watch all Clojure tests and support REPL connections + rm -f "$$SHADOW_OUTPUT_TO" && \ yarn install && shadow-cljs compile mocks && \ concurrently --kill-others --prefix-colors 'auto' --names 'build,repl' \ - 'yarn shadow-cljs watch test --verbose' \ + "yarn shadow-cljs watch test --verbose --config-merge '{:output-to \"$(SHADOW_OUTPUT_TO)\" :ns-regexp \"$(SHADOW_NS_REGEXP)\"}'" \ "until [ -f $$SHADOW_OUTPUT_TO ] ; do sleep 1 ; done ; node --require ./test-resources/override.js $$SHADOW_OUTPUT_TO --repl" test-unit: export SHADOW_OUTPUT_TO := target/unit_test/test.js