Skip to content

Commit

Permalink
Play nice with Casper > v1.0.2
Browse files Browse the repository at this point in the history
- Call patchRequire for Casper > v1.0.2
- Fix hello example to work with recent Caspers
- Fix tests to work with old and new casper require

Thanks to @rumca and @ucarbehlul for helping me run this one down.

close #73
close #75
  • Loading branch information
lawnsea committed Sep 27, 2013
1 parent 9c1b0b2 commit 66bf63d
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 7 deletions.
10 changes: 8 additions & 2 deletions README.md
Expand Up @@ -52,8 +52,10 @@ var spooky = new Spooky({

spooky.start(
'http://en.wikipedia.org/wiki/Spooky_the_Tuff_Little_Ghost');
spooky.thenEvaluate(function () {
console.log('Hello, from', document.title);
spooky.then(function () {
this.emit('hello', 'Hello, from ' + this.evaluate(function () {
return document.title;
}));
});
spooky.run();
});
Expand All @@ -75,6 +77,10 @@ spooky.on('console', function (line) {
});
*/

spooky.on('hello', function (greeting) {
console.log(greeting);
});

spooky.on('log', function (log) {
if (log.space === 'remote') {
console.log(log.message.replace(/ \- .*/, ''));
Expand Down
10 changes: 8 additions & 2 deletions examples/hello.js
Expand Up @@ -21,8 +21,10 @@ var spooky = new Spooky({

spooky.start(
'http://en.wikipedia.org/wiki/Spooky_the_Tuff_Little_Ghost');
spooky.thenEvaluate(function () {
console.log('Hello, from', document.title);
spooky.then(function () {
this.emit('hello', 'Hello, from ' + this.evaluate(function () {
return document.title;
}));
});
spooky.run();
});
Expand All @@ -44,6 +46,10 @@ spooky.on('console', function (line) {
});
*/

spooky.on('hello', function (greeting) {
console.log(greeting);
});

spooky.on('log', function (log) {
if (log.space === 'remote') {
console.log(log.message.replace(/ \- .*/, ''));
Expand Down
6 changes: 6 additions & 0 deletions lib/bootstrap/casper.js
@@ -1,3 +1,9 @@
if (phantom.casperVersion.major >= 1 &&
(phantom.casperVersion.minor > 0 || phantom.casperVersion.patch > 2)
) {
require = patchRequire(require);
}

var createFunction =
require(options.spooky_lib + 'lib/bootstrap/create-function');
var casper = require('casper');
Expand Down
7 changes: 7 additions & 0 deletions lib/stream.js
@@ -1,3 +1,10 @@
if (phantom &&
phantom.casperVersion.major >= 1 &&
(phantom.casperVersion.minor > 0 || phantom.casperVersion.patch > 2)
) {
require = patchRequire(require);
}

// Copyright (c) 2011 Jxck
//
// Originally from node.js (http://nodejs.org)
Expand Down
8 changes: 6 additions & 2 deletions tests/test/emit.js
Expand Up @@ -13,7 +13,9 @@ describe('bootstrap/emit', function () {
context.spooky.start();

context.spooky.then(function () {
var emit = require('./lib/bootstrap/emit').emit;
var fs = require('fs');
var emit =
require(fs.workingDirectory + '/lib/bootstrap/emit').emit;

emit('testing', 1, 2, 3);
});
Expand All @@ -37,7 +39,9 @@ describe('bootstrap/emit', function () {
context.spooky.start();

context.spooky.then(function () {
var console = require('./lib/bootstrap/emit').console;
var fs = require('fs');
var console =
require(fs.workingDirectory + '/lib/bootstrap/emit').console;

console.log('HEYO');
console.debug('HEYO');
Expand Down
2 changes: 1 addition & 1 deletion tests/util/hooks.js
Expand Up @@ -78,7 +78,7 @@ module.exports.before = function (context) {
child: {
port: 8081,
script: 'lib/bootstrap.js',
spooky_lib: './',
spooky_lib: process.cwd() + '/',
transport: process.env.TEST_TRANSPORT || 'stdio'
},
casper: {
Expand Down

0 comments on commit 66bf63d

Please sign in to comment.