phantomjs headless javascript unit testing with unit test injection

I have a PHP application that is very javascript heavy and although it has quite a few javascript functions most of them use jquery in some way. This presents a small issue with unit testing where I require a fully loaded Document Object Model (DOM) to interact with. Enter phantomjs a headless webkit that provides the capability to load a webpage, build a full DOM and interact with it. However most examples i came across on the internet seem to assume that the unit tests and qunit are already loaded into the HTML page being called. I didn’t want to mix my testing with my production code in any way and maintaining a seperate HTML page for the unit tests would defeat the point of having the tests, especially with so much integration with elements in the DOM. So i have taken the runner.js example from qunit and modified it to inject qunit, my unit tests and even handle logging into my website to get to the main page to test.

The phantomjs code is available as a gist

resources I used to understand this included and via

Facebook HipHop PHP HHVM on Ubuntu 12.10

It seems that Ubuntu have removed some of the required dependencies for installing the HipHop VM. you can find them in some of the older repositories. Add the following to your /etc/apt/sources.list to get them.

deb precise main
deb precise main universe
deb-src precise main universe