Skip to content

Instantly share code, notes, and snippets.

@jsjoeio
Last active February 27, 2023 12:06
Show Gist options
  • Save jsjoeio/2a5e7eb4533922040190e87b90a5449c to your computer and use it in GitHub Desktop.
Save jsjoeio/2a5e7eb4533922040190e87b90a5449c to your computer and use it in GitHub Desktop.
How to Run a Jest test multiple times
#!/usr/bin/env bash
i=1
successes=0
failures=0
totalTests=10
SUCCESS_CHECKMARK=$(printf '\342\234\224\n' | iconv -f UTF-8)
CROSS_MARK=$(printf '\342\235\214\n' | iconv -f UTF-8)
OUTPUT_FILE="jestOutput.txt"
until [ $i -gt $totalTests ]; do
echo "Attempt #$i"
if yarn test -i test_file_name >>"$OUTPUT_FILE" 2>&1; then
((successes = successes + 1))
echo " $SUCCESS_CHECKMARK tests passed"
else
((failures = failures + 1))
echo " $CROSS_MARK tests failed"
fi
((i = i + 1))
done
echo "\n
Ran $totalTests Tests.\n
✅ Succeeded: $successes/10
❌ Failed: $failures/10
\n
"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment