Say What Now?
The “say” command is both hilarious and convenient. Let’s use it!
I have a problem — I write a LOT of unit tests and when I run them, I tend to shift my focus to other things: email, coffee, etc. Sometimes I lose track of time. Depending on the project and if there are any integration tests in the mix, the tests can take upwards of a couple minutes to complete. Wouldn’t it be nice if the tests told me when they were done? Well they can. And it’s really freakin’ simple.
Let’s do this
My package.json had this line for my test script:
"test": "export NODE_ENV=test && ./node_modules/.bin/istanbul cover -x '**/spec/_helpers/**/*' ./node_modules/.bin/jasmine"
And all I have to do is add a simple command to the end:
"test": "export NODE_ENV=test && ./node_modules/.bin/istanbul cover -x '**/spec/_helpers/**/*' ./node_modules/.bin/jasmine && say 'Unit Testing Complete'"
So that’s going to literally run all my tests and tell me through the computer speakers when it’s done. Boom.
What if the tests fail?
Right, that’s pretty important too. Let’s add that!
"test": "export NODE_ENV=test && ./node_modules/.bin/istanbul cover -x '**/spec/_helpers/**/*' ./node_modules/.bin/jasmine && say 'Unit Testing Complete' || say 'Unit Tests Failed'"
“It sounds like a robot.” Well, that’s because you didn’t specify a voice and your default voice is robot man. Lucky for you there are a ton of voice options with different accents and everything. Simply type this to see which options you have installed on your machine (they vary per OSX install):
say -v \?
And then we can change it up:
say -v Anna "Unit testing complete"
Use cases aside from unit tests?
- How about a hook into a server that monitors logs and errors and tells you when you have fatal errors in production?
- How about a hook into your CI so it tells you when your build fails, meaning the team doesn’t have to sit there and watch it for 20 minutes hoping it turns green?
- How about a hook into a calendar API to verbalize reminders for you as they come in?
- How about secretly setting some CRON jobs on your co-worker’s computer to run a shell script so their computer talks shit about them sporadically throughout the day?
- How about a hook into the Github API to tell you when someone has opened a pull request that needs your eyes?
Not on a Mac?
If you’re on an Ubuntu distro you can get
apt like :
sudo apt-get install gnustep-gui-runtime
say "A man goes to the doctor for a physical. The doctor says to the man 'You are going to need to stop masturbating.' The man says 'Oh no! Why?' to which the doctor replies 'Because I am trying to give you a physical.'"
If you are stuck on Windows, then unfortunately like most things on Windows, this isn’t nearly as graceful but you still have options:
- Get this “Peter’s Text To Speech” binary http://jampal.sourceforge.net/ptts.html
- Use it like so :
echo please help me get off windows | ptts.exe
Most OS’s have some port of
espeak as well, but at that point just move on and have your computer simply beep at you when the tests are done.
If you liked this, please click the 💚 below so others can enjoy!