Skip to content
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
8 changes: 8 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ machine:
dependencies:
pre:
- sudo apt-get update; sudo apt-get install rhino
- wget https://github.com/laurentj/slimerjs/archive/RELEASE_0.9.6.tar.gz
- tar xfvz RELEASE_0.9.6.tar.gz
- cd slimerjs-RELEASE_0.9.6/ && ./buildpackage.sh
- mkdir - /tmp/slimerjs/
- cp -p slimerjs-RELEASE_0.9.6/_dist/slimerjs-0.9.6-linux-x86_64.tar.bz2 /tmp/slimerjs/
- wget https://github.com/boot-clj/boot-bin/releases/download/2.4.2/boot.sh
- mv boot.sh boot && chmod a+x boot && sudo mv boot /usr/local/bin
- cd library && lein deps
Expand Down Expand Up @@ -57,6 +62,9 @@ test:
- cd example && lein doo electron test once
- cd example && lein doo electron advanced once
- cd example && lein doo electron none-test once
- cd example && lein doo electron electron-test once
- cd example && lein doo electron electron-advanced once
- cd example && lein doo electron electron-none once
# Boot
- cd example && boot add-tests test-cljs -e phantom -x
- cd example && boot add-tests test-cljs -e phantom -x -O advanced
Expand Down
3 changes: 1 addition & 2 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"karma-phantomjs-launcher": "^1.0.0",
"karma-safari-launcher": "^1.0.0",
"karma-slimerjs-launcher": "^1.0.0",
"phantomjs-prebuilt": "^2.1.7",
"slimerjs": "^0.9.6"
"phantomjs-prebuilt": "^2.1.7"
}
}
15 changes: 15 additions & 0 deletions example/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@
:optimizations :advanced
:target :nodejs}}

:electron-test {:source-paths ["src" "test"]
:compiler {:output-to "out/testable.js"
:main example.electron-runner
:optimizations :simple}}
:electron-none {:source-paths ["src" "test"]
:compiler {:output-to "out/testable.js"
:main example.electron-runner
:source-map true
:optimizations :none}}
:electron-advanced {:source-paths ["src" "test"]
:compiler {:output-to "out/testable.js"
:main example.electron-runner
:optimizations :advanced
:externs ["externs/electron.js"]}}

;; These cljsbuild configs are for CI testing only.
:dev-fail {:source-paths ["src"]
:compiler {:output-to "resources/public/js/dev.js"
Expand Down
21 changes: 21 additions & 0 deletions example/src/example/electron.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
(ns example.electron)

(def electron (js/require "electron"))
(def remote (.-remote electron ))
(def app (.-app remote))

(defn get-current-window
[]
(.getCurrentWindow remote))

(defn get-window-size
"Helper function to get Electron window size."
[window]
(let [[width height] (array-seq (.getSize window))]
{:width width
:height height}))

(defn set-window-size!
"Helper function to set Electron window size."
[window {:keys [width height]}]
(.setSize window width height))
6 changes: 6 additions & 0 deletions example/test/example/electron_runner.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(ns example.electron-runner
(:require [cljs.test :as test]
[doo.runner :refer-macros [doo-all-tests doo-tests]]
[example.electron-test]))

(doo-tests 'example.electron-test)
31 changes: 31 additions & 0 deletions example/test/example/electron_test.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
(ns example.electron-test
(:require [cljs.test :refer-macros [deftest is testing]]
[clojure.string :refer [split]]
[example.electron :as electron]))

(deftest electron-app-path
(is (= (last (split (.getAppPath electron/app) #"/"))
"runner.electron")))

(deftest electron-window-get-size
(let [window (electron/get-current-window)
size (electron/get-window-size window)]
(is (> (:width size) 0)
"The Electron window width should be more than zero.")
(is (> (:height size) 0)
"The Electron window height should be more than zero.")))

(deftest electron-window-set-size
(let [window (electron/get-current-window)
original-size (electron/get-window-size window)
new-size {:width (rand-int 500)
:height (rand-int 500)}]
;; resize window to a random size
(electron/set-window-size! window new-size)
(is (= new-size (electron/get-window-size window))
"The Electron window should be resized to new-size.")

;; resize window back to original size
(electron/set-window-size! window original-size)
(is (= original-size (electron/get-window-size window))
"The Electron window should be resized back to original-size.")))
4 changes: 4 additions & 0 deletions library/resources/runners/electron-shims.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
window.require = window.top.require;
window.process = window.top.process;
window.__dirname = window.top.__dirname;
// require("module").globalPaths.push("./node_modules");
17 changes: 1 addition & 16 deletions library/src/doo/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,7 @@
;; Sadly, we can't just point Phantom to the file inside the jar
;; http://stackoverflow.com/questions/25307667/launching-phantomjs-as-a-local-resource-when-using-an-executable-jar

;; TODO: runner arg is not necessary
(defn runner-path!
"Creates a temp file for the given runner resource file."
([runner filename]
(runner-path! runner filename {:common? false}))
([runner filename {:keys [common?]}]
(letfn [(slurp-resource [res]
(slurp (io/resource (str shell/base-dir res))))
(add-common [file]
(when common?
(spit file (slurp-resource "common.js"))))]
(.getAbsolutePath
(doto (File/createTempFile (name runner) ".js")
.deleteOnExit
add-common
(spit (slurp-resource filename) :append true))))))
(def runner-path! (partial utils/runner-path! shell/base-dir))

(def default-command-table
{:phantom "phantomjs"
Expand Down
2 changes: 2 additions & 0 deletions library/src/doo/karma.clj
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
;; base path
;; WARNING: the order of the files is important, don't change it.
"files" (concat
(when (some #{:electron} js-envs)
[(utils/runner-path! shell/base-dir :electron-shims "electron-shims.js")])
(when (= :none (:optimizations compiler-opts))
(mapv ->out-dir ["/goog/base.js" "/cljs_deps.js"]))
[(:output-to compiler-opts)
Expand Down
18 changes: 18 additions & 0 deletions library/src/doo/utils.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns doo.utils
"Taken from leiningen.core.utils"
(:import java.io.File)
(:require [clojure.java.io :as io]))

(defn- get-by-pattern
Expand Down Expand Up @@ -31,3 +32,20 @@

(defn debug-log [& args]
(apply println "[doo]" args))

;; TODO: runner arg is not necessary
(defn runner-path!
"Creates a temp file for the given runner resource file."
([base-dir runner filename]
(runner-path! base-dir runner filename {:common? false}))
([base-dir runner filename {:keys [common?]}]
(letfn [(slurp-resource [res]
(slurp (io/resource (str base-dir res))))
(add-common [file]
(when common?
(spit file (slurp-resource "common.js"))))]
(.getAbsolutePath
(doto (File/createTempFile (name runner) ".js")
.deleteOnExit
add-common
(spit (slurp-resource filename) :append true))))))