biff

shinseitaro 2024-07-19T23:50:25.001639Z

Thank you so much for creating Biff. It's a truly amazing project! I am a complete novice when it comes to web applications, so I am learning a lot while using Biff. I have a question about testing. In the test files for the biff project template, there is a comment that says: > ;; If you add more test files, require them here so that they'll get loaded by com.example/on-save Specifically, should I implement it as follows? 1. Create a new test file (e.g., test/com/app_test.clj) 2. Write tests in test/com/app_test.clj 3. Add the following in test/com/example_test.clj

(ns com.example-test
  ;; If you add more test files, require them here so that they'll get loaded by com.example/on-save
  (:require [cheshire.core :as cheshire]
            [clojure.string :as str]
+           [clojure.test :refer [deftest is test-ns]]
            [com.biffweb :as biff :refer [test-xtdb-node]]
            [com.example :as main]
            [com.example.app :as app]
            [malli.generator :as mg]
            [rum.core :as rum]
            [xtdb.api :as xt]
            
+           [com.app-test]
            ))

+ (deftest run-all-tests
+   (test-ns 'com.app-test))

2024-07-20T17:50:27.869509Z

Glad Biff has been helpful! Yes, that'll work. Though instead of adding the (deftest run-all-tests (test-ns 'com.app-test)), you can move the new test namespace to com.example.app-test, and then it'll get picked up by com.example/on-save when it calls (test/run-all-tests #"com.example.*-test"). Alternatively you could adjust that regex. That being said: when poking around with the testing code just now, I noticed that test code doesn't get refreshed by default. i.e. if you edit a test file and then save it, biff won't automatically re-evaluate the file--you have to manually evaluate it with your editor. I just made https://github.com/jacobobryant/biff/commit/32640d260c63a0260352fa5053feb30eb3c7c542 to fix that, and it also means that you don't need to explicitly require new test namespaces at all. So instead of doing the above, you can just: 1. Upgrade your biff dependency to com.biffweb/biff {:git/tag "v1.8.19" :git/sha "32640d2" ...} OR add :biff.beholder/paths and :biff/eval-paths to your resources/config.edn file with the values https://github.com/jacobobryant/biff/commit/32640d260c63a0260352fa5053feb30eb3c7c542#diff-f042f2c95397bed02f0d8aab6376551ab6dae7125024fd82b47776a78131bb94 2. Create the com.example.app-test file and add tests there. and no need to require this file from anywhere.

👍 1
🎉 2
shinseitaro 2024-07-20T19:13:22.806299Z

Thank you! I was able to confirm that it works as expected with :git/sha "32640d2".

👌 1
🎉 1