Skip to content

Instantly share code, notes, and snippets.

@ryanhallcs
Last active August 16, 2016 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanhallcs/003120ef8bba4e7911464d79b66b5ec7 to your computer and use it in GitHub Desktop.
Save ryanhallcs/003120ef8bba4e7911464d79b66b5ec7 to your computer and use it in GitHub Desktop.
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