From af27d41fbd26a52d9005e3367b4ae082daf99012 Mon Sep 17 00:00:00 2001 From: zkldi <20380519+zkldi@users.noreply.github.com> Date: Sun, 17 Jul 2022 18:21:34 +0100 Subject: [PATCH] test: some *idiot* never checked whether seeds CI could fail --- database-seeds/scripts/run-tests.sh | 40 ++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/database-seeds/scripts/run-tests.sh b/database-seeds/scripts/run-tests.sh index 6ae31bb40..f3accd580 100755 --- a/database-seeds/scripts/run-tests.sh +++ b/database-seeds/scripts/run-tests.sh @@ -2,10 +2,38 @@ cd "$(dirname "$0")" || exit 1 -# Output stderr and stdout to the terminal, but only save stderr to a file -# Isn't bash wonderful? -ts-node test/collections.test.ts 2> >(tee failed-tests.log >&2) -ts-node test/id.test.ts 2> >(tee -a failed-tests.log >&2) -ts-node test/folder-id.test.ts 2> >(tee -a failed-tests.log >&2) -ts-node test/table-folders.test.ts 2> >(tee -a failed-tests.log >&2) + +failed=() +function onFailure() { + failed+=( "$?" ) +} + +trap onFailure ERR + +tests=("collections" "id" "folder-id" "table-folders") + +# for all tests +for test in "${tests[@]}" +do + # Output stderr and stdout to the terminal, but only save stderr to a file + # Isn't bash wonderful? + ts-node "test/$test.test.ts" 2> >(tee failed-tests.log >&2) +done + +# if more than 0 commands failed +if [ "${#failed[@]}" -ne 0 ]; then + # iterate through the error codes and zip them with their + # test equivalent + for (( i = 0; i < ${#failed[@]}; i++ )); + do + if [ "${failed[$i]}" -ne 0 ]; then + echo "Test ${tests[$i]} failed. exit code: ${failed[$i]}" + fi; + done + + exit 1; +fi; + +# success +exit 0; \ No newline at end of file