Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed NullPointerException and made tests run #112

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions sidecar/src/figwheel_sidecar/config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
(:require
[clojure.string :as string]
[clojure.java.io :as io]
[clojure.walk :as walk]))
[clojure.walk :as walk]
[figwheel-sidecar.core :refer [norm-path]]))

(defn mkdirs [fpath]
(let [f (io/file fpath)]
Expand All @@ -19,10 +20,6 @@
(= :none (get-in build [:compiler :optimizations])))

;; checking to see if output dir is in right directory
(defn norm-path
"Normalize paths to a forward slash separator to fix windows paths"
[p] (string/replace p "\\" "/"))

(defn relativize-resource-paths
"Relativize to the local root just in case we have an absolute path"
[resource-paths]
Expand Down
14 changes: 10 additions & 4 deletions sidecar/src/figwheel_sidecar/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
[clojurescript-build.api :as cbapi]
[clojure.pprint :as p]))

(defn atom?
"Returns true when the provided argument is an atom."
[maybe-atom?]
(instance? clojure.lang.Atom maybe-atom?))

;; get rid of fs dependancy

(defn split-ext
Expand Down Expand Up @@ -142,8 +147,9 @@
(defn append-msg [q msg] (conj (take 30 q) msg))

(defn send-message! [{:keys [file-change-atom] :as st} msg-name data]
(swap! file-change-atom append-msg
(message* st msg-name data)))
(when (atom? file-change-atom)
(swap! file-change-atom append-msg
(message* st msg-name data))))

(defn send-changed-files
"Formats and sends a files-changed message to the file-change-atom.
Expand Down Expand Up @@ -208,9 +214,9 @@

(defn file-changed?
"Standard md5 check to see if a file actually changed."
[{:keys [file-md5-atom]} filepath]
[{:keys [file-md5-atom]} filepath]
(let [file (as-file filepath)]
(when (.exists file)
(when (and (.exists file) (atom? file-md5-atom))
(let [contents (slurp file)]
(when (.contains contents "addDependency")
(let [check-sum (digest/md5 contents)
Expand Down
68 changes: 11 additions & 57 deletions sidecar/test/figwheel_sidecar/core_test.clj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
(ns figwheel-sidecar.core-test
(:use figwheel-sidecar.core)
(:use clojure.test)
(:require
[clojure.string :as string]
[clojure.java.io :as io]))
(:use [clojure.test]
[figwheel-sidecar.core])
(:require [clojure.string :as string]
[clojure.java.io :as io]
[figwheel-sidecar.config :refer [relativize-resource-paths]]))

(deftest test-utils
(is (.startsWith (project-unique-id) "figwheel-sidecar--")))
Expand All @@ -15,58 +15,12 @@
"other-resources-help/dang"]))

(is (= (relativize-resource-paths (dissoc st :resource-paths))
[]))
(is (= (ns-to-server-relative-path st 'example.crazy-name)
"/js/compiled/out/example/crazy_name.js"))
(is (= (ns-to-server-relative-path st 'example.crazy_name)
"/js/compiled/out/example/crazy_name.js"))
(is (= (ns-to-server-relative-path st "example.crazy_name")
"/js/compiled/out/example/crazy_name.js"))
(is (= (ns-to-server-relative-path st "example.crazy-name")
"/js/compiled/out/example/crazy_name.js")))
[])))

(deftest test-remove-resource-path
(let [root (.getCanonicalPath (io/file "."))
st { :http-server-root "public"
:output-dir "other-resources/public/js/compiled/out"
:resource-paths [(str root "/resources")
(str root "/other-resources")
(str root "/dev-resources")
(str root "/other-resources-help/dang")]}]
(remove-resource-path-tests st)
(remove-resource-path-tests
(assoc st
:output-dir "resources/public/js/compiled/out"))
(remove-resource-path-tests
(assoc st
:output-dir "other-resources-help/dang/public/js/compiled/out"))
(remove-resource-path-tests
(merge st {:http-server-root "public/house"
:output-dir "other-resources/public/house/js/compiled/out"}))

;; make sure it works if not given abasolute paths
(remove-resource-path-tests
(merge st {:resource-paths [(str "resources")
(str "other-resources")
(str "dev-resources")
(str "other-resources-help/dang")] }))
))


(defn windows-pather [s]
(string/replace s "/" "\\"))

(deftest test-remove-resource-windows-path
(let [root (windows-pather (.getCanonicalPath (io/file ".")))
st { :http-server-root "public"
:resource-paths [(str root "\\resources")
(str root "\\other-resources")
(str root "\\dev-resources")
(str root "\\other-resources-help/dang")]}]
(is (= (remove-resource-path st "resources\\public\\js\\example\\core.js")
"/js/example/core.js"))
(is (= (remove-resource-path st "resources\\public\\css\\style.css")
"/css/style.css"))
))
(deftest test-atom?
(let [not-an-atom "foo"
an-atom (atom {})]
(is (atom? an-atom))
(is (not (atom? not-an-atom)))))

#_(run-tests)