diff --git a/Makefile b/Makefile index 8048c6c1..424a3c91 100644 --- a/Makefile +++ b/Makefile @@ -8,4 +8,8 @@ config/environments/test.js: config/environments/test.js.example ./configure check: config/environments/test.js - ./run_tests.sh + ./run_tests.sh ${RUNTESTFLAGS} \ + test/unit/cartodb/redis_pool.test.js \ + test/unit/cartodb/req2params.test.js \ + test/acceptance/cache_validator.js \ + test/acceptance/server.js diff --git a/NEWS.md b/NEWS.md index 802546e0..020ca2f2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ 1.1.5 (DD//MM//YY) ----- +* Enhance run_tests.sh to allow running single tests and skipping preparation 1.1.4 (DD//MM//YY) ----- diff --git a/run_tests.sh b/run_tests.sh index 754bfdf3..394f5ad5 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -1,11 +1,28 @@ #!/bin/sh -# Must match config.redis_pool.port in test/support/config.js +# Must match redis_port in config/environments/test.js +# TODO: read from there REDIS_PORT=6333 +OPT_CREATE=yes # create the test environment +OPT_DROP=yes # drop the test environment + +cd $(dirname $0) +BASEDIR=$(pwd) +cd - + cleanup() { - echo "Cleaning up" - kill ${PID_REDIS} + if test x"$OPT_DROP" = xyes; then + if test x"$PID_REDIS" = x; then + PID_REDIS=$(cat ${BASEDIR}/redis.pid) + if test x"$PID_REDIS" = x; then + echo "Could not find a test redis pid to kill it" + return; + fi + fi + echo "Cleaning up" + kill ${PID_REDIS} + fi } cleanup_and_exit() { @@ -22,21 +39,43 @@ die() { trap 'cleanup_and_exit' 1 2 3 5 9 13 -echo "Starting redis on port ${REDIS_PORT}" -echo "port ${REDIS_PORT}" | redis-server - > test.log & -PID_REDIS=$! +while [ -n "$1" ]; do + if test "$1" = "--nodrop"; then + OPT_DROP=no + shift + continue + elif test "$1" = "--nocreate"; then + OPT_CREATE=no + shift + continue + else + break + fi +done + +if [ -z "$1" ]; then + echo "Usage: $0 [] []" >&2 + echo "Options:" >&2 + echo " --nocreate do not create the test environment on start" >&2 + echo " --nodrop do not drop the test environment on exit" >&2 + exit 1 +fi -echo "Preparing the database" -cd test/support; sh prepare_db.sh >> test.log || die "database preparation failure (see test.log)"; cd -; +TESTS=$@ + +if test x"$OPT_CREATE" = xyes; then + echo "Starting redis on port ${REDIS_PORT}" + echo "port ${REDIS_PORT}" | redis-server - > ${BASEDIR}/test.log & + PID_REDIS=$! + echo ${PID_REDIS} > ${BASEDIR}/redis.pid + + echo "Preparing the environment" + cd ${BASEDIR}/test/support; sh prepare_db.sh || die "database preparation failure"; cd - +fi PATH=node_modules/.bin/:$PATH echo "Running tests" -mocha -u tdd \ - test/unit/cartodb/redis_pool.test.js \ - test/unit/cartodb/req2params.test.js \ - test/acceptance/cache_validator.js \ - test/acceptance/server.js - +mocha -u tdd ${TESTS} cleanup