diff --git a/Makefile b/Makefile index 04d1dc45cd..912168dd34 100644 --- a/Makefile +++ b/Makefile @@ -335,26 +335,44 @@ shadow-server: export TARGET := clojure shadow-server:##@ Start shadow-cljs in server mode for watching yarn shadow-cljs server -test-watch: export TARGET := clojure -test-watch: ##@ Watch tests and re-run no changes to cljs files - yarn install - nodemon --exec 'yarn shadow-cljs compile mocks && yarn shadow-cljs compile test && node --require ./test-resources/override.js target/test/test.js' -e cljs - -test-watch-for-repl: export TARGET := clojure -test-watch-for-repl: ##@ Watch tests and support REPL connections - yarn install - rm -f target/test/test.js - concurrently --kill-others --prefix-colors 'auto' --names 'build,repl' \ - 'yarn shadow-cljs compile mocks && yarn shadow-cljs watch test --verbose' \ - 'until [ -f ./target/test/test.js ] ; do sleep 1 ; done ; node --require ./test-resources/override.js ./target/test/test.js --repl' - -test: export TARGET := clojure -test: ##@test Run tests once in NodeJS - # Here we create the gyp bindings for nodejs - yarn install +_test-clojure: export TARGET := clojure +_test-clojure: export WATCH ?= false +_test-clojure: +ifeq ($(WATCH), true) + yarn install && \ + yarn shadow-cljs compile mocks && \ + nodemon --exec "yarn shadow-cljs compile test && node --require ./test-resources/override.js $$SHADOW_OUTPUT_TO" -e cljs +else + yarn install && \ yarn shadow-cljs compile mocks && \ yarn shadow-cljs compile test && \ - node --require ./test-resources/override.js target/test/test.js + node --require ./test-resources/override.js "$$SHADOW_OUTPUT_TO" +endif + +test: export SHADOW_OUTPUT_TO := target/test/test.js +test: export SHADOW_NS_REGEXP := .*-test$$ +test: ##@test Run all Clojure tests +test: _test-clojure + +test-watch-for-repl: export SHADOW_OUTPUT_TO := target/test/test.js +test-watch-for-repl: export SHADOW_NS_REGEXP := .*-test$$ +test-watch-for-repl: ##@test Watch all Clojure tests and support REPL connections + yarn install + rm -f target/test/test.js + yarn shadow-cljs compile mocks && \ + concurrently --kill-others --prefix-colors 'auto' --names 'build,repl' \ + 'yarn shadow-cljs watch test --verbose' \ + "until [ -f $$SHADOW_OUTPUT_TO ] ; do sleep 1 ; done ; node --require ./test-resources/override.js $$SHADOW_OUTPUT_TO --repl" + +test-unit: export SHADOW_OUTPUT_TO := target/unit_test/test.js +test-unit: export SHADOW_NS_REGEXP := ^(?!status-im\.integration-test).*-test$$ +test-unit: ##@test Run unit tests +test-unit: _test-clojure + +test-integration: export SHADOW_OUTPUT_TO := target/integration_test/test.js +test-integration: export SHADOW_NS_REGEXP := ^status-im\.integration-test.*$$ +test-integration: ##@test Run integration tests +test-integration: _test-clojure android-test: jsbundle android-test: export TARGET := android diff --git a/ci/Jenkinsfile.tests b/ci/Jenkinsfile.tests index 5e8ac4afe7..19d324c852 100644 --- a/ci/Jenkinsfile.tests +++ b/ci/Jenkinsfile.tests @@ -52,16 +52,24 @@ pipeline { """ } } - stage('Tests') { + stage('Unit Tests') { steps { sh """#!/bin/bash set -eo pipefail - make test 2>&1 | tee -a ${LOG_FILE} + make test-unit 2>&1 | tee -a ${LOG_FILE} """ } } } } + stage('Integration Tests') { + steps { + sh """#!/bin/bash + set -eo pipefail + make test-integration 2>&1 | tee -a ${LOG_FILE} + """ + } + } stage('Component Tests') { steps { sh """#!/bin/bash diff --git a/doc/testing.md b/doc/testing.md index 1d8e299129..82b14078ff 100644 --- a/doc/testing.md +++ b/doc/testing.md @@ -5,7 +5,7 @@ To run tests: ``` - make test +make test ``` @@ -13,10 +13,10 @@ To run tests: Also test watcher can be launched. It will re-run the entire test suite when any file is modified ``` - make test-watch +make test WATCH=true ``` -Developers can also manually change the shadow-cljs option `:ns-regex` to control which namespaces the test runner should pick. +Developers can also manually change the shadow-cljs option `:ns-regex` to control which namespaces the test runner should pick. ## Testing with REPL diff --git a/shadow-cljs.edn b/shadow-cljs.edn index afa3820fbc..634110408e 100644 --- a/shadow-cljs.edn +++ b/shadow-cljs.edn @@ -108,13 +108,13 @@ ;; produced by the target :mocks below and redefines node require ;; function to use the mocks instead of the rn libraries :test - {:output-to "target/test/test.js" + {:output-to #shadow/env "SHADOW_OUTPUT_TO" :output-dir "target/test" :optimizations :simple :target :node-test :dev {:devtools {:preloads [status-im.setup.schema-preload]}} ;; Uncomment line below to `make test-watch` a specific file - ;; :ns-regexp "status-im.subs.messages-test$" + :ns-regexp #shadow/env "SHADOW_NS_REGEXP" :main legacy.status-im.test-runner/main ;; set :ui-driven to true to let shadow-cljs inject node-repl :ui-driven true