├── .gitignore ├── README.md ├── images └── clj-test-for-js.jpg ├── project.clj ├── resources └── public │ └── figwheel.html └── src ├── js_test_in_cljs └── test │ ├── core_test.cljs │ └── runner.cljs └── main.js /.gitignore: -------------------------------------------------------------------------------- 1 | pom.xml 2 | pom.xml.asc 3 | *jar 4 | /lib/ 5 | /classes/ 6 | /target/ 7 | /checkouts/ 8 | .lein-deps-sum 9 | .lein-repl-history 10 | .lein-plugins/ 11 | .lein-failures 12 | .nrepl-port 13 | figwheel_server.log 14 | resources/public/fig/* 15 | resources/public/test/* 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Rationale 2 | 3 | `Clojurescript` provides powerful tools and semantics for testing code like `deftest` and `test.check` (generative testing). 4 | This repository is a template for testing `javascript` code with `clojurescript` code. 5 | 6 | 7 | # Structure 8 | 9 | There is a `javascript` file `main.js` that defines a `javascript` function `foo`. 10 | 11 | There is a `clojurescript` file `core_test.cljs` that tests `foo`. 12 | 13 |  14 | 15 | In `project.clj`, `main.js` is defined as a `:foreign-libs`, so we can `:require` it from `clojurescript`. 16 | 17 | The tests are run with [lein doo](https://github.com/bensu/doo). 18 | 19 | Simple, no? 20 | 21 | # How to run 22 | ```bash 23 | lein doo phantom test 24 | ``` 25 | 26 | Modify the code of the test inside `src/js_test_in_cljs/test/core_test.cljs` and the tests re-run automatically in under 1 second. 27 | 28 | 29 | -------------------------------------------------------------------------------- /images/clj-test-for-js.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viebel/template-test-js-with-clj/a20c7e856f2bfa6218eef6d5c8c5c252a2ef98b3/images/clj-test-for-js.jpg -------------------------------------------------------------------------------- /project.clj: -------------------------------------------------------------------------------- 1 | (defproject js-test-in-cljs "0.0.1" 2 | :description "Test Javascript code in clojurescript" 3 | :dependencies [[org.clojure/clojure "1.8.0"] 4 | [org.clojure/clojurescript "1.9.36"] 5 | [org.clojure/test.check "0.9.0"]] 6 | :clean-targets ^{:protect false} ["resources/public/test/js"] 7 | :plugins [[lein-doo "0.1.6"]] 8 | :source-paths ["src"] 9 | :cljsbuild {:builds 10 | {:test 11 | {:source-paths ["src"] 12 | :compiler 13 | {:main "js-test-in-cljs.test.runner" 14 | :foreign-libs [{:file "main.js" 15 | :provides ["js.main"]}] 16 | :optimizations :none 17 | :output-to "resources/public/test/js/testable.js" 18 | :output-dir "resources/public/test/js"}}}}) 19 | -------------------------------------------------------------------------------- /resources/public/figwheel.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 |