Skip to content

Commit

Permalink
Fix test runner looping over more than one test ns
Browse files Browse the repository at this point in the history
  • Loading branch information
PEZ committed Nov 7, 2024
1 parent b71d205 commit 13f00be
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 40 deletions.
58 changes: 20 additions & 38 deletions e2e-test-ws/.joyride/src/test_runner/runner.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -52,48 +52,30 @@
(p/reject! running fail-reason)
(p/resolve! running true)))))

(defn test-file? [file]
(and (.endsWith file ".cljs")
(not (.startsWith file "_"))))

(defn file->ns [file]
(defn- file->ns [src-path file]
(-> file
(string/replace #"/" ".")
(subs (inc (count src-path)))
(string/replace #"\.cljs$" "")
(string/replace #"^tests\." "")))

(defn find-test-files+ [path]
(p/->> (vscode/workspace.findFiles (str path "/**/*_test.cljs"))
(.map vscode/workspace.asRelativePath)))

(defn get-test-namespaces+ [tests-path]
(p/let [files (find-test-files+ tests-path)]
(def files files)
(->> files
(filter #(test-file? (first %)))
(map #(file->ns (first %)))
(map symbol))))
(string/replace #"/" ".")
(string/replace #"_" "-")))

(comment
(def tests-path "e2e-test-ws/.joyride/src")
(p/let [test-namespaces (get-test-namespaces+ tests-path)]
(println "test-namespaces" test-namespaces)
(def test-namespaces test-namespaces)
:rcf)
)
(defn- find-test-nss+ [src-path]
(p/let [file-uris (vscode/workspace.findFiles (str src-path "/**/*_test.cljs"))
files (.map file-uris (fn [uri]
(vscode/workspace.asRelativePath uri false)))
nss-strings (-> files
(.map (partial file->ns src-path)))]
(mapv symbol nss-strings)))

(defn run-all-tests [tests-directory]
(defn run-all-tests [src-path]
(let [running (p/deferred)]
(swap! db/!state assoc :running running)
(try
(doseq [ns-sym (config/ns-symbols)]
(require ns-sym)
(cljs.test/run-tests ns-sym))
(catch :default e
(p/reject! (:running @db/!state) e)))
running))

(comment
(run-all-tests)
:rcf)
(p/let [nss-syms (find-test-nss+ src-path)]
(println "Running tests in" nss-syms)
(-> (p/do
(apply require nss-syms)
(apply cljs.test/run-tests nss-syms)
running)
(p/catch (fn [e]
(p/reject! (:running @db/!state) e)))))))

Empty file.
7 changes: 6 additions & 1 deletion e2e-test-ws/.joyride/src/tests/foo/bar/b_test.cljs
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
(ns tests.foo.bar.b-test)
(ns tests.foo.bar.b-test
(:require [cljs.test :refer [deftest testing is]]))

(deftest hello
(testing "We can test things"
(is (= :foo :foo))))
2 changes: 1 addition & 1 deletion e2e-test-ws/runTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ const vscode = require('vscode');
exports.run = async () => {
return vscode.commands.executeCommand(
'joyride.runCode',
"(require '[test-runner.runner :as runner]) (runner/run-all-tests)"
"(require '[test-runner.runner :as runner]) (runner/run-all-tests \".joyride/src\")"
);
};

0 comments on commit 13f00be

Please sign in to comment.