- update re-natal to 0.8.0
- git ignore config.cljs
- derive re-frisk url from config.cljs
- add tests for env/dev/env/utils
- remove lein re-frisk use-re-natal from Makefile

Signed-off-by: Oskar Thoren <ot@oskarthoren.com>
This commit is contained in:
t4sk 2017-12-22 19:35:05 +07:00 committed by Oskar Thoren
parent b5735230ff
commit 591e568e37
No known key found for this signature in database
GPG Key ID: 5128AB0637CD85AF
9 changed files with 76 additions and 14 deletions

2
.gitignore vendored
View File

@ -50,6 +50,8 @@ android/keystores/debug.keystore
index.android.js
index.ios.js
target/
env/dev/env/config.cljs
.re-natal.local
# Generated by lein voom
#

View File

@ -31,7 +31,6 @@ prepare: ##@prepare Install dependencies and prepare workspace
npm install
./re-natal deps
./re-natal use-figwheel
lein re-frisk use-re-natal
./re-natal enable-source-maps
prepare-ios: prepare ##@prepare Install iOS specific dependencies

View File

@ -1,10 +1,10 @@
(ns ^:figwheel-no-load env.android.main
(:require [reagent.core :as r]
[re-frame.core :as re-frame]
[status-im.android.core :as core]
[figwheel.client :as figwheel :include-macros true]
[re-frisk-remote.core :as rr]
[env.config :as conf]
[env.utils]
[status-im.utils.handlers :as utils.handlers]))
(enable-console-print!)
@ -16,11 +16,11 @@
(defn reloader [] @cnt [core/app-root])
(def root-el (r/as-element [reloader]))
(figwheel/watch-and-reload
:websocket-url "ws://localhost:3449/figwheel-ws"
:heads-up-display false
:jsload-callback #(swap! cnt inc))
(figwheel/start {:websocket-url (:android conf/figwheel-urls)
:heads-up-display false
:jsload-callback #(swap! cnt inc)})
(utils.handlers/add-pre-event-callback rr/pre-event-callback)
(rr/enable-re-frisk-remote! {:host "10.0.3.2:4567" :on-init core/init})
(rr/enable-re-frisk-remote! {:host (env.utils/re-frisk-url (:android conf/figwheel-urls))
:on-init core/init})

View File

@ -4,19 +4,24 @@
[status-im.ios.core :as core]
[status-im.utils.handlers :as utils.handlers]
[figwheel.client :as figwheel :include-macros true]
[env.config :as conf]
[env.utils]
[cljs.pprint]))
(enable-console-print!)
(assert (exists? core/init) "Fatal Error - Your core.cljs file doesn't define an 'init' function!!! - Perhaps there was a compilation failure?")
(assert (exists? core/app-root) "Fatal Error - Your core.cljs file doesn't define an 'app-root' function!!! - Perhaps there was a compilation failure?")
(def cnt (r/atom 0))
(defn reloader [] @cnt [core/app-root])
(def root-el (r/as-element [reloader]))
(figwheel/watch-and-reload
:websocket-url "ws://localhost:3449/figwheel-ws"
:heads-up-display false
:jsload-callback #(swap! cnt inc))
(figwheel/start {:websocket-url (:ios conf/figwheel-urls)
:heads-up-display false
:jsload-callback #(swap! cnt inc)})
(utils.handlers/add-pre-event-callback rr/pre-event-callback)
(rr/enable-re-frisk-remote! {:host "localhost:4567" :on-init core/init})
(rr/enable-re-frisk-remote! {:host (env.utils/re-frisk-url (:ios conf/figwheel-urls))
:on-init core/init})

22
env/dev/env/utils.cljs vendored Normal file
View File

@ -0,0 +1,22 @@
(ns env.utils
(:require [clojure.string :as string]))
(defn get-host
"Expects the input url to be in the form protocol://host:port
Returns host or an empty string upon failure"
[url]
(->
url
(string/split #"/")
(get 2 "")
(string/split #":")
(get 0 "")))
(defn re-frisk-url
"Expects the input url to be in the form ws://host:port/figwheel-ws
which is generated by re-natal"
[url]
(let [host (get-host url)]
(if (string/blank? host)
(throw (js/Error. "Failed to parse figwheel url. re-frisk url cannot be blank"))
(str host ":" 4567))))

View File

@ -43,7 +43,7 @@
"prop-types": "15.6.0",
"punycode": "^1.4.1",
"querystring-es3": "0.2.1",
"re-natal": "0.7.2",
"re-natal": "0.8.0",
"react": "^16.0.0",
"react-dom": "16.0.0",
"react-native": "^0.50.3",

View File

@ -21,7 +21,8 @@
["with-profile" "prod" "cljsbuild" "once" "android"]]
"figwheel-repl" ["run" "-m" "clojure.main" "env/dev/run.clj"]
"test-cljs" ["with-profile" "test" "doo" "node" "test" "once"]
"test-protocol" ["with-profile" "test" "doo" "node" "protocol" "once"]}
"test-protocol" ["with-profile" "test" "doo" "node" "protocol" "once"]
"test-env-dev-utils" ["with-profile" "test" "doo" "node" "env-dev-utils" "once"]}
:figwheel {:nrepl-port 7888}
:profiles {:dev {:dependencies [[figwheel-sidecar "0.5.14"]
[re-frisk-remote "0.5.3"]
@ -61,6 +62,13 @@
{:id "protocol"
:source-paths ["src" "test/cljs"]
:compiler {:main status-im.test.protocol.runner
:output-to "target/test/test.js"
:output-dir "target/test"
:optimizations :none
:target :nodejs}}
{:id "env-dev-utils"
:source-paths ["env/dev/env/utils.cljs" "test/env/dev"]
:compiler {:main env.test.runner
:output-to "target/test/test.js"
:output-dir "target/test"
:optimizations :none

13
test/env/dev/env/test/runner.cljs vendored Normal file
View File

@ -0,0 +1,13 @@
(ns env.test.runner
(:require [doo.runner :refer-macros [doo-tests]]
[env.test.utils]))
(enable-console-print!)
;; Or doo will exit with an error, see:
;; https://github.com/bensu/doo/issues/83#issuecomment-165498172
(set! (.-error js/console) (fn [x] (.log js/console x)))
(set! goog.DEBUG false)
(doo-tests 'env.test.utils)

13
test/env/dev/env/test/utils.cljs vendored Normal file
View File

@ -0,0 +1,13 @@
(ns env.test.utils
(:require [cljs.test :refer-macros [deftest is]]
[env.utils :as utils]))
(deftest get-host-test
(is (= (utils/get-host "http://localhost:8000") "localhost"))
(is (= (utils/get-host "http://0.0.0.0:8000") "0.0.0.0"))
(is (= (utils/get-host "invalid") "")))
(deftest re-frisk-url-test
(is (= (utils/re-frisk-url "ws://localhost:3449/figwheel-ws") "localhost:4567"))
(is (= (utils/re-frisk-url "ws://10.0.2.2:3449/figwheel-ws") "10.0.2.2:4567"))
(is (thrown? js/Error (utils/re-frisk-url "invalid"))))