浏览代码

chore: add basic help test

Also add assertion to guard against previous load time issue
Gabriel Horner 2 月之前
父节点
当前提交
a6974021ce
共有 1 个文件被更改,包括 23 次插入0 次删除
  1. 23 0
      deps/cli/test/logseq/cli_test.cljs

+ 23 - 0
deps/cli/test/logseq/cli_test.cljs

@@ -0,0 +1,23 @@
+(ns logseq.cli-test
+  (:require ["child_process" :as child-process]
+            [cljs.test :refer [is deftest]]
+            [clojure.string :as string]))
+
+(defn- sh
+  "Run shell cmd synchronously and silently. Stdout/stderr can be inspected as needed"
+  [cmd]
+  (child-process/spawnSync (first cmd)
+                           (clj->js (rest cmd))
+                           #js {:stdio "pipe"}))
+
+(deftest basic-help
+  (let [start-time (cljs.core/system-time)
+        result (sh ["node" "cli.mjs" "--help"])
+        end-time (cljs.core/system-time)]
+
+    (is (string/includes? (str (.-stdout result))
+                          "Usage: logseq [command]"))
+
+    (let [max-time (-> 0.25 (* (if js/process.env.CI 2 1)))]
+      (is (< (-> end-time (- start-time) (/ 1000)) max-time)
+          (str "Printing CLI help takes less than " max-time "s")))))