Erik A. Hanson's Weblog

Running Jasmine Tests Through Jaxer

Posted: June 4th, 2009    Tags: Jasmine, Javascript, Jaxer, Unit Testing, Web development

Jasmine? Jaxer?

Jasmine is a new Javascript testing framework from my pals at Pivotal Labs.

Jaxer is an Apache module that wraps Firefox’s Javascript and rendering engine, providing a server-side Javascript environment that’s fast and compatible with any JS that works in Firefox (including all kinds of DOM manipulation and libraries like Prototype, jQuery, etc.).

Running Jasmine Tests Through Jaxer

Part of an app I’m writing uses Jaxer and I wanted to write my tests in Jasmine, so I wrote a test runner and reporter to bridge the two, and then I wrote a rake task to run the tests.

So now I can run “rake spec” and my JS tests will run, in Firefox, but without having to actually have Firefox open up (or be installed).

So:

rake spec

returns:

.    foo should do something.
.    foo should do something else.
.    foo should do yet another thing.

3 of 3 specs passed

And the whole thing takes 0.37 seconds. It should be noted that those are trivial tests, but running a JS test suite with only 0.37 seconds of overhead is pretty neat.

My rake task looks like:

task :spec do
  results = `curl -s http://127.0.0.1:8081/jaxer-service/jasmine-jaxer`
  print results
  fail "spec failures" if results.match(/FAILURES!/)
end

Download

The JS code that hooks Jasmine to Jaxer is here: jasmine-jaxer.js.



2 Responses to “Running Jasmine Tests Through Jaxer”

  1. Amos King Says:

    This sounds great. Can you give some more info on how to get up and running? Or maybe post a sample and how to install and run in jaxer.

  2. Erik Says:

    I stopped using Jaxer in my app (only a tiny part of my app used Jaxer so I decided to rip it out), so I don’t have any code sitting around anymore, but the steps are basically:

    - install Jaxer
    - copy jasmine-jaxer.js into the jaxer-service directory
    - use the above rake task to run the tests

    jasmine-jaxer.js is probably incompatible with the current version of Jasmine, so you might have to make some changes.

Leave a Reply



(Comments are moderated to keep out spam. Please be patient.)