Last active
August 16, 2016 18:34
-
-
Save ryanhallcs/003120ef8bba4e7911464d79b66b5ec7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function run() { | |
try { | |
var Spooky = require('spooky'); | |
} catch (e) { | |
console.log(e.message); | |
e = new Error('Failed to initialize SpookyJS'); | |
e.details = e; | |
throw e; | |
} | |
var spooky = new Spooky({ | |
child: { | |
transport: 'http' | |
}, | |
casper: { | |
logLevel: 'debug', | |
verbose: true | |
} | |
}, function (err) { | |
if (err) { | |
console.log(e.message); | |
e = new Error('Failed to initialize SpookyJS'); | |
e.details = err; | |
throw e; | |
} | |
spooky.start( | |
'http://en.wikipedia.org/wiki/Spooky_the_Tuff_Little_Ghost'); | |
spooky.then(function () { | |
this.emit('hello', 'Hello, from ' + this.evaluate(function () { | |
return document.title; | |
})); | |
}); | |
spooky.run(); | |
}); | |
spooky.on('remote.message', function(msg) { | |
this.log('remote message caught: ' + msg); | |
}); | |
// 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) { | |
// console.log(line); | |
// }); | |
spooky.on('hello', function (greeting) { | |
console.log(greeting); | |
}); | |
spooky.on('log', function (log) { | |
if (log.space === 'remote') { | |
console.log(log.message.replace(/ \- .*/, '')); | |
} | |
}); | |
} | |
function create() { | |
var result = {}; | |
result.run = run; | |
return result; | |
} | |
module.exports = create; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment