|
|
@@ -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)]
|
|
|
|