Skip to content

Commit 92499fd

Browse files
authored
Run tests with new CLJS on Github Actions (#70)
1 parent 7651f93 commit 92499fd

File tree

9 files changed

+105
-45
lines changed

9 files changed

+105
-45
lines changed

.github/workflows/ci.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: ci
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
7+
clojure:
8+
9+
strategy:
10+
matrix:
11+
os: [ubuntu-latest]
12+
13+
runs-on: ${{ matrix.os }}
14+
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v3
18+
19+
# It is important to install java before installing clojure tools which needs java
20+
# exclusions: babashka, clj-kondo and cljstyle
21+
- name: Prepare java
22+
uses: actions/setup-java@v3
23+
with:
24+
distribution: 'zulu'
25+
java-version: '8'
26+
27+
- name: Install clojure tools
28+
uses: DeLaGuardo/[email protected]
29+
with:
30+
bb: latest
31+
lein: latest
32+
# Optional step:
33+
- name: Cache clojure dependencies
34+
uses: actions/cache@v3
35+
with:
36+
path: |
37+
~/.m2/repository
38+
~/.gitlibs
39+
~/.deps.clj
40+
# List all files containing dependencies:
41+
key: cljdeps-${{ hashFiles('deps.edn') }}
42+
# key: cljdeps-${{ hashFiles('deps.edn', 'bb.edn') }}
43+
# key: cljdeps-${{ hashFiles('project.clj') }}
44+
# key: cljdeps-${{ hashFiles('build.boot') }}
45+
restore-keys: cljdeps-
46+
47+
- name: Execute clj tests
48+
run: bb test:clj
49+
50+
- name: Execute cljs tests
51+
run: |
52+
bb test:cljs-npm-install
53+
bb test:cljs
54+

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ pom.xml
1313
out/
1414
.cpcache
1515
.cache
16+
cljs-test-runner-out
17+
node_modules
18+
19+
package-lock.json

bb.edn

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
{:deps {io.github.borkdude/lein2deps {:git/url "https://github.com/borkdude/lein2deps"
22
:git/sha "e26edeb114c9d88a5c4d3abb683306588fcaad13"}}
3-
:tasks {lein2deps {:doc "Generate deps.edn from project.clj"
4-
:requires ([lein2deps.api :as lein2deps])
5-
:task (lein2deps/lein2deps {:write-file "deps.edn"})}} }
3+
:tasks
4+
{:requires ([babashka.fs :as fs])
5+
6+
test:clj (shell "lein test")
7+
8+
test:cljs-npm-install (do (shell "npm install -g karma-cli")
9+
(shell "npm install"))
10+
test:cljs (do
11+
(fs/delete-tree "cljs-test-runner-out")
12+
(apply clojure "-M:test:cljs:cljs-test-runner" "--env" "chrome-headless" *command-line-args*))
13+
repl:cljs-node (shell "rlwrap bb clojure -M:test:cljs -m cljs.main -re node")
14+
repl:cljs-browser (shell "rlwrap bb clojure -M:test:cljs -m cljs.main")}}

deps.edn

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
quoin/quoin
66
{:mvn/version "0.1.2", :exclusions [org.clojure/clojure]}},
77
:aliases
8-
{:dev
9-
{:extra-deps
10-
{org.clojure/clojurescript {:mvn/version "1.9.293"},
11-
viebel/codox-klipse-theme {:mvn/version "0.0.1"}}}}}
8+
{:test {:extra-paths ["test/cljc"]}
9+
:cljs {:extra-deps {org.clojure/clojurescript {:mvn/version "1.11.60"}}}
10+
:cljs-test-runner
11+
{:extra-deps {olical/cljs-test-runner {:mvn/version "3.8.0"}
12+
viebel/codox-klipse-theme {:mvn/version "0.0.1"}}
13+
:extra-paths ["cljs-test-runner-out"]
14+
:main-opts ["-m" "cljs-test-runner.main" "--namespace-regex" "hickory.test.*"]}}}

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"devDependencies": {
3+
"karma": "^6.4.1",
4+
"karma-chrome-launcher": "^3.1.1",
5+
"karma-cli": "^2.0.0",
6+
"karma-cljs-test": "^0.1.0"
7+
}
8+
}

project.clj

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,13 @@
1515
[quoin "0.1.2" :exclusions [org.clojure/clojure]]
1616
[viebel/codox-klipse-theme "0.0.1" :scope "provided"]]
1717

18-
:hooks [leiningen.cljsbuild]
19-
2018
:plugins [[lein-codox "0.10.0"]]
21-
:doo {:build "test"}
2219

2320
:source-paths ["src/clj" "src/cljc" "src/cljs"]
2421

25-
:cljsbuild {:builds {}
26-
:test-commands {"unit-tests" ["lein" "with-profile" "test" "doo" "phantom" "once"]}}
27-
2822
:profiles
29-
{:dev {:source-paths ["src/clj" "src/cljc"]
30-
:dependencies [[lein-doo "0.1.11"]]
31-
:plugins [[lein-cljsbuild "1.1.8"]
32-
[lein-doo "0.1.11" :exclusions [org.clojure/clojure]]]}
33-
:test {:source-paths ["src/cljs" "src/cljc" "test/cljc" "test/cljs"]
34-
:plugins [[lein-doo "0.1.11" :exclusions [org.clojure/clojure]]]
35-
:cljsbuild {:builds {:test {:source-paths ["src/cljs" "src/cljc" "test/cljc" "test/cljs"]
36-
:compiler {:output-to "target/cljs/testable.js"
37-
:main "hickory.doo-runner"}
38-
:optimizations :whitespace
39-
:pretty-print true}}}
40-
}}
23+
{:dev {:source-paths ["src/clj" "src/cljc"]}
24+
:test {:source-paths ["src/cljs" "src/cljc" "test/cljc" "test/cljs"]}}
4125

