Max Schmitt

November 24 2025

A Useful Bash Function for Debugging Flaky Tests

To check if a test is flaky, there's often no other way than to run it multiple times.

I have a Bash function in my .bashrc to do this for me:

times 10 npm t

This will run npm t up to 10 times but it will stop immediately if one of the test runs fails.

Feel free to copy it to your .bashrc or .bash_profile:

BASH

times() {
n=$1
shift
echo $@
while [[ $n -gt 0 ]]; do if "$@"; then n=$((n-1)); else break; fi; done
}