Skip to content

Commit

Permalink
Merge pull request #332 from EpistasisLab/UnitTestRunnerOptions
Browse files Browse the repository at this point in the history
Unit testing - add env var-based options for managing which run
Merged per Heather instructions
  • Loading branch information
mgstauffer authored Jun 16, 2021
2 parents 8a5124f + c552778 commit dc44de4
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
5 changes: 5 additions & 0 deletions config/unit-test-js-only.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Optional env file to include for running only js unit tests in lab
# Gets picked up in tests/unit/unit_test_runner.sh
# e.g. docker-compose --env-file ./config/unit-test-js-only.env -f .\docker-compose-unit-test.yml up --abort-on-container-exit

PENNAI_UNIT_TESTS_JS_ONLY=1
5 changes: 5 additions & 0 deletions config/unit-test-py-only.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Optional env file to include for running only python unit tests in lab
# Gets picked up in tests/unit/unit_test_runner.sh
# e.g. docker-compose --env-file ./config/unit-test-py-only.env -f .\docker-compose-unit-test.yml up --abort-on-container-exit

PENNAI_UNIT_TESTS_PY_ONLY=1
4 changes: 3 additions & 1 deletion docker-compose-unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ services:
context: .
dockerfile: tests/unit/Dockerfile
working_dir: /appsrc
command: bash -c "dos2unix tests/unit/unit_test_runner.sh && sh tests/unit/unit_test_runner.sh"
command: bash -c "dos2unix tests/unit/unit_test_runner.sh && export PENNAI_UNIT_TESTS_JS_ONLY=$PENNAI_UNIT_TESTS_JS_ONLY && export PENNAI_UNIT_TESTS_PY_ONLY=$PENNAI_UNIT_TESTS_PY_ONLY && sh tests/unit/unit_test_runner.sh"
tty: true
stdin_open: true
volumes:
- "./:/appsrc"
- "/appsrc/lab/webapp/node_modules"
- "/appsrc/lab/node_modules"


31 changes: 25 additions & 6 deletions tests/unit/unit_test_runner.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
#!/bin/bash

# NOTE
# To run only the python tests (py_tests.sh) or only the web/javascript tests
# (js_tests.sh), set the appropriate env var, as used below.
# With docker-compose, use the --env-file param and pass either of
# config/unit-test-js-only.env, or
# config/unit-test-py-only.env

dos2unix /appsrc/tests/unit/py_tests.sh
dos2unix /appsrc/tests/unit/js_tests.sh

# initialize
pyres=0
jsres=0

# run via sh to avoid permissions problem
sh /appsrc/tests/unit/py_tests.sh
pyres=$?
# echo "==== py_tests unit tests result "$pyres
if [ -z "${PENNAI_UNIT_TESTS_JS_ONLY}" ]; then
sh /appsrc/tests/unit/py_tests.sh
pyres=$?
# echo "==== py_tests unit tests result "$pyres
else
echo "$0 - skipped py_tests"
fi

# run via sh to avoid permissions problem
sh /appsrc/tests/unit/js_tests.sh
jsres=$?
# echo "==== js_tests unit tests result "$jsres
if [ -z "${PENNAI_UNIT_TESTS_PY_ONLY}" ]; then
sh /appsrc/tests/unit/js_tests.sh
jsres=$?
# echo "==== js_tests unit tests result "$jsres
else
echo "$0 - skipped js_tests"
fi

# exit with code 1 if either test fails
# If we don't exit with a non-zero value, github actions won't catch the error
Expand Down

0 comments on commit dc44de4

Please sign in to comment.