Headless JS Testing with Jasmine, PhantomJS and IntelliJ IDEA

September 3rd, 2013

Most of the work i’ve been doing lately has been in enterprise, Java environments, so we’ve usually handled that through Maven using the Exec Maven Plugin. This time around, I’m working on a pure JS project, with a NodeJS back-end, so the set-up’s a bit different. It’s just kind of come up a few times now, so I figured I’d put in the time to get it right.

After a bit of digging, I found the JsTestDriver plug-in. I’ve had some experience with JsTestDriver in the past, and it’s great if you want to run tests against a bunch of browsers. The plug-in goes a long way toward making it quick and painless to fire up browsers and bind them to your current IDEA project environment.

Unfortunately, this wasn’t what I was after.

All I really want to do is start up IDEA, write a bit of code, and hit a “test” button, without the need for any supporting browsers. Once we go into an integrated environment with automated builds, the same code should run on the build server without the need for browsers. After a bit of trial-and-error, I’ve come to this pretty simple set-up that gets me what I need: (I’m running on OSX 10.7.5, so your mileage may vary)

  1. Install PhantomJS. Make sure it’s in your path (The brew install worked for me).
  2. Get Phantom-Jasmine. Set up your project whatever way you want. I just rejiggered the default project and combined it with the latest Jasmine (I used 1.3.1). Here’s my sample app, too.
  3. Also, get CoffeeScript.
  4. Use the “External Tools” feature in IDEA to create a Phantom-Jasmine command, and configure it as I’ve done here (Note the $ProjectFileDir$ macro use):


External Tools Settings


Click “OK” and close. That’s it!

You should now be able to run the Phantom-Jasmine command from the Tools Menu, and hit “Play/Run” down in the “Run” menu after to keep re-running your tests.

Screen Shot 2013-09-03 at 1.16.21 PM-2

I can’t speak to this setup’s robustness (using it with jasmine-jquery, for instance), but I’m sure I’ll find out soon enough and post any findings.

Download the sample app

Leave a Reply