Skip to content

Commit

Permalink
A few cosmetic changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
aflatter committed Mar 28, 2012
1 parent 35dacc6 commit 8368ce5
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
14 changes: 9 additions & 5 deletions lib/client.js
Expand Up @@ -11,7 +11,7 @@ Client.create = function() {
var instance = Object.create(proto);
constructor.apply(instance, arguments);
return instance;
}
};

/**
* Constructor
Expand All @@ -24,7 +24,7 @@ function constructor(opts) {
this.path = opts.path || '';

underscore.bindAll.call(underscore, [this] + this._bound);
};
}

/**
* Specifies which methods are bound to the instance.
Expand Down Expand Up @@ -75,7 +75,7 @@ proto.request = function(method, resource, data, callback) {
options.headers['Content-Length'] = data.length;
}

req = http.request(options)
req = http.request(options);

// Buffer up the response body and proceed.
req.on('response', function(res) {
Expand Down Expand Up @@ -129,7 +129,7 @@ proto._requestDidComplete = function(res, body, callback) {

// Automatically follow redirects.
if (code >= 300 && code < 400) {
return this.get(res.headers['location'], callback);
return this.get(res.headers.location, callback);
}

if (!type.match('application/json')) {
Expand Down Expand Up @@ -161,7 +161,7 @@ proto._requestDidComplete = function(res, body, callback) {
proto._requestDidFail = function(res, body, cb) {
var type, data, error;

type = res.headers['content-type'] || ""
type = res.headers['content-type'] || "";

// The content-type is expected to be text/plain.
if (type !== 'text/plain') {
Expand All @@ -187,5 +187,9 @@ proto._requestDidFail = function(res, body, cb) {
error = res.statusCode === 404 ? "Unknown command" : "Unknown error";
}

if (typeof error === 'string') {
error = new Error(error);
}

cb(error);
};
4 changes: 2 additions & 2 deletions lib/endpoint.js
Expand Up @@ -31,7 +31,7 @@ function constructor(opts) {
, port: opts.port
, path: opts.path
});
};
}

/**
* Retrieves status of the endpoint.
Expand All @@ -43,7 +43,7 @@ proto.status = function(callback) {
if (err) {
return callback(err);
}

callback(null, res.value);
});
};
Expand Down
7 changes: 5 additions & 2 deletions lib/session.js
Expand Up @@ -72,11 +72,14 @@ proto.execute = function(fn, args, callback) {

if (typeof args === 'function') {
callback = args;
args = [];
args = null;
}

args = args || [];

this.post('/execute', {script: fn, args: args}, function(err, res) {
if (err) {
callback(err);
return callback(err);
}

callback(null, res.value);
Expand Down
2 changes: 2 additions & 0 deletions test/endpoint_test.js
@@ -1,3 +1,5 @@
/*global suite test*/

var assert = require('chai').assert
, spy = require('sinon').spy
, Endpoint = require('webdriver/lib/endpoint')
Expand Down
5 changes: 5 additions & 0 deletions test/session_test.js
@@ -1,3 +1,5 @@
/*global suite test*/

var assert = require('chai').assert
,spy = require('sinon').spy
, Session = require('webdriver/lib/session');
Expand Down Expand Up @@ -32,6 +34,7 @@ suite('Session', function() {
assert.instanceOf(session, Session);
});
}); // constructor

suite('request', function() {
var method = 'GET'
, resource = '/foo'
Expand All @@ -54,6 +57,7 @@ suite('Session', function() {
assert.equal(args[3], callback, 'callback is not modified');
});
}); // request

suite('url', function() {
test('retrieves url when called without string', function() {
var client = fakeClient()
Expand All @@ -71,6 +75,7 @@ suite('Session', function() {
assert.equal(args[2], null, 'params are not defined');
assert.equal(args[3], callback, 'callback is passed');
});

test('navigates to url when called with a string', function() {
var client = fakeClient()
, session = Session.create({id: 1, client: client})
Expand Down

0 comments on commit 8368ce5

Please sign in to comment.