4226
:codox {:sources ["src" "target/generated-src"]
4327
:output-path "codox-out"

src/cljs/hickory/core.cljs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
(:require [hickory.utils :as utils]
33
[clojure.zip :as zip]
44
[goog.string :as gstring]
5-
[goog.dom :as dom]))
5+
[goog.dom]))
66

77
;;
88
;; Protocols
@@ -35,7 +35,7 @@
3535

3636
(defn node-type
3737
[type]
38-
(aget dom/NodeType type))
38+
(aget goog.dom.NodeType type))
3939

4040
(def Attribute (node-type "ATTRIBUTE"))
4141
(def Comment (node-type "COMMENT"))
@@ -52,7 +52,7 @@
5252
(let [name (aget dt "name")
5353
publicId (aget dt "publicId")
5454
systemId (aget dt "systemId")]
55-
(if (not (empty? publicId))
55+
(if (seq publicId)
5656
(gstring/format "<!DOCTYPE %s PUBLIC \"%s\" \"%s\">" name publicId systemId)
5757
(str "<!DOCTYPE " name ">"))))
5858

@@ -80,9 +80,9 @@
8080
(into [] (concat [tag
8181
(into {} (map as-hiccup (as-seq (aget this "attributes"))))]
8282
(if (utils/unescapable-content tag)
83-
(map dom/getRawTextContent (as-seq (aget this "childNodes")))
83+
(map goog.dom.getRawTextContent (as-seq (aget this "childNodes")))
8484
(map as-hiccup (as-seq (aget this "childNodes")))))))
85-
Text (utils/html-escape (dom/getRawTextContent this)))))
85+
Text (utils/html-escape (goog.dom.getRawTextContent this)))))
8686

8787
(extend-protocol HickoryRepresentable
8888
object
@@ -104,7 +104,7 @@
104104
:content (not-empty
105105
(into [] (map as-hickory
106106
(as-seq (aget this "childNodes")))))}
107-
Text (dom/getRawTextContent this))))
107+
Text (goog.dom.getRawTextContent this))))
108108

109109
(defn extract-doctype
110110
[s]
@@ -119,7 +119,7 @@
119119

120120
(defn parse-dom-with-domparser
121121
[s]
122-
(if (exists? js/DOMParser)
122+
(when (exists? js/DOMParser)
123123
(.parseFromString (js/DOMParser.) s "text/html")))
124124

125125
(defn parse-dom-with-write

test/cljc/hickory/test/convert.cljc

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
(ns hickory.test.convert
2-
(:require [hickory.convert :refer [hiccup-fragment-to-hickory hiccup-to-hickory hickory-to-hiccup]]
3-
[hickory.core :refer [as-hickory as-hiccup parse parse-fragment]]
4-
#?(:clj
5-
[clojure.test :refer :all]
6-
:cljs [cljs.test :refer-macros [is are deftest testing use-fixtures]]))
7-
)
2+
(:require
3+
[clojure.test :refer [deftest is]]
4+
[hickory.convert :refer [hiccup-fragment-to-hickory hiccup-to-hickory
5+
hickory-to-hiccup]]
6+
[hickory.core :refer [as-hiccup as-hickory parse parse-fragment]]))
87

98
(deftest hiccup-to-hickory-test
109
(is (= (as-hickory (parse "<i>Hi.</i>"))

test/cljc/hickory/test/render.cljc

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
(ns hickory.test.render
2-
(:require [hickory.core :refer [as-hiccup as-hickory parse parse-fragment]]
3-
[hickory.render :refer [hiccup-to-html hickory-to-html]]
4-
#?(:clj
5-
[clojure.test :refer :all]
6-
:cljs [cljs.test :refer-macros [is are deftest testing use-fixtures]])))
2+
(:require
3+
[clojure.test :refer [deftest is]]
4+
[hickory.core :refer [as-hiccup as-hickory parse parse-fragment]]
5+
[hickory.render :refer [hiccup-to-html hickory-to-html]]))
76
;;
87
;; Hickory to HTML
98
;;
@@ -20,7 +19,7 @@
2019
;; Make sure the contents of script/style tags do not get html escaped.
2120
(is (= "<script>Test<!--Test&Test-->Test</script>"
2221
(hickory-to-html (as-hickory
23-
(first (parse-fragment "<script>Test<!--Test&Test-->Test</script>"))))))
22+
(first (parse-fragment "<body><script>Test<!--Test&Test-->Test</script></body>"))))))
2423
;; Make sure attribute contents are html-escaped.
2524
(is (= "<img fake-attr=\"abc&quot;def\">"
2625
(hickory-to-html (as-hickory (first (parse-fragment "<img fake-attr=\"abc&quot;def\">")))))))
@@ -71,7 +70,7 @@
7170
;; Make sure the contents of script/style tags do not get html escaped.
7271
(is (= "<script>Test<!--Test&Test-->Test</script>"
7372
(hiccup-to-html [(as-hiccup
74-
(first (parse-fragment "<script>Test<!--Test&Test-->Test</script>")))])))
73+
(first (parse-fragment "<body><script>Test<!--Test&Test-->Test</script></body>")))])))
7574
;; Make sure attribute contents are html-escaped.
7675
(is (= "<img fake-attr=\"abc&quot;def\">"
7776
(hiccup-to-html [(as-hiccup (first (parse-fragment "<img fake-attr=\"abc&quot;def\">")))]))))

0 commit comments

Comments
 (0)