Skip to content


Subversion checkout URL

You can clone with
Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

116 lines (86 sloc) 3.246 kB


Drive CasperJS from Node.js.



SpookyJS is available from npm.

$ npm install spooky


var Spooky = require('../lib/spooky');

var spooky = new Spooky({
        child: {
            script: './lib/bootstrap.js',
            spooky_lib: './node_modules'
        casper: {
            logLevel: 'debug',
            verbose: true
    }, function (err) {
        if (err) {
            e = new Error('Failed to initialize SpookyJS');
            e.details = err;
            throw e;

        spooky.on('error', function (e) {

        // Uncomment this block to see all of the things Casper has to say.
        // There are a lot.
        // He has opinions.
        spooky.on('console', function (line) {

        spooky.on('log', function (log) {
            if ( === 'remote') {
                console.log(log.message.replace(/ \- .*/, ''));

        spooky.thenEvaluate(function () {
            console.log('Hello, from', document.title);

A minimal example can be found in the repo under examples. Run it like this:

$ node examples/hello.js

A small example Cucumber.js test suite can be found in the repo under examples/cucumber. To run the suite:

$ make cucumber.js

You may change the port that the fixture server runs on by setting the TEST_PORT make parameter.

See the tests for an example of how to use SpookyJS with Mocha.


Running the tests

SpookyJS includes a suite of unit tests, driven by Mocha. To run the tests:

$ make test

The following make parameters are supported (defaults are in parentheses):

  • TEST_REPORTER the Mocha reporter to use (dot)
  • TEST_PORT the port to run the fixture web server on (8080)
  • TEST_TIMEOUT threshold in ms to timeout a test (4000)
  • TEST_SLOW threshold in ms to say a test is slow (2000)
  • TEST_ARGS Additional arguments to pass through to Mocha
  • TEST_DEBUG Print debug logging to the console (false)
  • TEST_TRANSPORT the Spooky transport to use when running the tests (stdio)


SpookyJS is made available under the MIT License.

Acknowledgements and Attribution

The image tests/fixtures/fail-road.jpeg is the work Fail Road and is copyright (c) 2007 fireflythegreat and made available under an Attribution 2.0 Generic license.

Jump to Line
Something went wrong with that request. Please try again.