Skip to content

Commit fffcf86

Browse files
committed
Headless test
1 parent e7bc536 commit fffcf86

File tree

5 files changed

+377
-1
lines changed

5 files changed

+377
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ pom.xml
1313
/examples/*/main.js
1414
*~
1515
*.asc
16+
node_modules/

.travis.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
language: clojure
22
script: ./script/test
33
sudo: false
4+
addons:
5+
apt:
6+
sources: [ 'ubuntu-toolchain-r-test']
7+
packages: ['libstdc++6']
48
cache:
59
directories:
6-
- $HOME/.m2
10+
- $HOME/.m2
11+
- node_modules

package-lock.json

Lines changed: 322 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

script/headless_test.cljs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
(ns om-tools.headless-test)
2+
3+
(def path (js/require "path"))
4+
5+
(def p (js/require "puppeteer"))
6+
7+
(def expected-outputs
8+
{"\nTesting om-tools.core-test " 1
9+
"\nTesting om-tools.dom-test " 1
10+
"\nTesting om-tools.mixin-test " 1
11+
"\nTesting om-tools.schema-test " 1
12+
"\nRan 13 synchronous tests containing 367 assertions." 1
13+
"Waiting on 1 asynchronous test to complete." 1
14+
"\nTesting om-tools.core-test (async)" 1
15+
"\nRan 14 tests containing 370 assertions." 1
16+
"Testing complete: 0 failures, 0 errors." 2})
17+
18+
(defn goto-test-html
19+
[p]
20+
(.goto p (str "file://" (path.resolve "test/index.html"))))
21+
22+
(defn watch-for-log-events [p result-store]
23+
(.on p "console"
24+
(fn [console-message]
25+
(swap! result-store
26+
update (.text console-message) inc))))
27+
28+
(js/setTimeout
29+
(fn []
30+
(js/console.error "Tests did not pass within allowed time")
31+
(.exit js/process 1))
32+
20000)
33+
34+
(let [browser (.launch p (clj->js {:args ["--no-sandbox"]}))
35+
page (.then browser (fn [browser]
36+
(.newPage browser)))
37+
result-store (let [a (atom {})]
38+
(add-watch a ::store
39+
(fn [k r o n]
40+
(when (= n expected-outputs)
41+
(prn "Tests passed :)")
42+
(.exit js/process)))))]
43+
(-> page
44+
(.then #(watch-for-log-events % result-store))
45+
(.then goto-test-html)))

script/test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ set -ev
44
cd "$(dirname ${0})/.."
55

66
lein do clean, test, cljsbuild test
7+
npm install -i puppeteer
8+
npm install -i lumo-cljs
9+
./node_modules/lumo-cljs/bin/lumo -i script/headless_test.cljs

0 commit comments

Comments
 (0)