Skip to content
Browse files

Provide query CLI option to the server.

The query option specifies a query-string parameter
that will be added during testing. This is used
to trigger YUI Loader to load instrumented files
for code coverage, e.g. with filter=coverage.

Note: router support for the query string does not exist yet,
so files requested will contain the query part of the URL
as the filename.
  • Loading branch information...
1 parent 3b47634 commit 4febb03856dd7a9b25ff3aaf5941399a02f0b645 @reid reid committed Aug 22, 2012
Showing with 27 additions and 12 deletions.
  1. +6 −3 lib/cli.js
  2. +5 −2 lib/client.js
  3. +15 −6 lib/hub/batch.js
  4. +1 −1 lib/hub/index.js
View
9 lib/cli.js
@@ -64,6 +64,7 @@ function parseArgv(argv) {
"server": Boolean,
"version": Boolean,
"loglevel": ["info", "debug"],
+ "query": String,
"debug": Boolean,
"port": Number,
"hub": String,
@@ -80,9 +81,10 @@ function parseArgv(argv) {
return nopt(knownOptions, shortHands, argv);
}
-function submitBatch(client, tests, cb) {
+function submitBatch(client, query, tests, cb) {
var batch = client.createBatch({
basedir: process.cwd(),
+ query: query,
tests: tests
}),
timeStart = Number(new Date()),
@@ -243,6 +245,7 @@ function runBatch(options) {
var files = options.argv.remain,
port = options.port || 9000,
url = options.hub,
+ query = options.query,
debug = options.debug;
function prepareTests(client) {
@@ -260,7 +263,7 @@ function runBatch(options) {
});
if (agents.length > 0) {
- submitBatch(client, files);
+ submitBatch(client, query, files);
} else {
if (!isTTY) {
// TODO Only throw this error if no agents are immediately available.
@@ -278,7 +281,7 @@ function runBatch(options) {
rl.question("When ready, press Enter to begin testing.\n", function () {
rl.close();
process.stdin.destroy();
- submitBatch(client, files);
+ submitBatch(client, query, files);
});
}
});
View
7 lib/client.js
@@ -21,9 +21,10 @@ var Blizzard = require("./blizzard");
* @param {BlizzardSession} session Connected Blizzard session to the Hub.
* @param {String} basedir The base path to serve tests from.
* @param {Array} tests An array of string paths of test files.
+ * @param {String} query Query string additions for test URLs.
* @param {Boolean} useProxy True if tests should be fetched over RPC, false otherwise.
*/
-function ClientBatch(session, basedir, tests, useProxy) {
+function ClientBatch(session, basedir, tests, query, useProxy) {
if (!basedir && useProxy) {
throw new Error("Basedir required.");
}
@@ -50,6 +51,7 @@ function ClientBatch(session, basedir, tests, useProxy) {
this.session.emit("rpc.batch", {
tests: tests,
+ query: query,
useProxy: useProxy
}, this.emit.bind(this, "ack"));
}
@@ -261,6 +263,7 @@ Client.prototype.handleBlizzardError = function (err) {
* Must contain tests (Array) property.
* Must also contain either:
* - basedir (String) -- Root path for test filenames.
+ * - query (String) -- Query string additions for test URLs.
* - useProxy (Boolean) --
* True if tests are filenames to proxy to the Hub,
* false if they are literal URL pathnames.
@@ -280,7 +283,7 @@ Client.prototype.createBatch = function (config) {
config.useProxy = true;
}
- return new ClientBatch(this.session, config.basedir, config.tests, config.useProxy);
+ return new ClientBatch(this.session, config.basedir, config.tests, config.query, config.useProxy);
};
/**
View
21 lib/hub/batch.js
@@ -1,7 +1,7 @@
"use strict";
var util = require("util");
-var EventEmitter2 = require("eventemitter2").EventEmitter2;
+var EventEmitter2 = require("../events").EventEmitter2;
var EventYoshi = require("eventyoshi");
var TestServer = require("./test-server");
@@ -15,13 +15,15 @@ var TestServer = require("./test-server");
* @param {Number} id Batch ID.
* @param {BlizzardSession} session Hub session.
* @param {Array} tests Array of tests.
+ * @param {String} query Query string additions for test URLs.
* @param {Boolean} useProxy True if tests should be fetched over RPC, false otherwise.
*/
-function Batch(manager, id, session, tests, useProxy) {
+function Batch(manager, id, session, tests, query, useProxy) {
this.manager = manager;
this.id = id;
this.session = session;
this.tests = tests;
+ this.query = query;
this.useProxy = useProxy;
this.agentManager = manager.agentManager;
@@ -153,6 +155,7 @@ Batch.prototype.dispatch = function () {
var agents = this.manager.agentManager.getAvailableAgents(),
agentNames = [],
+ query = this.query,
mountpoint = this.manager.hub.mountpoint,
self = this;
@@ -168,6 +171,8 @@ Batch.prototype.dispatch = function () {
self.batchSession.emit("rpc.dispatch", agentNames);
+ self.debug("dispatch, query:", query);
+
agents.forEach(function (agent) {
var id = agent.getId(),
urls = [];
@@ -176,11 +181,12 @@ Batch.prototype.dispatch = function () {
self.runningAgents[id] = true;
self.agentEmitter.add(agent);
-
+
if (self.useProxy) {
self.tests.forEach(function (test) {
urls.push(mountpoint + "/agent/" + id +
- "/batch/" + self.id + "/test/" + test);
+ "/batch/" + self.id + "/test/" + test
+ + (query ? "?" + query : ""));
});
} else {
// Call slice to pass each urlQueue by value, not by reference.
@@ -270,13 +276,16 @@ BatchManager.prototype.destroyBatch = function (id) {
*
* @param {BlizzardSession} session Hub session.
* @param {Array} tests Array of tests.
+ * @param {String} query Query string additions for test URLs.
* @param {Boolean} useProxy True if tests should be fetched over RPC, false otherwise.
* @param {Function} reply Blizzard reply callback.
*/
-BatchManager.prototype.createBatch = function (session, tests, useProxy, reply) {
+BatchManager.prototype.createBatch = function (session, tests, query, useProxy, reply) {
var id = this.newId();
- this.batches[id] = new Batch(this, id, session, tests, useProxy);
+ this.batches[id] = new Batch(this, id, session, tests, query, useProxy);
+
+ this.batches[id].pipeLog(this.hub);
this.batches[id].batchSession.once("end", this.destroyBatch.bind(this, id));
View
2 lib/hub/index.js
@@ -122,7 +122,7 @@ Hub.prototype._setupEvents = function () {
var self = this;
self.on("batch", function (session, data, reply) {
- self.batchManager.createBatch(session, data.tests, data.useProxy, reply);
+ self.batchManager.createBatch(session, data.tests, data.query, data.useProxy, reply);
});
self.agentManager.on("agentConnect", self.sessions.emit.bind(self.sessions, "rpc.agentConnect"));

0 comments on commit 4febb03

Please sign in to comment.
Something went wrong with that request. Please try again.