Fork me on GitHub
#polylith
<
2023-04-02
>
Dave Russell09:04:51

Hello! Is there something I need to do used the normal Emacs/CIDER workflow to run component tests? E.g. I'm able to execute cider-test-run-test from emacs but the test never runs. The same behaviour happens in the real world demo app when I pull it down and try to run some of the example tests, so I guess it's not something unique to my project. I'm running the REPL from the commandline:

clj -Sdeps '{:deps {nrepl/nrepl {:mvn/version "0.5.3"}}}' -M:dev -m nrepl.cmdline
And then using:
cider-connect-clj
I heavily execute tests directly during development using CIDER so I'd prefer not to have to run the poly tool to execute them 🙂

furkan3ayraktar15:04:35

The poly tool can help detect which components are changed since the last stable point and run tests incrementally. It has a built-in test runner and support for providing your own test runner to benefit from incremental testing. During local development, I also use this approach and let the poly tool run the test most of the time, although, sometimes, I run the test directly from Calva. I do not have any particular setup; as long as the test sources are in the classpath when the REPL is started, I can use Calva’s test runner without any issues. When Calva starts the REPL for me, it includes the`:dev` and :test aliases from the workspace deps.edn; hence all the test namespaces load into the REPL session. I’ve tested it just now in Calva with the RealWorld example and found no issues. I do not have any experience with CIDER, so the only direction I can give you is to make sure the test namespaces are included in the REPL session (aka :test alias).

furkan3ayraktar15:04:17

It could be as simple as adding :test alias here:

clj -Sdeps '{:deps {nrepl/nrepl {:mvn/version "0.5.3"}}}' -M:dev:test -m nrepl.cmdline

seancorfield15:04:27

I use VS Code/Calva and have hot keys to execute current test (at cursor), all tests in the current (test) namespace, and all tests in the associated namespace (executes the test ns for the current src ns). That all works fine with Polylith.

seancorfield15:04:49

But I've no idea what assumptions CIDER makes about how to run tests.

Dave Russell16:04:37

Ah! Figured it out. I normally jack into cider from emacs, but for this project have been starting REPL from the CLI to include the aliases for this project. Turns out I wasn't using the CIDER nrepl middleware when starting up that REPL, and adding those arguments in now has it working. You both pointed me in the right direction with the aliases though, so thanks for the support! 🙂

seancorfield16:04:52

Cool! I mostly start my REPLs from the command line with a long list of aliases - so much so that I have a script to start my main work REPL in a Polylith project!

seancorfield16:04:41

The cider middleware is in one of my aliases.

Chad Walstrom02:04:03

Thanks for this thread. It was really helpful. I was having a bear of a time trying to play around in the REPL when components were pulling in dependencies that the root project didn't need. C-u C-c M-j to jack in, then add :dev:test to the -M:cider/nrepl alias -> -M:cider/nrepl:dev:test. I can then open the .clj file I want, C-u C-z to change to and load that namespace, and off to the races. Now to put that in a .dir-locals.el so I don't have to remember it each time. 🙂

Chad Walstrom03:04:32

Found it.

((clojure-mode . ((cider-clojure-cli-aliases . "-M:dev:test"))))