diff --git a/.circleci/config.yml b/.circleci/config.yml index 7bac4945..3e14ae94 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -65,7 +65,7 @@ jobs: - node_modules - run: name: Test - command: npm run test + command: ./.circleci/test.sh - run: name: Coverage command: npm run coverage diff --git a/.circleci/test.sh b/.circleci/test.sh new file mode 100755 index 00000000..b6ab1ca1 --- /dev/null +++ b/.circleci/test.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +# override CircleCi's default run settings, +# so that we run all tests and do not exit early +# on test failures. +set +e +set +o pipefail + +EXIT_STATE=0 +MAX_AUTO_RETRY=5 + +# inspired by https://unix.stackexchange.com/a/82602 +retry () { + local n=0 + + until [ $n -ge $MAX_AUTO_RETRY ]; do + "$@" && break + n=$[$n+1] + echo '' + echo run $n of $MAX_AUTO_RETRY failed, trying again ... + echo '' + sleep 15 + done + + if [ $n -eq $MAX_AUTO_RETRY ]; then + EXIT_STATE=1 + fi +} + +npm run pretest +npm run test:lint || EXIT_STATE=$? +npm run test:unit || EXIT_STATE=$? +retry npm run test:integration +exit $EXIT_STATE