fix: enable repl test on non-node environments

This commit is contained in:
Tienson Qin
2023-08-18 20:54:55 +08:00
parent e19613f2d8
commit c1b16cea89
6 changed files with 31 additions and 29 deletions

View File

@@ -1,6 +1,6 @@
(ns frontend.fs-test
(:require [clojure.test :refer [is use-fixtures]]
[frontend.test.fixtures :as fixtures]
[frontend.test.node-fixtures :as node-fixtures]
[frontend.test.helper :as test-helper :include-macros true :refer [deftest-async]]
[frontend.test.node-helper :as test-node-helper]
[frontend.fs :as fs]
@@ -8,7 +8,7 @@
["fs" :as fs-node]
["path" :as node-path]))
(use-fixtures :once fixtures/redef-get-fs)
(use-fixtures :once node-fixtures/redef-get-fs)
(deftest-async create-if-not-exists-creates-correctly
;; dir needs to be an absolute path for fn to work correctly

View File

@@ -3,6 +3,7 @@
[frontend.test.helper :as test-helper :include-macros true :refer [deftest-async]]
[frontend.test.node-helper :as test-node-helper]
[frontend.test.fixtures :as fixtures]
[frontend.test.node-fixtures :as node-fixtures]
[frontend.handler.plugin-config :as plugin-config-handler]
[frontend.handler.global-config :as global-config-handler]
[frontend.schema.handler.plugin-config :as plugin-config-schema]
@@ -14,7 +15,7 @@
[clojure.string :as string]
[frontend.handler.notification :as notification]))
(use-fixtures :once fixtures/redef-get-fs)
(use-fixtures :once node-fixtures/redef-get-fs)
(defn- create-global-config-dir
[]

View File

@@ -333,15 +333,12 @@
(deftest test-paste-into-empty-block
(testing "
Paste a block into the first block (its content is empty)
[[22 [[2 [[3 [[4]
[5]]]
[6 [[7 [[8]]]]]
[9 [[10]
[11]]]]]
[12 [[13]
[14]
[15]]]
[16 [[17]]]]]]
[[22 [[2 [[3 [[4] [5]]]
[6 [[7
[[8]]]]]
[9 [[10] [11]]]]]
[12 [[13] [14] [15]]]
[16 [[17]]]]]]
"
(transact-tree! tree)
(db/transact! test-db [{:block/uuid 22
@@ -349,9 +346,9 @@
(let [target-block (get-block 22)]
(outliner-tx/transact!
{:graph test-db}
(outliner-core/insert-blocks! [{:block/left [:block/uuid 1]
(outliner-core/insert-blocks! [{:block/left 1
:block/content "test"
:block/parent [:block/uuid 1]
:block/parent 1
:block/page 1}]
target-block
{:sibling? false

View File

@@ -4,11 +4,8 @@
[logseq.db.schema :as db-schema]
[frontend.db.conn :as conn]
[frontend.db.react :as react]
[frontend.fs.test-node :as test-node]
[frontend.fs :as fs]
[frontend.state :as state]
[frontend.test.helper :as test-helper]
[cljs.test :refer [async]]))
[frontend.test.helper :as test-helper]))
(defn load-test-env
[f]
@@ -34,13 +31,3 @@
(reset-datascript repo)
(let [r (f)]
(reset-datascript repo) r)))
(let [get-fs-fn (atom nil)]
(def redef-get-fs
"Redef fs/get-fs to an implementation that is valid for node tests"
{:before (fn []
(async done
(reset! get-fs-fn fs/get-fs)
(set! fs/get-fs (constantly (test-node/->NodeTestfs)))
(done)))
:after (fn [] (set! fs/get-fs @get-fs-fn))}))

View File

@@ -11,7 +11,10 @@
[datascript.core :as d]
[logseq.graph-parser.text :as text]))
(defonce test-db (if (some? js/process.env.DB_GRAPH) "logseq_db_test-db" "test-db"))
(def node? (exists? js/process))
(defonce test-db
(if (and node? (some? js/process.env.DB_GRAPH)) "logseq_db_test-db" "test-db"))
(defn start-test-db!
[]

View File

@@ -0,0 +1,14 @@
(ns frontend.test.node-fixtures
(:require [cljs.test :refer [async]]
[frontend.fs :as fs]
[frontend.fs.test-node :as test-node]))
(let [get-fs-fn (atom nil)]
(def redef-get-fs
"Redef fs/get-fs to an implementation that is valid for node tests"
{:before (fn []
(async done
(reset! get-fs-fn fs/get-fs)
(set! fs/get-fs (constantly (test-node/->NodeTestfs)))
(done)))
:after (fn [] (set! fs/get-fs @get-fs-fn))}))