From 270aa509ac99c992b5ebb19e89f6892ed2c12ebe Mon Sep 17 00:00:00 2001 From: Icaro Motta Date: Tue, 26 Dec 2023 11:44:11 -0300 Subject: [PATCH 1/4] Split Clojure integration tests from unit tests --- Makefile | 56 ++++++++++++++++++++++++++++++++++++++------ ci/Jenkinsfile.tests | 12 ++++++++-- shadow-cljs.edn | 4 ++-- 3 files changed, 61 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 04d1dc45cd5..4d08546af4e 100644 --- a/Makefile +++ b/Makefile @@ -335,26 +335,68 @@ shadow-server: export TARGET := clojure shadow-server:##@ Start shadow-cljs in server mode for watching yarn shadow-cljs server +test: export TARGET := clojure +test: export SHADOW_OUTPUT_TO := target/test/test.js +test: export SHADOW_NS_REGEXP := .*-test$$ +test: ##@test Run all Clojure tests + yarn install + yarn shadow-cljs compile mocks && \ + yarn shadow-cljs compile test && \ + node --require ./test-resources/override.js target/test/test.js + test-watch: export TARGET := clojure -test-watch: ##@ Watch tests and re-run no changes to cljs files +test-watch: export SHADOW_OUTPUT_TO := target/test/test.js +test-watch: export SHADOW_NS_REGEXP := .*-test$$ +test-watch: ##@test Watch all Clojure tests and re-run when files change 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 + yarn shadow-cljs compile mocks && \ + nodemon --exec '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 +test-watch-for-repl: export SHADOW_OUTPUT_TO := target/test/test.js +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 compile mocks && yarn shadow-cljs watch test --verbose' \ + '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 +unit-test: export TARGET := clojure +unit-test: export SHADOW_OUTPUT_TO := target/unit_test/test.js +unit-test: export SHADOW_NS_REGEXP := ^(?!status-im\.integration-test).*-test$$ +unit-test: ##@test Run unit tests # Here we create the gyp bindings for nodejs 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 target/unit_test/test.js + +unit-test-watch: export TARGET := clojure +unit-test-watch: export SHADOW_OUTPUT_TO := target/unit_test/test.js +unit-test-watch: export SHADOW_NS_REGEXP := ^(?!status-im\.integration-test).*-test$$ +unit-test-watch: ##@test Watch unit tests and re-run when files change + yarn install + yarn shadow-cljs compile mocks && \ + nodemon --exec 'yarn shadow-cljs compile test && node --require ./test-resources/override.js target/unit_test/test.js' -e cljs + +integration-test: export TARGET := clojure +integration-test: export SHADOW_OUTPUT_TO := target/integration_test/test.js +integration-test: export SHADOW_NS_REGEXP := ^status-im\.integration-test.*$$ +integration-test: ##@test Run integration tests + # Here we create the gyp bindings for nodejs + yarn install + yarn shadow-cljs compile mocks && \ + yarn shadow-cljs compile test && \ + node --require ./test-resources/override.js target/integration_test/test.js + +integration-test-watch: export TARGET := clojure +integration-test-watch: export SHADOW_OUTPUT_TO := target/integration_test/test.js +integration-test-watch: export SHADOW_NS_REGEXP := ^status-im\.integration-test.*$$ +integration-test-watch: ##@test Watch integration tests and re-run when files change + yarn install + yarn shadow-cljs compile mocks && \ + nodemon --exec 'yarn shadow-cljs compile test && node --require ./test-resources/override.js target/integration_test/test.js' -e cljs android-test: jsbundle android-test: export TARGET := android diff --git a/ci/Jenkinsfile.tests b/ci/Jenkinsfile.tests index 5e8ac4afe76..f461b655694 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 unit-test 2>&1 | tee -a ${LOG_FILE} """ } } } } + stage('Integration Tests') { + steps { + sh """#!/bin/bash + set -eo pipefail + make integration-test 2>&1 | tee -a ${LOG_FILE} + """ + } + } stage('Component Tests') { steps { sh """#!/bin/bash diff --git a/shadow-cljs.edn b/shadow-cljs.edn index afa3820fbc5..634110408ef 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 From 141fb8aa6c48fa782d80155988cc705d6ab9bd60 Mon Sep 17 00:00:00 2001 From: Icaro Motta Date: Wed, 27 Dec 2023 11:51:40 -0300 Subject: [PATCH 2/4] Refactor: DRY out make targets --- Makefile | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index 4d08546af4e..2d9a8c8b4d2 100644 --- a/Makefile +++ b/Makefile @@ -335,68 +335,63 @@ shadow-server: export TARGET := clojure shadow-server:##@ Start shadow-cljs in server mode for watching yarn shadow-cljs server +_clojure-test: + yarn install && \ + yarn shadow-cljs compile mocks && \ + yarn shadow-cljs compile test && \ + node --require ./test-resources/override.js "$$SHADOW_OUTPUT_TO" + +_clojure-test-watch: + 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 + test: export TARGET := clojure test: export SHADOW_OUTPUT_TO := target/test/test.js test: export SHADOW_NS_REGEXP := .*-test$$ test: ##@test Run all Clojure tests - yarn install - yarn shadow-cljs compile mocks && \ - yarn shadow-cljs compile test && \ - node --require ./test-resources/override.js target/test/test.js +test: _clojure-test test-watch: export TARGET := clojure test-watch: export SHADOW_OUTPUT_TO := target/test/test.js test-watch: export SHADOW_NS_REGEXP := .*-test$$ test-watch: ##@test Watch all Clojure tests and re-run when files change - yarn install - yarn shadow-cljs compile mocks && \ - nodemon --exec 'yarn shadow-cljs compile test && node --require ./test-resources/override.js target/test/test.js' -e cljs +test-watch: _clojure-test-watch test-watch-for-repl: export TARGET := 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 ./target/test/test.js ] ; do sleep 1 ; done ; node --require ./test-resources/override.js ./target/test/test.js --repl' + "until [ -f $$SHADOW_OUTPUT_TO ] ; do sleep 1 ; done ; node --require ./test-resources/override.js $$SHADOW_OUTPUT_TO --repl" unit-test: export TARGET := clojure unit-test: export SHADOW_OUTPUT_TO := target/unit_test/test.js unit-test: export SHADOW_NS_REGEXP := ^(?!status-im\.integration-test).*-test$$ unit-test: ##@test Run unit tests - # Here we create the gyp bindings for nodejs - yarn install - yarn shadow-cljs compile mocks && \ - yarn shadow-cljs compile test && \ - node --require ./test-resources/override.js target/unit_test/test.js +unit-test: _clojure-test unit-test-watch: export TARGET := clojure unit-test-watch: export SHADOW_OUTPUT_TO := target/unit_test/test.js unit-test-watch: export SHADOW_NS_REGEXP := ^(?!status-im\.integration-test).*-test$$ unit-test-watch: ##@test Watch unit tests and re-run when files change - yarn install - yarn shadow-cljs compile mocks && \ - nodemon --exec 'yarn shadow-cljs compile test && node --require ./test-resources/override.js target/unit_test/test.js' -e cljs +unit-test-watch: _clojure-test-watch integration-test: export TARGET := clojure integration-test: export SHADOW_OUTPUT_TO := target/integration_test/test.js integration-test: export SHADOW_NS_REGEXP := ^status-im\.integration-test.*$$ integration-test: ##@test Run integration tests - # Here we create the gyp bindings for nodejs - yarn install - yarn shadow-cljs compile mocks && \ - yarn shadow-cljs compile test && \ - node --require ./test-resources/override.js target/integration_test/test.js +integration-test: _clojure-test integration-test-watch: export TARGET := clojure integration-test-watch: export SHADOW_OUTPUT_TO := target/integration_test/test.js integration-test-watch: export SHADOW_NS_REGEXP := ^status-im\.integration-test.*$$ integration-test-watch: ##@test Watch integration tests and re-run when files change - yarn install - yarn shadow-cljs compile mocks && \ - nodemon --exec 'yarn shadow-cljs compile test && node --require ./test-resources/override.js target/integration_test/test.js' -e cljs +integration-test-watch: _clojure-test-watch android-test: jsbundle android-test: export TARGET := android From 4c97a81cc83a3fe25aeb779455b72134a2923842 Mon Sep 17 00:00:00 2001 From: Icaro Motta Date: Wed, 27 Dec 2023 14:23:55 -0300 Subject: [PATCH 3/4] Move common target variable to subtask --- Makefile | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 2d9a8c8b4d2..ce5de7b74ed 100644 --- a/Makefile +++ b/Makefile @@ -335,30 +335,29 @@ shadow-server: export TARGET := clojure shadow-server:##@ Start shadow-cljs in server mode for watching yarn shadow-cljs server +_clojure-test: export TARGET := clojure _clojure-test: yarn install && \ yarn shadow-cljs compile mocks && \ yarn shadow-cljs compile test && \ node --require ./test-resources/override.js "$$SHADOW_OUTPUT_TO" +_clojure-test-watch: export TARGET := clojure _clojure-test-watch: 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 -test: export TARGET := clojure test: export SHADOW_OUTPUT_TO := target/test/test.js test: export SHADOW_NS_REGEXP := .*-test$$ test: ##@test Run all Clojure tests test: _clojure-test -test-watch: export TARGET := clojure test-watch: export SHADOW_OUTPUT_TO := target/test/test.js test-watch: export SHADOW_NS_REGEXP := .*-test$$ test-watch: ##@test Watch all Clojure tests and re-run when files change test-watch: _clojure-test-watch -test-watch-for-repl: export TARGET := 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 @@ -369,25 +368,21 @@ test-watch-for-repl: ##@test Watch all Clojure tests and support REPL connection '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" -unit-test: export TARGET := clojure unit-test: export SHADOW_OUTPUT_TO := target/unit_test/test.js unit-test: export SHADOW_NS_REGEXP := ^(?!status-im\.integration-test).*-test$$ unit-test: ##@test Run unit tests unit-test: _clojure-test -unit-test-watch: export TARGET := clojure unit-test-watch: export SHADOW_OUTPUT_TO := target/unit_test/test.js unit-test-watch: export SHADOW_NS_REGEXP := ^(?!status-im\.integration-test).*-test$$ unit-test-watch: ##@test Watch unit tests and re-run when files change unit-test-watch: _clojure-test-watch -integration-test: export TARGET := clojure integration-test: export SHADOW_OUTPUT_TO := target/integration_test/test.js integration-test: export SHADOW_NS_REGEXP := ^status-im\.integration-test.*$$ integration-test: ##@test Run integration tests integration-test: _clojure-test -integration-test-watch: export TARGET := clojure integration-test-watch: export SHADOW_OUTPUT_TO := target/integration_test/test.js integration-test-watch: export SHADOW_NS_REGEXP := ^status-im\.integration-test.*$$ integration-test-watch: ##@test Watch integration tests and re-run when files change From b2ad9e30e14aa9a45bfd5cba4f97ee44088183f1 Mon Sep 17 00:00:00 2001 From: Icaro Motta Date: Wed, 3 Jan 2024 15:30:42 -0300 Subject: [PATCH 4/4] Remove *-watch targets and rename test targets --- Makefile | 52 ++++++++++++++++---------------------------- ci/Jenkinsfile.tests | 4 ++-- doc/testing.md | 6 ++--- 3 files changed, 24 insertions(+), 38 deletions(-) diff --git a/Makefile b/Makefile index ce5de7b74ed..912168dd340 100644 --- a/Makefile +++ b/Makefile @@ -335,28 +335,24 @@ shadow-server: export TARGET := clojure shadow-server:##@ Start shadow-cljs in server mode for watching yarn shadow-cljs server -_clojure-test: export TARGET := clojure -_clojure-test: +_test-clojure: export TARGET := clojure +_test-clojure: export WATCH ?= false +_test-clojure: +ifeq ($(WATCH), true) yarn install && \ yarn shadow-cljs compile mocks && \ - yarn shadow-cljs compile test && \ - node --require ./test-resources/override.js "$$SHADOW_OUTPUT_TO" - -_clojure-test-watch: export TARGET := clojure -_clojure-test-watch: + 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 && \ - nodemon --exec "yarn shadow-cljs compile test && node --require ./test-resources/override.js $$SHADOW_OUTPUT_TO" -e cljs + yarn shadow-cljs compile test && \ + 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: _clojure-test - -test-watch: export SHADOW_OUTPUT_TO := target/test/test.js -test-watch: export SHADOW_NS_REGEXP := .*-test$$ -test-watch: ##@test Watch all Clojure tests and re-run when files change -test-watch: _clojure-test-watch +test: _test-clojure test-watch-for-repl: export SHADOW_OUTPUT_TO := target/test/test.js test-watch-for-repl: export SHADOW_NS_REGEXP := .*-test$$ @@ -368,25 +364,15 @@ test-watch-for-repl: ##@test Watch all Clojure tests and support REPL connection '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" -unit-test: export SHADOW_OUTPUT_TO := target/unit_test/test.js -unit-test: export SHADOW_NS_REGEXP := ^(?!status-im\.integration-test).*-test$$ -unit-test: ##@test Run unit tests -unit-test: _clojure-test - -unit-test-watch: export SHADOW_OUTPUT_TO := target/unit_test/test.js -unit-test-watch: export SHADOW_NS_REGEXP := ^(?!status-im\.integration-test).*-test$$ -unit-test-watch: ##@test Watch unit tests and re-run when files change -unit-test-watch: _clojure-test-watch - -integration-test: export SHADOW_OUTPUT_TO := target/integration_test/test.js -integration-test: export SHADOW_NS_REGEXP := ^status-im\.integration-test.*$$ -integration-test: ##@test Run integration tests -integration-test: _clojure-test - -integration-test-watch: export SHADOW_OUTPUT_TO := target/integration_test/test.js -integration-test-watch: export SHADOW_NS_REGEXP := ^status-im\.integration-test.*$$ -integration-test-watch: ##@test Watch integration tests and re-run when files change -integration-test-watch: _clojure-test-watch +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 f461b655694..19d324c8527 100644 --- a/ci/Jenkinsfile.tests +++ b/ci/Jenkinsfile.tests @@ -56,7 +56,7 @@ pipeline { steps { sh """#!/bin/bash set -eo pipefail - make unit-test 2>&1 | tee -a ${LOG_FILE} + make test-unit 2>&1 | tee -a ${LOG_FILE} """ } } @@ -66,7 +66,7 @@ pipeline { steps { sh """#!/bin/bash set -eo pipefail - make integration-test 2>&1 | tee -a ${LOG_FILE} + make test-integration 2>&1 | tee -a ${LOG_FILE} """ } } diff --git a/doc/testing.md b/doc/testing.md index 1d8e299129e..82b14078ff1 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