Skip to content

Commit

Permalink
Run tests with new CLJS on Github Actions (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude authored Nov 20, 2022
1 parent 7651f93 commit 92499fd
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 45 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: ci

on: [push, pull_request]

jobs:

clojure:

strategy:
matrix:
os: [ubuntu-latest]

runs-on: ${{ matrix.os }}

steps:
- name: Checkout
uses: actions/checkout@v3

# It is important to install java before installing clojure tools which needs java
# exclusions: babashka, clj-kondo and cljstyle
- name: Prepare java
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '8'

- name: Install clojure tools
uses: DeLaGuardo/[email protected]
with:
bb: latest
lein: latest
# Optional step:
- name: Cache clojure dependencies
uses: actions/cache@v3
with:
path: |
~/.m2/repository
~/.gitlibs
~/.deps.clj
# List all files containing dependencies:
key: cljdeps-${{ hashFiles('deps.edn') }}
# key: cljdeps-${{ hashFiles('deps.edn', 'bb.edn') }}
# key: cljdeps-${{ hashFiles('project.clj') }}
# key: cljdeps-${{ hashFiles('build.boot') }}
restore-keys: cljdeps-

- name: Execute clj tests
run: bb test:clj

- name: Execute cljs tests
run: |
bb test:cljs-npm-install
bb test:cljs
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ pom.xml
out/
.cpcache
.cache
cljs-test-runner-out
node_modules

package-lock.json
15 changes: 12 additions & 3 deletions bb.edn
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
{:deps {io.github.borkdude/lein2deps {:git/url "https://github.com/borkdude/lein2deps"
:git/sha "e26edeb114c9d88a5c4d3abb683306588fcaad13"}}
:tasks {lein2deps {:doc "Generate deps.edn from project.clj"
:requires ([lein2deps.api :as lein2deps])
:task (lein2deps/lein2deps {:write-file "deps.edn"})}} }
:tasks
{:requires ([babashka.fs :as fs])

test:clj (shell "lein test")

test:cljs-npm-install (do (shell "npm install -g karma-cli")
(shell "npm install"))
test:cljs (do
(fs/delete-tree "cljs-test-runner-out")
(apply clojure "-M:test:cljs:cljs-test-runner" "--env" "chrome-headless" *command-line-args*))
repl:cljs-node (shell "rlwrap bb clojure -M:test:cljs -m cljs.main -re node")
repl:cljs-browser (shell "rlwrap bb clojure -M:test:cljs -m cljs.main")}}
11 changes: 7 additions & 4 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
quoin/quoin
{:mvn/version "0.1.2", :exclusions [org.clojure/clojure]}},
:aliases
{:dev
{:extra-deps
{org.clojure/clojurescript {:mvn/version "1.9.293"},
viebel/codox-klipse-theme {:mvn/version "0.0.1"}}}}}
{:test {:extra-paths ["test/cljc"]}
:cljs {:extra-deps {org.clojure/clojurescript {:mvn/version "1.11.60"}}}
:cljs-test-runner
{:extra-deps {olical/cljs-test-runner {:mvn/version "3.8.0"}
viebel/codox-klipse-theme {:mvn/version "0.0.1"}}
:extra-paths ["cljs-test-runner-out"]
:main-opts ["-m" "cljs-test-runner.main" "--namespace-regex" "hickory.test.*"]}}}
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"devDependencies": {
"karma": "^6.4.1",
"karma-chrome-launcher": "^3.1.1",
"karma-cli": "^2.0.0",
"karma-cljs-test": "^0.1.0"
}
}
20 changes: 2 additions & 18 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,13 @@
[quoin "0.1.2" :exclusions [org.clojure/clojure]]
[viebel/codox-klipse-theme "0.0.1" :scope "provided"]]

:hooks [leiningen.cljsbuild]

:plugins [[lein-codox "0.10.0"]]
:doo {:build "test"}

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

:cljsbuild {:builds {}
:test-commands {"unit-tests" ["lein" "with-profile" "test" "doo" "phantom" "once"]}}

:profiles
{:dev {:source-paths ["src/clj" "src/cljc"]
:dependencies [[lein-doo "0.1.11"]]
:plugins [[lein-cljsbuild "1.1.8"]
[lein-doo "0.1.11" :exclusions [org.clojure/clojure]]]}
:test {:source-paths ["src/cljs" "src/cljc" "test/cljc" "test/cljs"]
:plugins [[lein-doo "0.1.11" :exclusions [org.clojure/clojure]]]
:cljsbuild {:builds {:test {:source-paths ["src/cljs" "src/cljc" "test/cljc" "test/cljs"]
:compiler {:output-to "target/cljs/testable.js"
:main "hickory.doo-runner"}
:optimizations :whitespace
:pretty-print true}}}
}}
{:dev {:source-paths ["src/clj" "src/cljc"]}
:test {:source-paths ["src/cljs" "src/cljc" "test/cljc" "test/cljs"]}}

:codox {:sources ["src" "target/generated-src"]
:output-path "codox-out"
Expand Down
14 changes: 7 additions & 7 deletions src/cljs/hickory/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(:require [hickory.utils :as utils]
[clojure.zip :as zip]
[goog.string :as gstring]
[goog.dom :as dom]))
[goog.dom]))

;;
;; Protocols
Expand Down Expand Up @@ -35,7 +35,7 @@

(defn node-type
[type]
(aget dom/NodeType type))
(aget goog.dom.NodeType type))

(def Attribute (node-type "ATTRIBUTE"))
(def Comment (node-type "COMMENT"))
Expand All @@ -52,7 +52,7 @@
(let [name (aget dt "name")
publicId (aget dt "publicId")
systemId (aget dt "systemId")]
(if (not (empty? publicId))
(if (seq publicId)
(gstring/format "<!DOCTYPE %s PUBLIC \"%s\" \"%s\">" name publicId systemId)
(str "<!DOCTYPE " name ">"))))

Expand Down Expand Up @@ -80,9 +80,9 @@
(into [] (concat [tag
(into {} (map as-hiccup (as-seq (aget this "attributes"))))]
(if (utils/unescapable-content tag)
(map dom/getRawTextContent (as-seq (aget this "childNodes")))
(map goog.dom.getRawTextContent (as-seq (aget this "childNodes")))
(map as-hiccup (as-seq (aget this "childNodes")))))))
Text (utils/html-escape (dom/getRawTextContent this)))))
Text (utils/html-escape (goog.dom.getRawTextContent this)))))

(extend-protocol HickoryRepresentable
object
Expand All @@ -104,7 +104,7 @@
:content (not-empty
(into [] (map as-hickory
(as-seq (aget this "childNodes")))))}
Text (dom/getRawTextContent this))))
Text (goog.dom.getRawTextContent this))))

(defn extract-doctype
[s]
Expand All @@ -119,7 +119,7 @@

(defn parse-dom-with-domparser
[s]
(if (exists? js/DOMParser)
(when (exists? js/DOMParser)
(.parseFromString (js/DOMParser.) s "text/html")))

(defn parse-dom-with-write
Expand Down
11 changes: 5 additions & 6 deletions test/cljc/hickory/test/convert.cljc
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
(ns hickory.test.convert
(:require [hickory.convert :refer [hiccup-fragment-to-hickory hiccup-to-hickory hickory-to-hiccup]]
[hickory.core :refer [as-hickory as-hiccup parse parse-fragment]]
#?(:clj
[clojure.test :refer :all]
:cljs [cljs.test :refer-macros [is are deftest testing use-fixtures]]))
)
(:require
[clojure.test :refer [deftest is]]
[hickory.convert :refer [hiccup-fragment-to-hickory hiccup-to-hickory
hickory-to-hiccup]]
[hickory.core :refer [as-hiccup as-hickory parse parse-fragment]]))

(deftest hiccup-to-hickory-test
(is (= (as-hickory (parse "<i>Hi.</i>"))
Expand Down
13 changes: 6 additions & 7 deletions test/cljc/hickory/test/render.cljc
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
(ns hickory.test.render
(:require [hickory.core :refer [as-hiccup as-hickory parse parse-fragment]]
[hickory.render :refer [hiccup-to-html hickory-to-html]]
#?(:clj
[clojure.test :refer :all]
:cljs [cljs.test :refer-macros [is are deftest testing use-fixtures]])))
(:require
[clojure.test :refer [deftest is]]
[hickory.core :refer [as-hiccup as-hickory parse parse-fragment]]
[hickory.render :refer [hiccup-to-html hickory-to-html]]))
;;
;; Hickory to HTML
;;
Expand All @@ -20,7 +19,7 @@
;; Make sure the contents of script/style tags do not get html escaped.
(is (= "<script>Test<!--Test&Test-->Test</script>"
(hickory-to-html (as-hickory
(first (parse-fragment "<script>Test<!--Test&Test-->Test</script>"))))))
(first (parse-fragment "<body><script>Test<!--Test&Test-->Test</script></body>"))))))
;; Make sure attribute contents are html-escaped.
(is (= "<img fake-attr=\"abc&quot;def\">"
(hickory-to-html (as-hickory (first (parse-fragment "<img fake-attr=\"abc&quot;def\">")))))))
Expand Down Expand Up @@ -71,7 +70,7 @@
;; Make sure the contents of script/style tags do not get html escaped.
(is (= "<script>Test<!--Test&Test-->Test</script>"
(hiccup-to-html [(as-hiccup
(first (parse-fragment "<script>Test<!--Test&Test-->Test</script>")))])))
(first (parse-fragment "<body><script>Test<!--Test&Test-->Test</script></body>")))])))
;; Make sure attribute contents are html-escaped.
(is (= "<img fake-attr=\"abc&quot;def\">"
(hiccup-to-html [(as-hiccup (first (parse-fragment "<img fake-attr=\"abc&quot;def\">")))]))))
Expand Down

0 comments on commit 92499fd

Please sign in to comment.