Permalink
Browse files

Fix requires so that the lib/* modules work

Also moved console event listener closer to child spawn point.
  • Loading branch information...
1 parent abbd6bf commit cdea3e6dfc7401f6e5ff96f391a1e4b6943c0790 @lawnsea lawnsea committed Sep 24, 2012
Showing with 25 additions and 25 deletions.
  1. +4 −4 lib/bootstrap.js
  2. +2 −1 lib/bootstrap/casper.js
  3. +2 −2 lib/bootstrap/http-server.js
  4. +3 −3 lib/bootstrap/stdio-server.js
  5. +13 −14 lib/spooky.js
  6. +1 −1 tests/util/hooks.js
View
@@ -1,20 +1,20 @@
var options = phantom.casperArgs.options;
-phantom.requireBase = options.spooky_lib;
+phantom.requireBase = options.spooky_lib + 'node_modules/';
var system = require('system');
var utils = require('utils');
var transport = (options.transport || '').toLowerCase();
var server;
if (transport === 'http') {
- server = require('./lib/bootstrap/http-server');
+ server = require(options.spooky_lib + 'lib/bootstrap/http-server');
} else if (transport === 'stdio') {
- server = require('./lib/bootstrap/stdio-server');
+ server = require(options.spooky_lib + 'lib/bootstrap/stdio-server');
} else {
console.error('Unknown transport: ' + transport);
phantom.exit(1);
}
-require('./lib/bootstrap/casper').provideAll(server);
+require(options.spooky_lib + 'lib/bootstrap/casper').provideAll(server);
function emit(event) {
var args = Array.prototype.slice.call(arguments);
View
@@ -1,4 +1,5 @@
-var createFunction = require('./lib/bootstrap/create-function');
+var createFunction =
+ require(options.spooky_lib + 'lib/bootstrap/create-function');
var casper = require('casper');
var instance;
@@ -1,7 +1,7 @@
var port = options.port || 8080;
-var JsonRpcServer =
- require(options.spooky_lib + '/tiny-jsonrpc/lib/tiny-jsonrpc').Server;
+var JsonRpcServer = require(options.spooky_lib +
+ 'node_modules/tiny-jsonrpc/lib/tiny-jsonrpc').Server;
var server = new JsonRpcServer();
@@ -5,7 +5,7 @@ var line;
var emptyLines = 0;
var start = Date.now();
-var Stream = require('./lib/stream');
+var Stream = require(options.spooky_lib + 'lib/stream');
var stream = new Stream();
stream.write = function (s) {
@@ -38,8 +38,8 @@ function loop() {
}
}
-var StreamServer =
- require(options.spooky_lib + '/tiny-jsonrpc/lib/tiny-jsonrpc').StreamServer;
+var StreamServer = require(options.spooky_lib +
+ 'node_modules/tiny-jsonrpc/lib/tiny-jsonrpc').StreamServer;
var server = new StreamServer();
server.listen(stream);
View
@@ -27,7 +27,7 @@ var defaults = {
command: 'casperjs',
port: 8081,
script: './node_modules/spooky/lib/bootstrap.js',
- spooky_lib: './node_modules/spooky/node_modules',
+ spooky_lib: './node_modules/spooky/',
transport: 'stdio',
bufferSize: 16 * 1024 // 16KB
},
@@ -159,7 +159,18 @@ Spooky.prototype._spawnChild = function () {
}
child = this._child = spawn('casperjs', args);
- child.stdout.setEncoding('utf8');
+
+ var stdout = child.stdout;
+ stdout.setEncoding('utf8');
+ child.stdout = new Stream();
+ carrier.carry(stdout).on('line', (function (line) {
+ this.stdout.emit('data', line);
+ }).bind(child));
+
+ // emit anything that isn't JSON-RPC traffic as a console event
+ (new FilteredStream(child.stdout, function (data) {
+ return !isJsonRpcResponse(data) && !isJsonRpcRequest(data);
+ })).on('data', this.emit.bind(this, 'console'));
var stdin = child.stdin;
child.stdin = new BufferedStream(options.bufferSize);
@@ -177,18 +188,6 @@ Spooky.prototype._spawnChild = function () {
this.emit('error', e);
}
}).bind(this));
-
- var stdout = child.stdout;
- stdout.setEncoding('utf8');
- child.stdout = new Stream();
- carrier.carry(stdout).on('line', (function (line) {
- this.stdout.emit('data', line);
- }).bind(child));
-
- // emit anything that isn't JSON-RPC traffic as a console event
- (new FilteredStream(child.stdout, function (data) {
- return !isJsonRpcResponse(data) && !isJsonRpcRequest(data);
- })).on('data', this.emit.bind(this, 'console'));
return child;
};
View
@@ -74,7 +74,7 @@ module.exports.before = function (context) {
child: {
port: 8081,
script: 'lib/bootstrap.js',
- spooky_lib: './node_modules',
+ spooky_lib: './',
transport: process.env.TEST_TRANSPORT || 'stdio'
},
casper: {

0 comments on commit cdea3e6

Please sign in to comment.