hyperfiddle / rcf

RCF – a REPL-first, async test macro for Clojure/Script
MIT License
279 stars 12 forks source link

How to use RCF with leiningen #53

Open dustingetz opened 2 years ago

dustingetz commented 2 years ago

Question is: "Basically just be able to use RCF with lein. It would be great if i can 'lein test' and it works."

StankovicMarko commented 2 years ago

Solution from slack: https://clojurians.slack.com/archives/C7Q9GSHFV/p1650824587456189

; project.clj
:test-paths ["test"]
  :profiles {
             :test {:jvm-opts ["-Dhyperfiddle.rcf.generate-tests=true"]
                    :aliases {"run-tests" ["run" "-m" "app.core-test/run-tests" :project/test-paths]}}
             }

;app_test.clj
(ns app.core-test
  (:require [clojure.test :as test]
            [app.config]))

(defn run-tests [args]
  (test/run-tests 'app.config))

;how to run it (terminal)
lein with-profile test run-tests

; references
; https://github.com/technomancy/leiningen/blob/master/doc/PLUGINS.md#not-writing-a-plugin-%E6%97%A0%E4%B8%BA
; https://github.com/technomancy/leiningen/blob/master/doc/PROFILES.md

I'd be happy to learn about better/cleaner way to do this. At the moment this approach works for my needs.

Thanks for sharing this!

ggeoffrey commented 2 years ago

A minimal project.clj:

(defproject my/project "0.0.0"
  :dependencies [[org.clojure/clojure "1.10.3"]]
  :profiles {:test {:dependencies [[com.hyperfiddle/rcf "20220405"]]
                    :jvm-opts ["-Dhyperfiddle.rcf.generate-tests=true"]}})

Then run lein test

If you have tests forms in your src folder:

(defproject my/project "0.0.0"
  :dependencies [[org.clojure/clojure "1.10.3"]
                 [com.hyperfiddle/rcf "20220405"]]
  :profiles {:test {:jvm-opts ["-Dhyperfiddle.rcf.generate-tests=true"]
                    :test-paths ["test" "src"]}})
StankovicMarko commented 2 years ago

Oh wow, it's obvious now. Thanks a lot :)

ieugen commented 2 years ago

I would love for this to be documented for newbies like me :)

dustingetz commented 2 years ago

Reopening to add to readme