mirror of
https://github.com/logseq/logseq.git
synced 2026-05-24 20:54:09 +00:00
Reuse helpers b/n repo and mldoc
This commit is contained in:
@@ -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)]
|
||||
|
||||
|
||||
34
src/test/frontend/test/docs_graph_helper.cljs
Normal file
34
src/test/frontend/test/docs_graph_helper.cljs
Normal file
@@ -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] {})))
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user