Skip to content

Instantly share code, notes, and snippets.

@mmalecki
Created November 9, 2012 01:18
Show Gist options
  • Save mmalecki/4043108 to your computer and use it in GitHub Desktop.
Save mmalecki/4043108 to your computer and use it in GitHub Desktop.
The only test runner you'll ever need
#!/bin/sh
echo "Running test suite"
passed=0
failed=0
total=0
for t in test/*-test.js; do
total=`expr $total + 1`
echo
echo "Running $t..."
output=`node $t`
code=$?
if [ $code -ne 0 ]; then
failed=`expr $failed + 1`
echo $output
echo " $(tput setaf 1)✗ $t (exit code: $code)$(tput sgr0)"
else
passed=`expr $passed + 1`
echo " $(tput setaf 2)✓ $t $(tput sgr0)"
fi
done
echo
if [ $failed -eq 0 ]; then
echo "$(tput setaf 2)✓ OK » $passed passed$(tput sgr0)"
else
echo "$(tput setaf 1)✗ Failed » $failed failed$(tput sgr0)"
echo "$(tput setaf 2) $passed passed$(tput sgr0)"
exit 1
fi
@tj
Copy link

tj commented Nov 9, 2012

works even better if you use make targets, then you can -j 4

@mmalecki
Copy link
Author

mmalecki commented Nov 9, 2012

I'm a bit opposed to running tests in parallel, especially if they interact with DBs or services, but if it's good for your usecase that's a very good idea

@tj
Copy link

tj commented Nov 9, 2012

yeah that can get ugly, node stuff is usually fast enough anyway

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment