From 7f58eb340404fae42c2e3c3900c1eb5c5f183792 Mon Sep 17 00:00:00 2001 From: Geoffrey Gaillard Date: Fri, 15 Apr 2022 18:49:39 +0200 Subject: [PATCH] Add test scripts - requires npm install --- .github/workflows/tests.yml | 7 ++----- ci/run_tests_all.sh | 4 ++++ ci/run_tests_browser.sh | 5 +++++ run_tests.sh => ci/run_tests_jvm.sh | 1 + ci/run_tests_node.sh | 5 +++++ ci/running_dom_tests.md | 8 ++++++++ karma.conf.js | 18 ++++++++++++++++++ package.json | 7 ++++++- shadow-cljs.edn | 9 ++++++++- 9 files changed, 57 insertions(+), 7 deletions(-) create mode 100755 ci/run_tests_all.sh create mode 100755 ci/run_tests_browser.sh rename run_tests.sh => ci/run_tests_jvm.sh (84%) create mode 100755 ci/run_tests_node.sh create mode 100644 ci/running_dom_tests.md create mode 100644 karma.conf.js diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index dd7ee5753..8a326f1ed 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -42,7 +42,7 @@ jobs: run: clojure -A:test -P - name: Run tests - run: clojure -X:test :dirs "[\"src\" \"src-docs\" \"test\"]" :patterns "[\"hyperfiddle.photon-impl.*\" \"hyperfiddle.photon-test\"]" + run: ./ci/run_tests_jvm.sh photon-nodejs: # if: ${{ false }} # Disabled until we fix the cljs test suite locally @@ -93,8 +93,5 @@ jobs: - name: Install Shadow run: npm install shadow-cljs - - name: Compile Tests - run: ./node_modules/.bin/shadow-cljs -A:test compile :test - - name: Run Tests - run: node out/node-tests.js + run: ./ci/run_tests_node.sh diff --git a/ci/run_tests_all.sh b/ci/run_tests_all.sh new file mode 100755 index 000000000..55fe6ee80 --- /dev/null +++ b/ci/run_tests_all.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +./run_tests_jvm.sh +./run_tests_node.sh \ No newline at end of file diff --git a/ci/run_tests_browser.sh b/ci/run_tests_browser.sh new file mode 100755 index 000000000..554f5386b --- /dev/null +++ b/ci/run_tests_browser.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +echo "Running Browser tests" +./node_modules/.bin/shadow-cljs -A:test compile :browser-test +./node_modules/.bin/karma start --single-run diff --git a/run_tests.sh b/ci/run_tests_jvm.sh similarity index 84% rename from run_tests.sh rename to ci/run_tests_jvm.sh index f547d59c5..e3b92a762 100755 --- a/run_tests.sh +++ b/ci/run_tests_jvm.sh @@ -1,3 +1,4 @@ #!/bin/bash +echo "Running JVM tests" clojure -X:test :dirs "[\"src\" \"src-docs\" \"test\"]" :patterns "[\"hyperfiddle.photon-impl.*\" \"hyperfiddle.photon-test\"]" diff --git a/ci/run_tests_node.sh b/ci/run_tests_node.sh new file mode 100755 index 000000000..6b64c502b --- /dev/null +++ b/ci/run_tests_node.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +echo "Running NodeJS tests" +./node_modules/.bin/shadow-cljs -A:test compile :test +node out/node-tests.js diff --git a/ci/running_dom_tests.md b/ci/running_dom_tests.md new file mode 100644 index 000000000..6f823f182 --- /dev/null +++ b/ci/running_dom_tests.md @@ -0,0 +1,8 @@ +# How to run tests in a browser during dev time + +## Running once +Use the `run_tests_browser.sh` script. + +## Live reloading +1. Start a watch build for `:browser-test` (either in shadow ui, or `shadow-cljs -A:test watch :browser-test`) +2. Run `./node_modules/.bin/karma start --browsers Chrome` \ No newline at end of file diff --git a/karma.conf.js b/karma.conf.js new file mode 100644 index 000000000..3feb4c61e --- /dev/null +++ b/karma.conf.js @@ -0,0 +1,18 @@ +process.env.CHROMIUM_BIN = require('puppeteer').executablePath() +module.exports = function (config) { + config.set({ + browsers: ['ChromiumHeadless'], + // The directory where the output file lives + basePath: 'out', + // The file itself + files: ['karma-tests.js'], + frameworks: ['cljs-test'], + plugins: ['karma-cljs-test', 'karma-chrome-launcher'], + colors: true, + logLevel: config.LOG_INFO, + client: { + args: ["shadow.test.karma.init"], + singleRun: true + } + }); +}; diff --git a/package.json b/package.json index f32d5122f..51a45a19f 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,11 @@ "postcss": "^8.2.13", "postcss-cli": "^8.3.1", "tailwindcss": "^2.1.2", - "typescript": "^4.2.4" + "typescript": "^4.2.4", + "karma": "6.3.17", + "karma-chrome-launcher": "3.1.1", + "karma-cljs-test": "0.1.0", + "puppeteer": "13.5.2", + "shadow-cljs": "2.16.4" } } diff --git a/shadow-cljs.edn b/shadow-cljs.edn index 90cac29a8..edbcada5d 100644 --- a/shadow-cljs.edn +++ b/shadow-cljs.edn @@ -45,4 +45,11 @@ :build-options {:cache-level :off} :modules {:main {:entries [hyperfiddle.photon hyperfiddle.photon-test]}} :dev {:closure-defines {hyperfiddle.dev.logger/LEVEL "debug"}} - :compiler-options {:warnings {:redef-in-file false}}}}} + :compiler-options {:warnings {:redef-in-file false}}} + :browser-test {:target :karma + :output-to "out/karma-tests.js" + :ns-regexp "^hyperfiddle.photon-.*$" + :build-options {:cache-level :off} + :modules {:main {:entries [hyperfiddle.photon hyperfiddle.photon-test]}} + :dev {:closure-defines {hyperfiddle.dev.logger/LEVEL "debug"}} + :compiler-options {:warnings {:redef-in-file false}}}}}