Configuring Mocha's TeamCity reporter
First we need to configure Mocha to emit specially formatted messages to console.log() that TeamCity can detect and parse. This is easy because Mocha supports pluggable reporters for displaying test progress, and it provides a TeamCity reporter out of the box. Set this up in your mocha.html page:
Executing Mocha tests from the command line
You can then invoke your tests from the command line, and you should see a bunch of TeamCity messages scroll past.
phantomjs.exe phantomjs-tests.js http://localhost:88/jstests/mocha.html
Note in my example I am running tests on a local web server on port 81, but PhantomJS also supports local file:// URLs.
Setting up a build step for PhantomJS
Finally the last thing we need to do is to set up a new Command Line build step in TeamCity to run PhantomJS.
And that's it! You should now see your test passes and fails showing up in TeamCity:
Thanks to Dan Merino for his original article on running Jasmine tests under TeamCity, which formed the basis for most of this post.