diff --git a/src/test/frontend/handler/repo_test.cljs b/src/test/frontend/handler/repo_test.cljs index 1a03d87ae9..7f7f82bb90 100644 --- a/src/test/frontend/handler/repo_test.cljs +++ b/src/test/frontend/handler/repo_test.cljs @@ -1,44 +1,14 @@ (ns frontend.handler.repo-test (:require [cljs.test :refer [deftest use-fixtures is testing]] - [clojure.string :as string] - ["fs" :as fs] - ["child_process" :as child-process] [frontend.handler.repo :as repo-handler] [frontend.test.helper :as test-helper] + [frontend.test.docs-graph-helper :as docs-graph-helper] [datascript.core :as d] [frontend.db.conn :as conn])) (use-fixtures :each {:before test-helper/start-test-db! :after test-helper/destroy-test-db!}) -(defn- slurp - "Like clojure.core/slurp" - [file] - (str (fs/readFileSync file))) - -(defn- sh - "Run shell cmd synchronously and print to inherited streams by default. Aims - to be similar to babashka.tasks/shell" - [cmd opts] - (child-process/spawnSync (first cmd) - (clj->js (rest cmd)) - (clj->js (merge {:stdio "inherit"} opts)))) - -(defn- build-graph-files - [dir] - (let [files (->> (str (.-stdout (sh ["git" "ls-files"] - {:cwd dir :stdio nil}))) - string/split-lines - (filter #(re-find #"^(pages|journals)" %)) - (map #(str dir "/" %)))] - (mapv #(hash-map :file/path % :file/content (slurp %)) files))) - -(defn- clone-docs-repo-if-not-exists - [dir] - (when-not (.existsSync fs dir) - (sh ["git" "clone" "--depth" "1" "-b" "v0.6.7" "-c" "advice.detachedHead=false" - "https://github.com/logseq/docs" dir] {}))) - (defn- get-top-block-properties [db] (->> (d/q '[:find (pull ?b [*]) @@ -67,8 +37,8 @@ ;; Integration test that test parsing a large graph like docs (deftest ^:integration parse-and-load-files-to-db (let [graph-dir "src/test/docs" - _ (clone-docs-repo-if-not-exists graph-dir) - files (build-graph-files graph-dir) + _ (docs-graph-helper/clone-docs-repo-if-not-exists graph-dir) + files (docs-graph-helper/build-graph-files graph-dir) _ (repo-handler/parse-files-and-load-to-db! test-helper/test-db files {:re-render? false}) db (conn/get-db test-helper/test-db)] diff --git a/src/test/frontend/test/docs_graph_helper.cljs b/src/test/frontend/test/docs_graph_helper.cljs new file mode 100644 index 0000000000..25f64eca63 --- /dev/null +++ b/src/test/frontend/test/docs_graph_helper.cljs @@ -0,0 +1,34 @@ +(ns ^:nbb-compatible frontend.test.docs-graph-helper + "Helper fns for running tests against docs graph" + (:require ["fs" :as fs] + ["child_process" :as child-process] + [clojure.string :as string])) + + +(defn- slurp + "Like clojure.core/slurp" + [file] + (str (fs/readFileSync file))) + +(defn- sh + "Run shell cmd synchronously and print to inherited streams by default. Aims + to be similar to babashka.tasks/shell" + [cmd opts] + (child-process/spawnSync (first cmd) + (clj->js (rest cmd)) + (clj->js (merge {:stdio "inherit"} opts)))) + +(defn build-graph-files + [dir] + (let [files (->> (str (.-stdout (sh ["git" "ls-files"] + {:cwd dir :stdio nil}))) + string/split-lines + (filter #(re-find #"^(pages|journals)" %)) + (map #(str dir "/" %)))] + (mapv #(hash-map :file/path % :file/content (slurp %)) files))) + +(defn clone-docs-repo-if-not-exists + [dir] + (when-not (.existsSync fs dir) + (sh ["git" "clone" "--depth" "1" "-b" "v0.6.7" "-c" "advice.detachedHead=false" + "https://github.com/logseq/docs" dir] {}))) diff --git a/src/test/logseq/graph_parser/mldoc_test.cljs b/src/test/logseq/graph_parser/mldoc_test.cljs index 347a90d4c7..ef71e1f259 100644 --- a/src/test/logseq/graph_parser/mldoc_test.cljs +++ b/src/test/logseq/graph_parser/mldoc_test.cljs @@ -3,8 +3,7 @@ ["fs" :as fs] ["child_process" :as child-process] [clojure.string :as string] - ;; hack needed for parse-property to exist - [logseq.graph-parser.text] + [frontend.test.docs-graph-helper :as docs-graph-helper] [cljs.test :refer [testing deftest are is]])) (deftest test-link @@ -43,33 +42,10 @@ (are [x y] (= (gp-mldoc/link? :markdown x) y) "[YouTube](https://www.youtube.com/watch?v=-8ym7pyUs9gL) - [Vimeo](https://vimeo.com/677920303) {{youtube https://www.youtube.com/watch?v=-8ym7pyUs9g}}" true))) -;; TODO: Reuse with repo-test fns -(defn- slurp - "Like clojure.core/slurp" - [file] - (str (fs/readFileSync file))) - -(defn- sh - "Run shell cmd synchronously and print to inherited streams by default. Aims - to be similar to babashka.tasks/shell" - [cmd opts] - (child-process/spawnSync (first cmd) - (clj->js (rest cmd)) - (clj->js (merge {:stdio "inherit"} opts)))) - -(defn- build-graph-files - [dir] - (let [files (->> (str (.-stdout (sh ["git" "ls-files"] - {:cwd dir :stdio nil}))) - string/split-lines - (filter #(re-find #"^(pages|journals)" %)) - (map #(str dir "/" %)))] - (mapv #(hash-map :file/path % :file/content (slurp %)) files))) - -;; TODO: Add clone docs step (deftest ^:integration test->edn (let [graph-dir "src/test/docs" - files (build-graph-files graph-dir) + _ (docs-graph-helper/clone-docs-repo-if-not-exists graph-dir) + files (docs-graph-helper/build-graph-files graph-dir) asts-by-file (->> files (map (fn [{:file/keys [path content]}] (let [format (if (string/ends-with? path ".org")