diff --git a/.gitignore b/.gitignore index e6d5b01a..d422e46e 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ pids/ redis.pid test.log npm-debug.log +coverage/ diff --git a/Makefile b/Makefile index 1d3c1cdd..e8177443 100644 --- a/Makefile +++ b/Makefile @@ -33,6 +33,9 @@ jshint: test-all: jshint test +coverage: + @RUNTESTFLAGS=--with-coverage make test + check: test .PHONY: pre-install test diff --git a/package.json b/package.json index 44a6e6f4..a4398db9 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "rollbar": "~0.3.13" }, "devDependencies": { + "istanbul": "~0.3.6", "mocha": "~1.21.4", "jshint": "~2.6.0", "redis": "~0.8.6", diff --git a/run_tests.sh b/run_tests.sh index 9790b7e6..e7ea3a2c 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -4,6 +4,7 @@ OPT_CREATE_REDIS=yes # create the redis test environment OPT_CREATE_PGSQL=yes # create the PostgreSQL test environment OPT_DROP_REDIS=yes # drop the redis test environment OPT_DROP_PGSQL=yes # drop the PostgreSQL test environment +OPT_COVERAGE=no # run tests with coverage export PGAPPNAME=cartodb_tiler_tester @@ -69,6 +70,10 @@ while [ -n "$1" ]; do OPT_CREATE_REDIS=no shift continue + elif test "$1" = "--with-coverage"; then + OPT_COVERAGE=yes + shift + continue # This is kept for backward compatibility elif test "$1" = "--nocreate"; then OPT_CREATE_REDIS=no @@ -85,6 +90,7 @@ if [ -z "$1" ]; then 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 + echo " --with-coverage use istanbul to determine code coverage" >&2 exit 1 fi @@ -112,8 +118,13 @@ cd - PATH=node_modules/.bin/:$PATH -echo "Running tests" -mocha -t 10000 -u tdd ${MOCHA_OPTS} ${TESTS} +if test x"$OPT_COVERAGE" = xyes; then + echo "Running tests with coverage" + ./node_modules/.bin/istanbul cover node_modules/.bin/_mocha -- -u tdd -t 5000 ${TESTS} +else + echo "Running tests" + mocha -u tdd -t 5000 ${TESTS} +fi ret=$? cleanup