I'm having some trouble running tests from the REPL using Calva (works fine in Emacs+Cider).
I have some bases and components with test, and :test aliases with some extra-deps
As per the documentation and examples, I've added each brick's test folder under the :test alias's :extra-paths (e.g. "bases/foo/test" "components/bar/test")
When I start emacs and jack-in with cider, and make sure I load the :dev and :test aliases, I can run cider-test-run-project-test and all tests that are loaded via those extra-paths are run.
In Calva however, when loading the same aliases, Calva reports that there are 0 tests to run. I can reproduce this even with the real-world example (https://github.com/furkan3ayraktar/clojure-polylith-realworld-example-app). Am I missing something?
Example calva output:
; Starting Jack-in: (cd /private/tmp/clojure-polylith-realworld-example-app; clojure -Sdeps '{:deps {nrepl/nrepl {:mvn/version,"1.1.1"},cider/cider-nrepl {:mvn/version,"0.47.1"}}}' -M:dev:test -m nrepl.cmdline --middleware "[cider.nrepl/cider-middleware]")
; Using host:port localhost:55277 ...
; Hooking up nREPL sessions ...
; Connected session: clj
; Evaluating code from settings: 'calva.autoEvaluateCode.onConnect.clj'
nil
clj꞉user꞉>
; Evaluating 'afterCLJReplJackInCode'
; 2024-09-04T11:30:20.031Z Meteor.local INFO [clojure.realworld.rest-api.main:?] - Starting server on port: 6003
; 2024-09-04T11:30:20.053Z Meteor.local INFO [clojure.realworld.log.config:77] - Initialized logging. Using console to print logs.
; 2024-09-04T11:30:20.053Z Meteor.local INFO [clojure.realworld.rest-api.api:?] - Generating database.
; 2024-09-04T11:30:20.394Z Meteor.local INFO [clojure.realworld.rest-api.api:?] - Database generated.
; 2024-09-04T11:30:20.394Z Meteor.local INFO [clojure.realworld.rest-api.api:?] - Initialized server.
#object[org.eclipse.jetty.server.Server 0x238526e "Server@238526e{STARTED}[9.4.48.v20220622]"]
"Please see
about why stdout printed to this file is prepended with `;` to be line comments."
clj꞉dev.server꞉>
; Jack-in done.
clj꞉dev.server꞉>
; Running all project tests…
; No tests found. 😱, ns: 0, vars: 0
clj꞉dev.server꞉> if I jack-in to the same repl but using emacs+cider, I can run all tests
Maybe CIDER loads the test namespaces somehow? Calva doesn’t do that unless you tell it to. (Maybe it should, but generally Calva tries to avoid evaluating anything it hasn’t been explicitly told to evaluate.)
It's also probably worth noting that Polylith has its own test runner that works differently to the "regular" approach. There are ways to invoke it programmatically, but that's not common.
My workflow with Polylith, is to load/eval specific test nses and then run those tests (I have a hot key bound to a custom REPL snippet that loads the corresponding *-test ns for the current ns and then run the tests in there).
TL;DR: looks like I didn't miss anything and that's just the way it is.
I think we'll be adopting a similar workflow as @seancorfield outlined(usually I just use poly test from the command line rather than testing from the REPL, but other people have different workflows so I was a bit surprised).
Guess emacs/cider does do it a little bit different, fair enough @pez. Or it could even be a Doom Emacs thing and not cider directly.
I don't actually use Calva's test running stuff at all BTW. I use custom REPL snippets: https://github.com/seancorfield/vscode-calva-setup/blob/develop/calva/config.edn -- ctrl+alt+space then c to run the "current test" (the form the cursor is inside), t to run all tests in the current ns, or x to require the associated -test ns and run all the tests in that. That satisfies all the needs I have for running tests interactively, while developing (given that I obsessively hit alt+enter to eval each top-level form as I edit it, without saving files or reloading anything).
If you're willing to run your REPL with the :poly alias added, you can run tests programmatically (via a custom REPL snippet, for example), via the Poly API: https://cljdoc.org/d/polylith/clj-poly/0.2.22-SNAPSHOT/api/polylith.clj.core.api.interface#test
thanks for these snippets @seancorfield!