Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run integration tests separately from unit tests #18304

Merged
merged 4 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 34 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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-clojure: export TARGET := clojure
_test-clojure: export WATCH ?= false
_test-clojure:
ifeq ($(WATCH), true)
yarn install && \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this start with underscore? And it's missing a help message.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the name should be test-clojure if we want to have consistent prefixes.

Copy link
Contributor Author

@ilmotta ilmotta Jan 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this start with underscore? And it's missing a help message.

There are other targets prefixed with underscore, so I used the same idea to mean "private" targets that shouldn't be used directly. Edit: Being "private", I preferred not to document them, but I can add something no problem.

And the name should be test-clojure if we want to have consistent prefixes.

Good point, will do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved by bcf0af0

I kept the underscore prefix like other targets and I didn't add any documentation. The "public" targets have a description though. Is that okay for you?

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 "$$SHADOW_OUTPUT_TO"
endif

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 SHADOW_OUTPUT_TO := target/test/test.js
test: export SHADOW_NS_REGEXP := .*-test$$
test: ##@test Run all Clojure tests
test: _test-clojure

test: export TARGET := clojure
test: ##@test Run tests once in NodeJS
# Here we create the gyp bindings for nodejs
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 && \
yarn shadow-cljs compile test && \
node --require ./test-resources/override.js target/test/test.js
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
Expand Down
12 changes: 10 additions & 2 deletions ci/Jenkinsfile.tests
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
jakubgs marked this conversation as resolved.
Show resolved Hide resolved
steps {
sh """#!/bin/bash
set -eo pipefail
make test-integration 2>&1 | tee -a ${LOG_FILE}
"""
}
}
stage('Component Tests') {
steps {
sh """#!/bin/bash
Expand Down
6 changes: 3 additions & 3 deletions doc/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
To run tests:

```
make test
make test
```



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

Expand Down
4 changes: 2 additions & 2 deletions shadow-cljs.edn
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down