Skip to content

Commit

Permalink
Lint client module.
Browse files Browse the repository at this point in the history
  • Loading branch information
reid committed Mar 8, 2012
1 parent d5ebc19 commit 5f1c6d6
Showing 1 changed file with 113 additions and 113 deletions.
226 changes: 113 additions & 113 deletions lib/client.js
Expand Up @@ -11,118 +11,6 @@ var EventEmitter2 = require("eventemitter2").EventEmitter2;


var Blizzard = require("./blizzard"); var Blizzard = require("./blizzard");


/**
* The Client submits test batches to a Yeti Hub and tracks their progress.
*
* @class Client
* @constructor
* @extends EventEmitter2
* @param {String} url Yeti Hub HTTP URL.
*/
function Client(url) {
EventEmitter2.call(this);

this.session = null;

this.url = url;

this.blizzard = new Blizzard();

this.blizzard.on("error", this.handleBlizzardError.bind(this));
}

util.inherits(Client, EventEmitter2);

/**
* Something went wrong.
* @event error
* @param {Error} error The error object.
*/

/**
* An agent connected to the Hub.
* @event agentConnect
* @param {String} agent Agent name.
*/

/**
* An agent requested a page (test or capture) from the connected Hub.
* @event agentSeen
* @param {String} agent Agent name.
*/

/**
* An agent disconnected from the Hub.
* @event agentDisconnect
* @param {String} agent Agent name.
*/

/**
* Connect to the Yeti Hub.
*
* @method connect
* @param {Function} cb Callback function.
*/
Client.prototype.connect = function (cb) {
var self = this;
self.blizzard.connect(self.url, function (err, session) {
if (err) {
cb(err);
return;
}

session.incomingBridge(self, "agentConnect");
session.incomingBridge(self, "agentSeen");
session.incomingBridge(self, "agentDisconnect");

self.session = session;

cb(err);
});
};

/**
* @method handleBlizzardError
* @protected
*/
Client.prototype.handleBlizzardError = function (err) {
if (err.code === "ECONNRESET") {
this.emit("error", new Error("Server does not speak Yeti's protocol. Version mismatch?"));
return;
}
this.emit("error", err);
};

/**
* Create and submit a batch of tests to the Hub.
*
* @method createBatch
* @param {Object} config Batch information.
* Must contain tests (Array) property.
* Must also contain either:
* - basedir (String) -- Root path for test filenames.
* - useProxy (Boolean) --
* True if tests are filenames to proxy to the Hub,
* false if they are literal URL pathnames.
* Optional. Defaults to true.
* @return {ClientBatch} batch The new ClientBatch object.
*/
Client.prototype.createBatch = function (config) {
// TODO check if connection happened!
// this.session may not yet exist
if (!this.session) {
// TODO Refactor to make this impossible.
throw new Error("Session started too soon -- Yeti bug.");
}

if (!("useProxy" in config)) {
// Use the proxy by default.
config.useProxy = true;
}

return new ClientBatch(this.session, config.basedir, config.tests, config.useProxy);
};

/** /**
* The ClientBatch represents a batch on the Hub. * The ClientBatch represents a batch on the Hub.
* *
Expand Down Expand Up @@ -159,7 +47,7 @@ function ClientBatch(session, basedir, tests, useProxy) {
tests: tests, tests: tests,
useProxy: useProxy useProxy: useProxy
}, this.emit.bind(this, "ack")); }, this.emit.bind(this, "ack"));
}; }


util.inherits(ClientBatch, EventEmitter2); util.inherits(ClientBatch, EventEmitter2);


Expand Down Expand Up @@ -240,6 +128,118 @@ ClientBatch.prototype.provideTests = function () {


}; };


/**
* The Client submits test batches to a Yeti Hub and tracks their progress.
*
* @class Client
* @constructor
* @extends EventEmitter2
* @param {String} url Yeti Hub HTTP URL.
*/
function Client(url) {
EventEmitter2.call(this);

this.session = null;

this.url = url;

this.blizzard = new Blizzard();

this.blizzard.on("error", this.handleBlizzardError.bind(this));
}

util.inherits(Client, EventEmitter2);

/**
* Something went wrong.
* @event error
* @param {Error} error The error object.
*/

/**
* An agent connected to the Hub.
* @event agentConnect
* @param {String} agent Agent name.
*/

/**
* An agent requested a page (test or capture) from the connected Hub.
* @event agentSeen
* @param {String} agent Agent name.
*/

/**
* An agent disconnected from the Hub.
* @event agentDisconnect
* @param {String} agent Agent name.
*/

/**
* Connect to the Yeti Hub.
*
* @method connect
* @param {Function} cb Callback function.
*/
Client.prototype.connect = function (cb) {
var self = this;
self.blizzard.connect(self.url, function (err, session) {
if (err) {
cb(err);
return;
}

session.incomingBridge(self, "agentConnect");
session.incomingBridge(self, "agentSeen");
session.incomingBridge(self, "agentDisconnect");

self.session = session;

cb(err);
});
};

/**
* @method handleBlizzardError
* @protected
*/
Client.prototype.handleBlizzardError = function (err) {
if (err.code === "ECONNRESET") {
this.emit("error", new Error("Server does not speak Yeti's protocol. Version mismatch?"));
return;
}
this.emit("error", err);
};

/**
* Create and submit a batch of tests to the Hub.
*
* @method createBatch
* @param {Object} config Batch information.
* Must contain tests (Array) property.
* Must also contain either:
* - basedir (String) -- Root path for test filenames.
* - useProxy (Boolean) --
* True if tests are filenames to proxy to the Hub,
* false if they are literal URL pathnames.
* Optional. Defaults to true.
* @return {ClientBatch} batch The new ClientBatch object.
*/
Client.prototype.createBatch = function (config) {
// TODO check if connection happened!
// this.session may not yet exist
if (!this.session) {
// TODO Refactor to make this impossible.
throw new Error("Session started too soon -- Yeti bug.");
}

if (undefined === config.useProxy) {
// Use the proxy by default.
config.useProxy = true;
}

return new ClientBatch(this.session, config.basedir, config.tests, config.useProxy);
};

/** /**
* @class exports * @class exports
* @static * @static
Expand Down

0 comments on commit 5f1c6d6

Please sign in to comment.