From b4640dabb91d4a2d45fd0fba921c3b9a3d083d54 Mon Sep 17 00:00:00 2001 From: Icaro Motta Date: Fri, 5 Jan 2024 15:47:03 -0300 Subject: [PATCH] Run integration tests separately from unit tests (#18304) - make test still exists, so if you have been using it, as well as make test-watch, they should all work exactly the same. - [Changed] As part of the check stage, Jenkins will run Lint and Unit Tests in parallel. Integration Tests run later because running them at the same time as Unit Tests caused errors. - [Added] "make unit-test" and "make unit-test-watch" run unit tests only. Watching all unit tests is faster now because we ignore integration tests and we only compile shadow-cljs :mock target once. We are at approximately 10-15s to re-run all unit tests after saving a watched file, depending on your hardware. If you change mocks.js_dependencies.cljs, you must re-run the make target. - [Added] "make integration-test" and "make integration-test-watch" run integration tests only. These are much slower than the unit tests. Fixes https://github.com/status-im/status-mobile/issues/18112 --- Makefile | 54 +++++++++++++++++++++++++++++--------------- ci/Jenkinsfile.tests | 12 ++++++++-- doc/testing.md | 6 ++--- shadow-cljs.edn | 4 ++-- 4 files changed, 51 insertions(+), 25 deletions(-) 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