Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

test-agent

Package Overview
Dependencies
Maintainers
1
Versions
108
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

test-agent - npm Package Compare versions

Comparing version 0.0.9 to 0.0.10

mocha/.npmignore

4

lib/node/bin/server.js

@@ -61,3 +61,3 @@ var server = new (require('../websocket-server')),

var httpServer = require('http').createServer(function (request, response) {
request.addListener('end', function () {
request.addListener('end', function onEnd() {
staticMiddleware.serve(request, response);

@@ -78,3 +78,3 @@ });

server.expose(configFile, function(){
server.expose(configFile, function onExpose(){
var Enhancements = require('../server/index');

@@ -81,0 +81,0 @@

@@ -14,3 +14,3 @@ var Client = require(__dirname + '/../../test-agent/websocket-client').TestAgent.WebsocketClient,

if(argv.help){
if (argv.help) {
optimist.showHelp();

@@ -20,9 +20,9 @@ process.exit(0);

instance.on('open', function(socket){
instance.on('open', function(socket) {
var files = process.argv.slice(3),
fsPath = require('path');
files = files.map(function(file){
files = files.map(function(file) {
file = fsPath.normalize(file);
if(file[0] !== '/'){
if (file[0] !== '/') {
file = fsPath.join(process.env.PWD, file);

@@ -29,0 +29,0 @@ }

@@ -8,3 +8,3 @@ var Proxy = require(__dirname + '/runner-stream-proxy'),

*/
function Reporter(options){
function Reporter(options) {
var key;

@@ -14,4 +14,4 @@

for(key in options){
if(options.hasOwnProperty(key)){
for (key in options) {
if (options.hasOwnProperty(key)) {
this[key] = options[key];

@@ -21,3 +21,3 @@ }

if(!this.reporterClass){
if (!this.reporterClass) {
this.reporterClass = require('mocha').reporters[this.defaultMochaReporter];

@@ -32,3 +32,3 @@ }

Reporter.prototype.createRunner = function(){
Reporter.prototype.createRunner = function createRunner() {
this.runner = new Responder();

@@ -49,5 +49,5 @@ this.reporter = new this.reporterClass(this.runner);

*/
Reporter.prototype.respond = function(line){
Reporter.prototype.respond = function respond(line) {
var data = Responder.parse(line);
if(data.event === 'start'){
if (data.event === 'start') {
this.createRunner();

@@ -54,0 +54,0 @@ this.emit('start', this);

var Responder = require(__dirname + '/../../test-agent/responder').TestAgent.Responder;
function copy(values, exclude){
function copy(values, exclude) {
var key;
if(!exclude){
if (!exclude) {
exclude = [];
}
for(key in values){
if(values.hasOwnProperty(key)){
if(exclude.indexOf(key) > -1){
for (key in values) {
if (values.hasOwnProperty(key)) {
if (exclude.indexOf(key) > -1) {
continue;

@@ -20,7 +20,7 @@ }

RunnerStreamProxy.Suite = function(suite){
RunnerStreamProxy.Suite = function Suite(suite) {
copy.call(this, suite);
};
RunnerStreamProxy.Test = function(test){
RunnerStreamProxy.Test = function Test(test) {
copy.call(this, test, ['fullTitle']);

@@ -30,7 +30,7 @@ this.__test__ = test;

RunnerStreamProxy.Test.prototype.fullTitle = function(){
RunnerStreamProxy.Test.prototype.fullTitle = function fullTitle() {
return this.__test__.fullTitle;
};
function RunnerStreamProxy(runner){
function RunnerStreamProxy(runner) {
var self = this;

@@ -44,3 +44,3 @@

'start': function(data){
'start': function onStart(data) {
runner.total = data.total;

@@ -50,11 +50,11 @@ runner.emit('start', data);

'log': function(data){
'log': function onLog(data) {
console.log.apply(console, data.messages);
},
'end': function(data){
'end': function onEnd(data) {
runner.emit('end', data);
},
'suite': function(data){
'suite': function onSuite(data) {
this.parent = new RunnerStreamProxy.Suite(data);

@@ -64,3 +64,3 @@ runner.emit('suite', this.parent);

'suite end': function(data){
'suite end': function onSuiteEnd(data) {
runner.emit('suite end', new RunnerStreamProxy.Suite(data));

@@ -70,3 +70,3 @@ this.parent = null;

'test': function(data){
'test': function onTest(data) {
self.err = null;

@@ -94,5 +94,5 @@ runner.emit('test', this._createTest(data));

*/
RunnerStreamProxy.prototype._emitTest = function(event, data){
RunnerStreamProxy.prototype._emitTest = function _emitTest(event, data) {
var err;
if(data.err){
if (data.err) {
err = data.err;

@@ -111,3 +111,3 @@ this.err = err;

*/
RunnerStreamProxy.prototype._createTest = function(data){
RunnerStreamProxy.prototype._createTest = function _createTest(data) {
var test = new RunnerStreamProxy.Test(data);

@@ -117,3 +117,3 @@

if(this.err){
if (this.err) {
test.err = this.err;

@@ -120,0 +120,0 @@ }

@@ -9,7 +9,7 @@ var WebSocketPool = require(__dirname + '/../websocket-pool');

*/
function Broadcast(){
function Broadcast() {
this.pool = new WebSocketPool();
}
Broadcast.prototype.enhance = function(server){
Broadcast.prototype.enhance = function enhance(server) {
server.socket.on('connection', this._onConnection.bind(this));

@@ -19,7 +19,7 @@ server.broadcast = this._broadcast.bind(this);

Broadcast.prototype._broadcast = function(message){
Broadcast.prototype._broadcast = function _broadcast(message) {
this.pool.broadcast(message);
};
Broadcast.prototype._onConnection = function(socket){
Broadcast.prototype._onConnection = function _onConnection(socket) {
this.pool.add(socket);

@@ -30,3 +30,3 @@

Broadcast.prototype._onConnectionClose = function(socket){
Broadcast.prototype._onConnectionClose = function _onConnectionClose(socket) {
this.pool.remove(socket);

@@ -33,0 +33,0 @@ };

@@ -9,3 +9,3 @@ var Reporter = require(__dirname + '/../mocha/reporter');

*/
function Mocha(options){
function Mocha(options) {
this.reporter = new Reporter(options);

@@ -16,3 +16,3 @@ }

enhance: function(server){
enhance: function enhance(server) {
server.on('test data', this._onTestData.bind(this));

@@ -22,7 +22,7 @@ this.reporter.on('start', this._onRunnerStart.bind(this, server));

_onTestData: function(data, socket){
_onTestData: function _onTestData(data, socket) {
this.reporter.respond(data);
},
_onRunnerStart: function(server, runner){
_onRunnerStart: function _onRunnerStart(server, runner) {
server.emit('test runner', runner);

@@ -29,0 +29,0 @@ }

@@ -7,3 +7,3 @@ /**

*/
function StartTests(){}
function StartTests() {}

@@ -14,11 +14,11 @@ StartTests.prototype = {

enhance: function(server){
enhance: function enhance(server) {
server.on(this.eventName, this._startTests.bind(this, server));
},
_startTests: function(server, data){
if(data && data.files && data.files.length > 0){
_startTests: function _startTests(server, data) {
if (data && data.files && data.files.length > 0) {
this._broadCastFiles(server, data.files);
} else {
server.suite.findTestFiles(function(err, files){
server.suite.findTestFiles(function(err, files) {
this._broadCastFiles(server, files);

@@ -29,5 +29,5 @@ }.bind(this));

_broadCastFiles: function(server, files){
var list = files.map(function(file){
_broadCastFiles: function _broadCastFiles(server, files) {
var list = files.map(function(file) {
var result = server.suite.testFromPath(file);

@@ -34,0 +34,0 @@ return result.testUrl;

@@ -18,3 +18,3 @@ /**

*/
function Responder(){
function Responder() {

@@ -24,11 +24,11 @@ }

Responder.prototype = {
enhance: function(server){
enhance: function enhance(server) {
server.socket.on('connection', this._onConnection.bind(this, server));
},
_onConnection: function(server ,socket){
_onConnection: function _onConnection(server ,socket) {
socket.on('message', this._onConnectionMessage.bind(this, server, socket));
},
_onConnectionMessage: function(server, socket, data){
_onConnectionMessage: function _onConnectionMessage(server, socket, data) {
server.respond(data, socket);

@@ -35,0 +35,0 @@ }

@@ -8,3 +8,3 @@ /**

*/
function Growl(){}
function Growl() {}

@@ -20,7 +20,7 @@ Growl.prototype = {

enhance: function(server){
enhance: function enhance(server) {
server.on('test runner', this.growl.bind(this, server));
},
growl: function(server, proxy) {
growl: function growl(server, proxy) {
var notify = this.notify,

@@ -31,3 +31,3 @@ images = this.images,

runner.on('end', function(){
runner.on('end', function onEnd() {
var stats = reporter.stats;

@@ -34,0 +34,0 @@ if (stats.failures) {

@@ -8,3 +8,3 @@ /**

*/
function Suite(suite){
function Suite(suite) {
this.suite = suite;

@@ -14,3 +14,3 @@ }

Suite.prototype = {
enhance: function(server){
enhance: function enhance(server) {
server.suite = this.suite;

@@ -17,0 +17,0 @@ }

@@ -10,5 +10,5 @@ var FileWatcher = require(__dirname + '/../watchr'),

*
* @param {Suite} suite object from node/suite
* @param {Suite} suite object from node/suite.
*/
function Watcher(){}
function Watcher() {}

@@ -20,3 +20,3 @@ Watcher.prototype = {

enhance: function(server){
enhance: function enhance(server) {
this.suite = server.suite;

@@ -26,5 +26,5 @@ this.start(this._onFileChange.bind(this, server));

start: function(callback){
this.suite.findFiles(function(err, files){
if(err){
start: function start(callback) {
this.suite.findFiles(function(err, files) {
if (err) {
throw err;

@@ -37,3 +37,3 @@ }

_onFileChange: function(server, file){
_onFileChange: function _onFileChange(server, file) {
server.emit(this.eventName, {files: [file]});

@@ -40,0 +40,0 @@ }

@@ -19,14 +19,14 @@ var fsPath = require('path'),

'libDir',
'testDir',
'testDir'
];
Suite._joinPath = function(key){
Suite._joinPath = function _joinPath(key) {
this[key] = fsPath.join(fsPath.normalize(this[key]), '/');
};
function Suite(options){
function Suite(options) {
var option;
for(option in options){
if(options.hasOwnProperty(option)){
for (option in options) {
if (options.hasOwnProperty(option)) {
this[option] = options[option];

@@ -36,5 +36,5 @@ }

for(option in Suite.defaults){
if(Suite.defaults.hasOwnProperty(option)){
if(typeof(this[option]) === 'undefined'){
for (option in Suite.defaults) {
if (Suite.defaults.hasOwnProperty(option)) {
if (typeof(this[option]) === 'undefined') {
this[option] = Suite.defaults[option];

@@ -55,3 +55,3 @@ }

_definePatterns: function(){
_definePatterns: function _definePatterns() {
var ptns = this.patterns = {},

@@ -61,3 +61,3 @@ prefix;

prefix = (this.strictMode)? '^' : '';
prefix = (this.strictMode) ? '^' : '';

@@ -81,11 +81,11 @@ ptns.testSuffix = new RegExp(

relativePath: function(path){
relativePath: function relativePath(path) {
return path.replace(this.path, '');
},
swapPaths: function(path, type){
var other = (type == 'lib')? 'test' : 'lib',
swapPaths: function swapPaths(path, type) {
var other = (type == 'lib') ? 'test' : 'lib',
result;
if(this.patterns[type + 'Dir'].test(path)){
if (this.patterns[type + 'Dir'].test(path)) {
return path;

@@ -106,5 +106,5 @@ }

*
* @param {Function} callback first argument is the list of files found
* @param {Function} callback first argument is the list of files found.
*/
findFiles: function(callback){
findFiles: function findFiles(callback) {
//always 2

@@ -114,4 +114,4 @@ var pending = 2,

function joinResults(err, found){
if(err){
function joinResults(err, found) {
if (err) {
callback(err);

@@ -124,3 +124,3 @@ } else {

if(pending === 0){
if (pending === 0) {
callback(null, files);

@@ -134,3 +134,3 @@ }

_filterFile: function(type, path){
_filterFile: function _filterFile(type, path) {
return this.matchesType(type, path);

@@ -144,3 +144,3 @@ },

*/
findTestFiles: function(callback){
findTestFiles: function findTestFiles(callback) {
MatchFiles.find(this.path, {

@@ -156,3 +156,3 @@ fileFilters: [this._filterFile.bind(this, 'test')]

*/
findLibFiles: function(callback){
findLibFiles: function findLibFiles(callback) {
MatchFiles.find(this.path, {

@@ -167,10 +167,10 @@ fileFilters: [this._filterFile.bind(this, 'lib')]

*
* @param {String} type lib or test
* @param {String} path the relative path of the file
* @param {String} type lib or test.
* @param {String} path the relative path of the file.
*/
matchesType: function(type, path){
matchesType: function matchesType(type, path) {
var pathRegex = this.patterns[type + 'Dir'],
fileRegex = this.patterns[type + 'Suffix'];
if(!pathRegex || !fileRegex){
if (!pathRegex || !fileRegex) {
throw Error("Invalid type '" + type + "'");

@@ -182,3 +182,3 @@ }

testFromPath: function(path){
testFromPath: function testFromPath(path) {
var results = {};

@@ -185,0 +185,0 @@ path = this.relativePath(path);

@@ -10,3 +10,3 @@ /* there are other watchr's but they don't do the trick */

*/
function Watchr(files){
function Watchr(files) {
this.files = files;

@@ -18,9 +18,9 @@ this.watchers = {};

start: function(callback){
start: function start(callback) {
var self = this;
this.files.forEach(function(file){
var result = fs.watchFile(file, {interval: 100}, function(curr, prev){
if(curr.mtime > prev.mtime){
this.files.forEach(function(file) {
var result = fs.watchFile(file, {interval: 100}, function(curr, prev) {
if (curr.mtime > prev.mtime) {
callback(file);

@@ -34,6 +34,6 @@ }

stop: function(){
stop: function stop() {
var file;
for(file in this.watchers){
for (file in this.watchers) {
this.watchers[file].stop();

@@ -40,0 +40,0 @@ delete this.watchers[file];

var PoolBase = require('../../lib/test-agent/pool-base').TestAgent.PoolBase;
function WebsocketPool(){
function WebsocketPool() {
PoolBase.apply(this, arguments);

@@ -11,3 +11,3 @@ }

WebsocketPool.prototype.objectDetails = function(object){
WebsocketPool.prototype.objectDetails = function objectDetails(object) {
var result = {};

@@ -21,3 +21,3 @@

WebsocketPool.prototype.checkObjectValue = function(value){
WebsocketPool.prototype.checkObjectValue = function checkObjectValue(value) {
return (!('socket' in value) || !value.socket.destroyed);

@@ -31,7 +31,7 @@ };

*/
WebsocketPool.prototype.broadcast = function(message){
WebsocketPool.prototype.broadcast = function broadcast(message) {
this.each(this._broadcastEach.bind(this, message));
};
WebsocketPool.prototype._broadcastEach = function(message, socket){
WebsocketPool.prototype._broadcastEach = function _broadcastEach(message, socket) {
socket.send(message);

@@ -38,0 +38,0 @@ };

@@ -7,3 +7,3 @@ var ws = require('websocket.io'),

function Server(){
function Server() {
this.implementation = ws;

@@ -16,3 +16,3 @@ this.socket = null;

Server.prototype = Object.create(Responder.prototype);
Server.prototype._createSandbox = function(file){
Server.prototype._createSandbox = function _createSandbox(file) {
return {

@@ -33,3 +33,3 @@ server: this,

* Enhancement = function(options){}
* Enhancement.prototype.enhance = function(server){
* Enhancement.prototype.enhance = function enhance(server){
* //do stuff

@@ -46,3 +46,3 @@ * }

*/
Server.prototype.use = function(enhancement, options){
Server.prototype.use = function use(enhancement, options) {
new enhancement(options).enhance(this);

@@ -59,10 +59,10 @@

*/
Server.prototype.expose = function(file, callback){
Server.prototype.expose = function expose(file, callback) {
var sandbox = this._createSandbox(file);
fs.readFile(file, 'utf8', function(err, code){
if(err){
fs.readFile(file, 'utf8', function(err, code) {
if (err) {
throw err;
}
vm.runInNewContext(code, sandbox, file);
if(callback){
if (callback) {
callback();

@@ -73,3 +73,3 @@ }

Server.prototype._delegate = function(){
Server.prototype._delegate = function delegate() {
var args = Array.prototype.slice.call(arguments),

@@ -86,5 +86,5 @@ func = args.shift();

*
* @return {Object} result of this.implementation.attach
* @return {Object} result of this.implementation.attach.
*/
Server.prototype.attach = function(){
Server.prototype.attach = function attach() {
var args = Array.prototype.slice.call(arguments);

@@ -100,5 +100,5 @@ args.unshift('attach');

*
* @return {Object} result of this.implementation.listen
* @return {Object} result of this.implementation.listen.
*/
Server.prototype.listen = function(){
Server.prototype.listen = function listen() {
var args = Array.prototype.slice.call(arguments);

@@ -111,3 +111,3 @@ args.unshift('listen');

module.exports = exports = Server;
module.exports = exports = Server;

@@ -1,27 +0,33 @@

(function(window){
(function(window) {
'use strict';
if(typeof(window.TestAgent) === 'undefined'){
if (typeof(window.TestAgent) === 'undefined') {
window.TestAgent = {};
}
TestAgent.BrowserWorker = function(options){
TestAgent.BrowserWorker = function BrowserWorker(options) {
var self = this,
dep = this.deps;
if(typeof(options) === 'undefined'){
if (typeof(options) === 'undefined') {
options = {};
}
this.deps.Server.call(
this,
options.server || this.defaults.server
);
function option(name) {
if (name in options) {
return options[name];
}
this.sandbox = new this.deps.Sandbox(
options.sandbox || this.defaults.sandbox
);
if (name in self.defaults) {
return self.defaults[name];
}
this.loader = new this.deps.Loader(
options.loader || this.defaults.loader
);
return undefined;
}
this.deps.Server.call(this, option('server'));
this.sandbox = new dep.Sandbox(option('sandbox'));
this.loader = new dep.Loader(option('loader'));
this._testsProcessor = [];

@@ -33,3 +39,3 @@ this.testRunner = options.testRunner;

TestAgent.BrowserWorker.prototype = Object.create(
TestAgent.WebsocketClient.prototype
TestAgent.WebsocketClient.prototype
);

@@ -57,10 +63,10 @@

*
* @param {Function} callback
* @param {Function} callback executed when sandbox is created.
*/
proto.createSandbox = function(callback){
proto.createSandbox = function createSandbox(callback) {
var self = this;
this.sandbox.run(function(){
this.sandbox.run(function onSandboxRun() {
self.loader.targetWindow = this;
if(callback){
if(!('require' in this)){
if (callback) {
if (!('require' in this)) {
this.require = self.loader.require.bind(self.loader);

@@ -74,3 +80,3 @@ }

proto._emitTestComplete = function(){
proto._emitTestComplete = function _emitTestComplete() {
var args = Array.prototype.slice.call(arguments);

@@ -89,6 +95,6 @@ args.unshift('run tests complete');

*
* @param {Function} callback
* @chainable
* @param {Function} callback reducer function.
* @return {Object} self.
*/
proto.addTestsProcessor = function(callback){
proto.addTestsProcessor = function addTestsProcessor(callback) {
this._testsProcessor.push(callback);

@@ -102,5 +108,5 @@ };

*
* @param {Array} tests
* @param {Array} tests list of tests to process.
*/
proto._processTests = function(tests){
proto._processTests = function _processTests(tests) {
var result = tests,

@@ -111,3 +117,3 @@ reducers = this._testsProcessor,

for(; i < length; i++){
for (; i < length; i++) {
result = reducers[i](result);

@@ -122,13 +128,13 @@ }

*
* @param {Array} tests
* @param {Array} tests list of tests to execute.
*/
proto.runTests = function(tests){
proto.runTests = function runTests(tests) {
var self = this,
done = this._emitTestComplete.bind(this);
if(!this.testRunner){
throw new Error("Worker must be provided a .testRunner method");
if (!this.testRunner) {
throw new Error('Worker must be provided a .testRunner method');
}
this.createSandbox(function(){
this.createSandbox(function createSandbox() {
self.testRunner(self, self._processTests(tests), done);

@@ -142,3 +148,3 @@ });

* Enhancement = function(options){}
* Enhancement.prototype.enhance = function(server){
* Enhancement.prototype.enhance = function enhance(server){
* //do stuff

@@ -151,7 +157,7 @@ * }

*
* @param {Object} enhancement
* @param {Object} options
* @chainable
* @param {Object} enhancement enhancement class.
* @param {Object} options options for class.
* @return {Object} self.
*/
proto.use = function(enhancement, options){
proto.use = function use(enhancement, options) {
new enhancement(options).enhance(this);

@@ -158,0 +164,0 @@

@@ -1,9 +0,9 @@

(function(window){
(function(window) {
'use strict';
var Worker = window.TestAgent.BrowserWorker;
Worker.Config = function(options){
if(typeof(options) === 'undefined'){
Worker.Config = function Config(options) {
if (typeof(options) === 'undefined') {
options = {};

@@ -16,10 +16,10 @@ }

Worker.Config.prototype = {
enhance: function(worker){
enhance: function enhance(worker) {
worker.config = this._config.bind(this, worker, this.config);
},
_config: function(worker, config, callback){
config.load(function(data){
_config: function _config(worker, config, callback) {
config.load(function(data) {
worker.emit('config', data);
if(callback){
if (callback) {
callback(data);

@@ -26,0 +26,0 @@ }

@@ -1,11 +0,13 @@

(function(window){
function MochaDriver (options) {
(function(window) {
'use strict';
function MochaDriver(options) {
var key;
if(typeof(options) === 'undefined'){
if (typeof(options) === 'undefined') {
options = {};
}
for(key in options){
if(options.hasOwnProperty(key)){
for (key in options) {
if (options.hasOwnProperty(key)) {
this[key] = options[key];

@@ -16,7 +18,7 @@ }

MochaDriver.createMutliReporter = function(){
MochaDriver.createMutliReporter = function createMultiReporter() {
var reporters = Array.prototype.slice.call(arguments);
return function(runner){
reporters.forEach(function(Report){
return function(runner) {
reporters.forEach(function(Report) {
new Report(runner);

@@ -32,3 +34,3 @@ });

enhance: function(worker){
enhance: function enhance(worker) {
this.worker = worker;

@@ -39,7 +41,7 @@ worker.testRunner = this._testRunner.bind(this);

_onRunTests: function(data){
_onRunTests: function _onRunTests(data) {
this.worker.runTests(data.tests || []);
},
getReporter: function(box){
getReporter: function getReporter(box) {
var stream = TestAgent.Mocha.JsonStreamReporter,

@@ -50,3 +52,3 @@ self = this;

stream.send = function(line){
stream.send = function send(line) {
self.worker.send('test data', line);

@@ -61,11 +63,11 @@ };

_testRunner: function(worker, tests, done){
_testRunner: function _testRunner(worker, tests, done) {
var box = worker.sandbox.getWindow(),
self = this;
worker.loader.done(function(){
worker.loader.done(function onDone() {
box.mocha.run(done);
});
box.require(this.mochaUrl, function(){
box.require(this.mochaUrl, function onRequireMocha() {
//setup mocha

@@ -80,3 +82,3 @@ box.mocha.setup({

tests.forEach(function(test){
tests.forEach(function(test) {
box.require(test);

@@ -83,0 +85,0 @@ });

@@ -1,6 +0,8 @@

(function(window){
(function(window) {
'use strict';
var FORMAT_REGEX = /%([0-9])?s/g;
var FORMAT_REGEX = /%([0-9])?s/g,
Worker = window.TestAgent.BrowserWorker;
function format(){
function format() {
var i = 0,

@@ -13,3 +15,3 @@ str,

result = str.replace(FORMAT_REGEX, function(match, pos){
result = str.replace(FORMAT_REGEX, function(match, pos) {
var index = parseInt(pos || i++, 10);

@@ -22,3 +24,3 @@ return args[index];

function fragment(){
function fragment() {
var string = format.apply(this, arguments),

@@ -31,6 +33,6 @@ element = document.createElement('div');

var TestUi = window.TestAgent.BrowserWorker.TestUi = function(options){
var TestUi = Worker.TestUi = function TestUi(options) {
var selector;
if(typeof(options) === 'undefined'){
if (typeof(options) === 'undefined') {
options = {};

@@ -52,3 +54,3 @@ }

enhance: function(worker){
enhance: function enhance(worker) {
this.worker = worker;

@@ -58,3 +60,3 @@ this.worker.on('config', this.onConfig.bind(this));

onConfig: function(data){
onConfig: function onConfig(data) {
//purge elements

@@ -67,3 +69,3 @@ var elements = this.element.getElementsByTagName('*'),

for(; i < elements.length; i++){
for (; i < elements.length; i++) {
element = elements[i];

@@ -75,3 +77,3 @@ element.parentNode.removeChild(element);

data.tests.forEach(function(test){
data.tests.forEach(function(test) {
parent.appendChild(fragment(

@@ -93,3 +95,3 @@ templates.testItem,

initDomEvents: function(){
initDomEvents: function initDomEvents() {
var ul = this.element.querySelector('ul'),

@@ -100,8 +102,8 @@ button = this.element.querySelector('button'),

ul.addEventListener('click', function(e){
ul.addEventListener('click', function(e) {
var target = e.target,
url = target.getAttribute('data-url');
if(url){
if(self.queue[url]){
if (url) {
if (self.queue[url]) {
target.className = target.className.replace(activeClass, '');

@@ -116,7 +118,7 @@ delete self.queue[url];

button.addEventListener('click', function(){
button.addEventListener('click', function onTestClick() {
var tests = [], key;
for(key in self.queue){
if(self.queue.hasOwnProperty(key)){
for (key in self.queue) {
if (self.queue.hasOwnProperty(key)) {
tests.push(key);

@@ -123,0 +125,0 @@ }

@@ -1,14 +0,14 @@

(function(window){
(function(window) {
'use strict';
if(typeof(window.TestAgent) === 'undefined'){
if (typeof(window.TestAgent) === 'undefined') {
window.TestAgent = {};
}
var Server = window.TestAgent.Config = function(options){
var Server = window.TestAgent.Config = function Config(options) {
var key;
for(key in options){
if(options.hasOwnProperty(key)){
for (key in options) {
if (options.hasOwnProperty(key)) {
this[key] = options[key];

@@ -24,4 +24,2 @@ }

*
*
* @property url
* @type String

@@ -34,5 +32,3 @@ */

*
*
* @type Boolean
* @property ready
*/

@@ -44,3 +40,2 @@ ready: false,

*
* @property resources
* @type Array

@@ -53,8 +48,8 @@ */

*
* @param Object xhr xhr object
* @param {Object} xhr xhr object.
*/
_parseResponse: function(xhr){
_parseResponse: function _parseResponse(xhr) {
var response;
if(xhr.responseText){
if (xhr.responseText) {
response = JSON.parse(xhr.responseText);

@@ -74,3 +69,3 @@ //only return files for now...

*/
load: function(callback){
load: function load(callback) {
var xhr = new XMLHttpRequest(),

@@ -81,5 +76,5 @@ self = this,

xhr.open('GET', this.url, true);
xhr.onreadystatechange = function(){
if(xhr.readyState === 4){
if(xhr.status === 200 || xhr.status === 0){
xhr.onreadystatechange = function onReadyStateChange() {
if (xhr.readyState === 4) {
if (xhr.status === 200 || xhr.status === 0) {
response = self._parseResponse(xhr);

@@ -92,3 +87,3 @@

} else {
throw new Error('Could not fetch tests from "' + self.url + '"');
throw new Error('Could not fetch tests from "' + self.url + '"');
}

@@ -95,0 +90,0 @@ } else {

@@ -1,10 +0,10 @@

(function(window){
(function(window) {
'use strict';
if(typeof(window.TestAgent) === 'undefined'){
if (typeof(window.TestAgent) === 'undefined') {
window.TestAgent = {};
}
var Loader = window.TestAgent.Loader = function(options){
var Loader = window.TestAgent.Loader = function Loader(options) {
var key;

@@ -16,8 +16,8 @@

if(typeof(options) === 'undefined'){
if (typeof(options) === 'undefined') {
options = {};
}
for(key in options){
if(options.hasOwnProperty(key)){
for (key in options) {
if (options.hasOwnProperty(key)) {
this[key] = options[key];

@@ -34,3 +34,2 @@ }

* @type String
* @property prefix
*/

@@ -43,3 +42,2 @@ prefix: '',

* @type Boolean
* @property bustCache
*/

@@ -52,3 +50,2 @@ bustCache: true,

* @private
* @property targetWindow
* @type Window

@@ -61,3 +58,2 @@ */

*
* @property _cached
* @type Object

@@ -68,7 +64,7 @@ * @private

get targetWindow(){
get targetWindow() {
return this._targetWindow;
},
set targetWindow(value){
set targetWindow(value) {
this._targetWindow = value;

@@ -81,8 +77,8 @@ this._cached = {};

*/
_decrementPending: function(){
if(this.pending > 0){
_decrementPending: function _decrementPending() {
if (this.pending > 0) {
this.pending--;
}
if(this.pending <= 0){
if (this.pending <= 0) {
this._fireCallbacks();

@@ -92,5 +88,5 @@ }

_fireCallbacks: function(){
_fireCallbacks: function _fireCallbacks() {
var callback;
while((callback = this.doneCallbacks.shift())){
while ((callback = this.doneCallbacks.shift())) {
callback();

@@ -101,8 +97,8 @@ }

/**
* Adds a done callback
* Adds a done callback.
* You may call this function multiple times.
*
*
* @param {Function} callback
* @param {Function} callback called after all scripts are loaded.
*/
done: function(callback){
done: function done(callback) {
this.doneCallbacks.push(callback);

@@ -117,6 +113,6 @@ return this;

*
* @param {String} url
* @param {String} callback
* @param {String} url location to load script from.
* @param {String} callback callback when script loading is complete.
*/
require: function(url, callback){
require: function require(url, callback) {
var prefix = this.prefix,

@@ -128,3 +124,3 @@ suffix = '',

if(url in this._cached){
if (url in this._cached) {
//url is cached we are good

@@ -134,4 +130,5 @@ return;

if(this.bustCache){
suffix = '?time=' + String(Date.now()) + '&rand=' + String(Math.random() * 1000);
if (this.bustCache) {
suffix = '?time=' + String(Date.now()) +
'&rand=' + String(Math.random() * 1000);
}

@@ -148,4 +145,4 @@

element.type = 'text/javascript';
element.onload = function(){
if(callback){
element.onload = function scriptOnLoad() {
if (callback) {
callback();

@@ -152,0 +149,0 @@ }

@@ -1,8 +0,9 @@

(function(window){
(function(window) {
'use strict';
if(typeof(window.TestAgent) === 'undefined'){
if (typeof(window.TestAgent) === 'undefined') {
window.TestAgent = {};
}
if(typeof(window.TestAgent.Mocha) === 'undefined'){
if (typeof(window.TestAgent.Mocha) === 'undefined') {
window.TestAgent.Mocha = {};

@@ -16,3 +17,3 @@ }

MochaReporter.console = window.console;
MochaReporter.send = function(){};
MochaReporter.send = function mochaReporterSend() {};

@@ -31,3 +32,4 @@ //TODO -- Buffer console.log calls

MochaReporter.console.log = function(){
MochaReporter.console.log = function consoleLogShim() {
var args = Array.prototype.slice.call(arguments);
//real console log

@@ -38,7 +40,7 @@ log.apply(this, arguments);

var stack, messages = Array.prototype.slice.call(arguments).map(function(item){
if(!item){
var stack, messages = args.map(function(item) {
if (!item) {
return item;
}
return (item.toString)? item.toString() : item;
return (item.toString) ? item.toString() : item;
});

@@ -48,3 +50,3 @@

throw new Error();
} catch (e){
} catch (e) {
stack = e.stack;

@@ -54,3 +56,3 @@ }

//re-orgnaize the stack to exlude the above
stack = stack.split("\n").map(function(e){
stack = stack.split('\n').map(function(e) {
return e.trim().replace(/^at /, '');

@@ -60,39 +62,53 @@ });

stack.splice(0, 1);
stack = stack.join("\n");
stack = stack.join('\n');
//this is temp
MochaReporter.send(JSON.stringify(['log', {messages: messages, stack: stack}]));
MochaReporter.send(
JSON.stringify(['log', {messages: messages, stack: stack}])
);
};
runner.on('suite', function(suite){
runner.on('suite', function onSuite(suite) {
indentation++;
MochaReporter.send(JSON.stringify(['suite', jsonExport(suite, { indentation: indentation }) ]));
MochaReporter.send(
JSON.stringify(
['suite', jsonExport(suite, { indentation: indentation })]
)
);
});
runner.on('suite end', function(suite){
MochaReporter.send(JSON.stringify(['suite end', jsonExport(suite, { indentation: indentation }) ]));
runner.on('suite end', function onSuiteEnd(suite) {
MochaReporter.send(
JSON.stringify(
['suite end', jsonExport(suite, { indentation: indentation })]
)
);
indentation--;
});
runner.on('test', function(test){
MochaReporter.send(JSON.stringify(['test', jsonExport(test) ]));
runner.on('test', function onTest(test) {
MochaReporter.send(JSON.stringify(['test', jsonExport(test)]));
});
runner.on('test end', function(test){
MochaReporter.send(JSON.stringify(['test end', jsonExport(test) ]));
runner.on('test end', function onTestEnd(test) {
MochaReporter.send(JSON.stringify(['test end', jsonExport(test)]));
});
runner.on('start', function(){
MochaReporter.send( JSON.stringify(['start', { total: total }]) );
runner.on('start', function onStart() {
MochaReporter.send(JSON.stringify(['start', { total: total }]));
});
runner.on('pass', function(test){
runner.on('pass', function onPass(test) {
MochaReporter.send(JSON.stringify(['pass', jsonExport(test)]));
});
runner.on('fail', function(test, err){
MochaReporter.send(JSON.stringify(['fail', jsonExport(test, {err: jsonErrorExport(err) })]));
runner.on('fail', function onFail(test, err) {
MochaReporter.send(
JSON.stringify(
['fail', jsonExport(test, {err: jsonErrorExport(err) })]
)
);
});
runner.on('end', function(){
runner.on('end', function onEnd() {
MochaReporter.send(JSON.stringify(['end', self.stats]));

@@ -111,3 +127,3 @@ });

function jsonErrorExport(err){
function jsonErrorExport(err) {
var result = {};

@@ -128,8 +144,8 @@

exportKeys.forEach(function(key){
exportKeys.forEach(function(key) {
var value;
if(key in object){
if (key in object) {
value = object[key];
if(typeof(value) === 'function'){
if (typeof(value) === 'function') {
result[key] = object[key]();

@@ -142,5 +158,5 @@ } else {

if(typeof(additional) !== 'undefined'){
for(key in additional){
if(additional.hasOwnProperty(key)){
if (typeof(additional) !== 'undefined') {
for (key in additional) {
if (additional.hasOwnProperty(key)) {
result[key] = additional[key];

@@ -147,0 +163,0 @@ }

@@ -1,26 +0,58 @@

(function(window){
if(typeof(window.TestAgent) === 'undefined'){
/*(The MIT License)
Copyright (c) 20011-2012 TJ Holowaychuk <tj@vision-media.ca>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
(function(window) {
'use strict';
if (typeof(window.TestAgent) === 'undefined') {
window.TestAgent = {};
}
if(typeof(window.TestAgent.Mocha) === 'undefined'){
if (typeof(window.TestAgent.Mocha) === 'undefined') {
window.TestAgent.Mocha = {};
}
Base.slow = 75;
//Credit: mocha - https://github.com/visionmedia/mocha/blob/master/lib/reporters/base.js#L194
//Credit: mocha -
//https://github.com/visionmedia/mocha/blob/master/lib/reporters/base.js#L194
function Base(runner) {
var self = this
, stats = this.stats = { suites: 0, tests: 0, passes: 0, pending: 0, failures: 0 }
, failures = this.failures = [];
var self = this,
stats,
failures = this.failures = [];
stats = this.stats = {
suites: 0, tests: 0, passes: 0, pending: 0, failures: 0
};
if (!runner) return;
this.runner = runner;
runner.on('start', function(){
runner.on('start', function onStart() {
stats.start = new Date;
});
runner.on('suite', function(suite){
runner.on('suite', function onSuite(suite) {
stats.suites = stats.suites || 0;

@@ -30,3 +62,3 @@ suite.root || stats.suites++;

runner.on('test end', function(test){
runner.on('test end', function onTestEnd(test) {
stats.tests = stats.tests || 0;

@@ -36,11 +68,11 @@ stats.tests++;

runner.on('pass', function(test){
runner.on('pass', function onPass(test) {
stats.passes = stats.passes || 0;
var medium = Base.slow / 2;
test.speed = test.duration > Base.slow
? 'slow'
: test.duration > medium
? 'medium'
: 'fast';
//reformatted for gjslint
test.speed =
(test.duration > Base.slow) ?
'slow' : test.duration > medium ?
'medium' : 'fast';

@@ -50,3 +82,3 @@ stats.passes++;

runner.on('fail', function(test, err){
runner.on('fail', function onFail(test, err) {
stats.failures = stats.failures || 0;

@@ -58,3 +90,3 @@ stats.failures++;

runner.on('end', function(){
runner.on('end', function onEnd() {
stats.end = new Date;

@@ -64,3 +96,3 @@ stats.duration = new Date - stats.start;

runner.on('pending', function(){
runner.on('pending', function onPending() {
stats.pending++;

@@ -67,0 +99,0 @@ });

@@ -1,7 +0,9 @@

(function(exports){
if(typeof(exports.TestAgent) === 'undefined'){
(function(exports) {
'use strict';
if (typeof(exports.TestAgent) === 'undefined') {
exports.TestAgent = {};
}
var Pool = exports.TestAgent.PoolBase = function(){
var Pool = exports.TestAgent.PoolBase = function Pool() {
this._items = {};

@@ -13,6 +15,6 @@ this.length = 0;

add: function(object){
add: function add(object) {
var details = this.objectDetails(object);
if(!this.has(object))
if (!this.has(object))
this.length += 1;

@@ -23,5 +25,5 @@

remove: function(object){
remove: function remove(object) {
var details = this.objectDetails(object);
if(this.has(object)){
if (this.has(object)) {
this.length -= 1;

@@ -32,3 +34,3 @@ }

has: function(object){
has: function has(object) {
var details = this.objectDetails(object);

@@ -38,7 +40,7 @@ return !!(details.key && (details.key in this._items));

checkObjectValue: function(object){
checkObjectValue: function checkObjectValue(object) {
return true;
},
objectDetails: function(object){
objectDetails: function objectDetails(object) {
return object;

@@ -53,12 +55,12 @@ },

*
* @param {Function} callback
* @param {Function} callback executes for each element in the pool.
*/
each: function(callback){
each: function each(callback) {
var key, value;
for(key in this._items){
if(this._items.hasOwnProperty(key)){
for (key in this._items) {
if (this._items.hasOwnProperty(key)) {
value = this._items[key];
if(this.checkObjectValue(value)){
if (this.checkObjectValue(value)) {
callback(value, key);

@@ -72,5 +74,5 @@ }

}(
(typeof(window) === 'undefined')? module.exports : window
(typeof(window) === 'undefined') ? module.exports : window
));

@@ -1,3 +0,5 @@

(function(exports){
if(typeof(exports.TestAgent) === 'undefined'){
(function(exports) {
'use strict';
if (typeof(exports.TestAgent) === 'undefined') {
exports.TestAgent = {};

@@ -9,8 +11,8 @@ }

*
* @param {Object} list of events to add onto responder
* @param {Object} list of events to add onto responder.
*/
var Responder = exports.TestAgent.Responder = function(events){
var Responder = exports.TestAgent.Responder = function Responder(events) {
this.events = {};
if(typeof(events) !== 'undefined'){
if (typeof(events) !== 'undefined') {
this.addEventListener(events);

@@ -24,7 +26,7 @@ }

*
* @param {String} command command name
* @param {Object} data object to be sent over the wire
* @return {String} json object
* @param {String} command command name.
* @param {Object} data object to be sent over the wire.
* @return {String} json object.
*/
Responder.stringify = function(command, data){
Responder.stringify = function stringify(command, data) {
return JSON.stringify([command, data]);

@@ -36,10 +38,10 @@ };

*
* @param {String} json json string to translate
* @return {Object} object where .data is json data and .command is command name.
* @param {String} json json string to translate.
* @return {Object} ex: { event: 'test', data: {} }.
*/
Responder.parse = function(json){
Responder.parse = function parse(json) {
var data;
try {
data = (json.forEach)? json : JSON.parse(json);
} catch(e){
data = (json.forEach) ? json : JSON.parse(json);
} catch (e) {
throw new Error("Could not parse json: '" + json + '"');

@@ -58,3 +60,2 @@ }

*
* @property events
* @type Object

@@ -67,7 +68,9 @@ */

*
* @param {String} json
* @param {Object} params... option number of params to pass to emit
* @return {Object} result of WebSocketCommon.parse
* @param {String|Object} json data object to respond to.
* @param {String} json.event event to emit.
* @param {Object} json.data data to emit with event.
* @param {Object} [params] option number of params to pass to emit.
* @return {Object} result of WebSocketCommon.parse.
*/
respond: function(json){
respond: function respond(json) {
var event = Responder.parse(json),

@@ -90,11 +93,11 @@ args = Array.prototype.slice.call(arguments).slice(1);

*
* @param {String} type event name
* @param {String} callback
* @param {String} type event name.
* @param {String} callback event callback.
*/
addEventListener: function(type, callback){
addEventListener: function addEventListener(type, callback) {
var event;
if(typeof(callback) === 'undefined' && typeof(type) === 'object'){
for(event in type){
if(type.hasOwnProperty(event)){
if (typeof(callback) === 'undefined' && typeof(type) === 'object') {
for (event in type) {
if (type.hasOwnProperty(event)) {
this.addEventListener(event, type[event]);

@@ -107,3 +110,3 @@ }

if(!(type in this.events)){
if (!(type in this.events)) {
this.events[type] = [];

@@ -123,6 +126,6 @@ }

*
* @param {String} eventName
* @param {Arg...}
* @param {String} eventName name of the event to emit.
* @param {Object} [arguments] additional arguments to pass.
*/
emit: function(){
emit: function emit() {
var args = Array.prototype.slice.call(arguments),

@@ -133,6 +136,6 @@ event = args.shift(),

if(event in this.events){
if (event in this.events) {
eventList = this.events[event];
eventList.forEach(function(callback){
eventList.forEach(function(callback) {
callback.apply(self, args);

@@ -149,6 +152,6 @@ });

*
* @param {String} event
* @param {String} event event type to remove.
*/
removeAllEventListeners: function(name){
if(name in this.events){
removeAllEventListeners: function removeAllEventListeners(name) {
if (name in this.events) {
//reuse array

@@ -166,9 +169,9 @@ this.events[name].length = 0;

*
* @param {String} eventName event name
* @param {Function} callback
* @param {String} eventName event name.
* @param {Function} callback same instance of event handler.
*/
removeEventListener: function(name, callback){
removeEventListener: function removeEventListener(name, callback) {
var i, length, events;
if(!(name in this.events)){
if (!(name in this.events)) {
return false;

@@ -179,4 +182,4 @@ }

for(i = 0, length = events.length; i < length; i++){
if(events[i] && events[i] === callback){
for (i = 0, length = events.length; i < length; i++) {
if (events[i] && events[i] === callback) {
events.splice(i, 1);

@@ -195,4 +198,4 @@ return true;

}(
(typeof(window) === 'undefined')? module.exports : window
(typeof(window) === 'undefined') ? module.exports : window
));

@@ -1,10 +0,10 @@

(function(window){
(function(window) {
'use strict';
if(typeof(window.TestAgent) === 'undefined'){
if (typeof(window.TestAgent) === 'undefined') {
window.TestAgent = {};
}
var Sandbox = window.TestAgent.Sandbox = function(url){
var Sandbox = window.TestAgent.Sandbox = function Sandbox(url) {
this.url = url;

@@ -18,3 +18,2 @@ };

/**
* @property ready
* @type Boolean

@@ -29,3 +28,3 @@ *

*
* @return String
* @type String
*/

@@ -38,7 +37,7 @@ url: null,

*
* @return DOMElement
* @type DOMElement
*/
getElement: function(){
getElement: function getElement() {
var iframe;
if(!this._element){
if (!this._element) {
iframe = this._element = window.document.createElement('iframe');

@@ -50,3 +49,3 @@ iframe.src = this.url + '?time=' + String(Date.now());

run: function(callback){
run: function run(callback) {
//cleanup old sandboxes

@@ -60,3 +59,3 @@ this.destroy();

window.document.body.appendChild(element);
element.contentWindow.addEventListener('DOMContentLoaded', function(){
element.contentWindow.addEventListener('DOMContentLoaded', function() {
self.ready = true;

@@ -67,6 +66,6 @@ callback.call(this);

destroy: function(){
destroy: function destroy() {
var el;
if(!this.ready){
if (!this.ready) {
return false;

@@ -85,4 +84,4 @@ }

getWindow: function(){
if(!this.ready){
getWindow: function getWindow() {
if (!this.ready) {
return false;

@@ -89,0 +88,0 @@ }

//depends on TestAgent.Responder
(function(exports){
if(typeof(exports.TestAgent) === 'undefined'){
(function(exports) {
'use strict';
if (typeof(exports.TestAgent) === 'undefined') {
exports.TestAgent = {};
}
var Native, Responder;
var Native, Responder, TestAgent;
//Hack Arounds for node
if(typeof(window) === 'undefined'){
if (typeof(window) === 'undefined') {
Native = require('ws');

@@ -15,2 +17,3 @@ Responder = require('./responder').TestAgent.Responder;

TestAgent = exports.TestAgent;
Responder = Responder || TestAgent.Responder;

@@ -21,3 +24,2 @@ Native = (Native || WebSocket || MozWebSocket);

/**

@@ -32,14 +34,13 @@ * Creates a websocket client handles custom

*
* - retry (false by default)
* - retries (current number of retries)
* - retryLimit ( number of retries before error is thrown Infinity by default)
* - retryTimeout ( Time between retries 3000ms by default)
*
*
* @param {Object} options
* @param {Object} options retry options.
* @param {Boolean} option.retry (false by default).
* @param {Numeric} option.retryLimit \
* ( number of retries before error is thrown Infinity by default).
* @param {Numeric} option.retryTimeout \
* ( Time between retries 3000ms by default).
*/
var Client = exports.TestAgent.WebsocketClient = function(options){
var Client = TestAgent.WebsocketClient = function WebsocketClient(options) {
var key;
for(key in options){
if(options.hasOwnProperty(key)){
for (key in options) {
if (options.hasOwnProperty(key)) {
this[key] = options[key];

@@ -50,2 +51,4 @@ }

this.proxyEvents = ['open', 'close', 'message'];
this.on('close', this._incrementRetry.bind(this));

@@ -56,3 +59,3 @@ this.on('message', this._processMessage.bind(this));

Client.RetryError = function(){
Client.RetryError = function RetryError() {
Error.apply(this, arguments);

@@ -66,4 +69,2 @@ };

Client.prototype.proxyEvents = ['open', 'close', 'message'];
//Retry

@@ -75,7 +76,9 @@ Client.prototype.retry = false;

Client.prototype.start = function(){
Client.prototype.start = function start() {
var i, event;
if(this.retry && this.retries >= this.retryLimit){
throw new Client.RetryError('Retry limit has been reach retried ' + String(this.retries) + ' times');
if (this.retry && this.retries >= this.retryLimit) {
throw new Client.RetryError(
'Retry limit has been reach retried ' + String(this.retries) + ' times'
);
}

@@ -85,3 +88,3 @@

for(i = 0; i < this.proxyEvents.length; i++){
for (i = 0; i < this.proxyEvents.length; i++) {
event = this.proxyEvents[i];

@@ -97,11 +100,11 @@ this.socket.addEventListener(event, this._proxyEvent.bind(this, event));

*
* @param {String} event
* @param {String} data
* @param {String} event event to send.
* @param {String} data object to send to the server.
*/
Client.prototype.send = function(event, data){
Client.prototype.send = function send(event, data) {
this.socket.send(this.stringify(event, data));
};
Client.prototype._incrementRetry = function(){
if(this.retry){
Client.prototype._incrementRetry = function _incrementRetry() {
if (this.retry) {
this.retries++;

@@ -112,4 +115,4 @@ setTimeout(this.start.bind(this), this.retryTimeout);

Client.prototype._processMessage = function(message){
if(message.data){
Client.prototype._processMessage = function _processMessage(message) {
if (message.data) {
message = message.data;

@@ -120,7 +123,7 @@ }

Client.prototype._clearRetries = function(){
Client.prototype._clearRetries = function _clearRetries() {
this.retries = 0;
};
Client.prototype._proxyEvent = function(){
Client.prototype._proxyEvent = function _proxyEvent() {
this.emit.apply(this, arguments);

@@ -130,3 +133,3 @@ };

}(
(typeof(window) === 'undefined')? module.exports : window
(typeof(window) === 'undefined') ? module.exports : window
));
{
"name": "test-agent",
"version": "0.0.9",
"version": "0.0.10",
"author": "James Lal",

@@ -5,0 +5,0 @@ "description": "execute client side tests from browser report back to cli",

@@ -1,3 +0,5 @@

(function(exports){
if(typeof(exports.TestAgent) === 'undefined'){
(function(exports) {
'use strict';
if (typeof(exports.TestAgent) === 'undefined') {
exports.TestAgent = {};

@@ -9,8 +11,8 @@ }

*
* @param {Object} list of events to add onto responder
* @param {Object} list of events to add onto responder.
*/
var Responder = exports.TestAgent.Responder = function(events){
var Responder = exports.TestAgent.Responder = function Responder(events) {
this.events = {};
if(typeof(events) !== 'undefined'){
if (typeof(events) !== 'undefined') {
this.addEventListener(events);

@@ -24,7 +26,7 @@ }

*
* @param {String} command command name
* @param {Object} data object to be sent over the wire
* @return {String} json object
* @param {String} command command name.
* @param {Object} data object to be sent over the wire.
* @return {String} json object.
*/
Responder.stringify = function(command, data){
Responder.stringify = function stringify(command, data) {
return JSON.stringify([command, data]);

@@ -36,10 +38,10 @@ };

*
* @param {String} json json string to translate
* @return {Object} object where .data is json data and .command is command name.
* @param {String} json json string to translate.
* @return {Object} ex: { event: 'test', data: {} }.
*/
Responder.parse = function(json){
Responder.parse = function parse(json) {
var data;
try {
data = (json.forEach)? json : JSON.parse(json);
} catch(e){
data = (json.forEach) ? json : JSON.parse(json);
} catch (e) {
throw new Error("Could not parse json: '" + json + '"');

@@ -58,3 +60,2 @@ }

*
* @property events
* @type Object

@@ -67,7 +68,9 @@ */

*
* @param {String} json
* @param {Object} params... option number of params to pass to emit
* @return {Object} result of WebSocketCommon.parse
* @param {String|Object} json data object to respond to.
* @param {String} json.event event to emit.
* @param {Object} json.data data to emit with event.
* @param {Object} [params] option number of params to pass to emit.
* @return {Object} result of WebSocketCommon.parse.
*/
respond: function(json){
respond: function respond(json) {
var event = Responder.parse(json),

@@ -90,11 +93,11 @@ args = Array.prototype.slice.call(arguments).slice(1);

*
* @param {String} type event name
* @param {String} callback
* @param {String} type event name.
* @param {String} callback event callback.
*/
addEventListener: function(type, callback){
addEventListener: function addEventListener(type, callback) {
var event;
if(typeof(callback) === 'undefined' && typeof(type) === 'object'){
for(event in type){
if(type.hasOwnProperty(event)){
if (typeof(callback) === 'undefined' && typeof(type) === 'object') {
for (event in type) {
if (type.hasOwnProperty(event)) {
this.addEventListener(event, type[event]);

@@ -107,3 +110,3 @@ }

if(!(type in this.events)){
if (!(type in this.events)) {
this.events[type] = [];

@@ -123,6 +126,6 @@ }

*
* @param {String} eventName
* @param {Arg...}
* @param {String} eventName name of the event to emit.
* @param {Object} [arguments] additional arguments to pass.
*/
emit: function(){
emit: function emit() {
var args = Array.prototype.slice.call(arguments),

@@ -133,6 +136,6 @@ event = args.shift(),

if(event in this.events){
if (event in this.events) {
eventList = this.events[event];
eventList.forEach(function(callback){
eventList.forEach(function(callback) {
callback.apply(self, args);

@@ -149,6 +152,6 @@ });

*
* @param {String} event
* @param {String} event event type to remove.
*/
removeAllEventListeners: function(name){
if(name in this.events){
removeAllEventListeners: function removeAllEventListeners(name) {
if (name in this.events) {
//reuse array

@@ -166,9 +169,9 @@ this.events[name].length = 0;

*
* @param {String} eventName event name
* @param {Function} callback
* @param {String} eventName event name.
* @param {Function} callback same instance of event handler.
*/
removeEventListener: function(name, callback){
removeEventListener: function removeEventListener(name, callback) {
var i, length, events;
if(!(name in this.events)){
if (!(name in this.events)) {
return false;

@@ -179,4 +182,4 @@ }

for(i = 0, length = events.length; i < length; i++){
if(events[i] && events[i] === callback){
for (i = 0, length = events.length; i < length; i++) {
if (events[i] && events[i] === callback) {
events.splice(i, 1);

@@ -195,14 +198,14 @@ return true;

}(
(typeof(window) === 'undefined')? module.exports : window
(typeof(window) === 'undefined') ? module.exports : window
));
(function(window){
(function(window) {
'use strict';
if(typeof(window.TestAgent) === 'undefined'){
if (typeof(window.TestAgent) === 'undefined') {
window.TestAgent = {};
}
var Loader = window.TestAgent.Loader = function(options){
var Loader = window.TestAgent.Loader = function Loader(options) {
var key;

@@ -214,8 +217,8 @@

if(typeof(options) === 'undefined'){
if (typeof(options) === 'undefined') {
options = {};
}
for(key in options){
if(options.hasOwnProperty(key)){
for (key in options) {
if (options.hasOwnProperty(key)) {
this[key] = options[key];

@@ -232,3 +235,2 @@ }

* @type String
* @property prefix
*/

@@ -241,3 +243,2 @@ prefix: '',

* @type Boolean
* @property bustCache
*/

@@ -250,3 +251,2 @@ bustCache: true,

* @private
* @property targetWindow
* @type Window

@@ -259,3 +259,2 @@ */

*
* @property _cached
* @type Object

@@ -266,7 +265,7 @@ * @private

get targetWindow(){
get targetWindow() {
return this._targetWindow;
},
set targetWindow(value){
set targetWindow(value) {
this._targetWindow = value;

@@ -279,8 +278,8 @@ this._cached = {};

*/
_decrementPending: function(){
if(this.pending > 0){
_decrementPending: function _decrementPending() {
if (this.pending > 0) {
this.pending--;
}
if(this.pending <= 0){
if (this.pending <= 0) {
this._fireCallbacks();

@@ -290,5 +289,5 @@ }

_fireCallbacks: function(){
_fireCallbacks: function _fireCallbacks() {
var callback;
while((callback = this.doneCallbacks.shift())){
while ((callback = this.doneCallbacks.shift())) {
callback();

@@ -299,8 +298,8 @@ }

/**
* Adds a done callback
* Adds a done callback.
* You may call this function multiple times.
*
*
* @param {Function} callback
* @param {Function} callback called after all scripts are loaded.
*/
done: function(callback){
done: function done(callback) {
this.doneCallbacks.push(callback);

@@ -315,6 +314,6 @@ return this;

*
* @param {String} url
* @param {String} callback
* @param {String} url location to load script from.
* @param {String} callback callback when script loading is complete.
*/
require: function(url, callback){
require: function require(url, callback) {
var prefix = this.prefix,

@@ -326,3 +325,3 @@ suffix = '',

if(url in this._cached){
if (url in this._cached) {
//url is cached we are good

@@ -332,4 +331,5 @@ return;

if(this.bustCache){
suffix = '?time=' + String(Date.now()) + '&rand=' + String(Math.random() * 1000);
if (this.bustCache) {
suffix = '?time=' + String(Date.now()) +
'&rand=' + String(Math.random() * 1000);
}

@@ -346,4 +346,4 @@

element.type = 'text/javascript';
element.onload = function(){
if(callback){
element.onload = function scriptOnLoad() {
if (callback) {
callback();

@@ -362,11 +362,11 @@ }

}(this));
(function(window){
(function(window) {
'use strict';
if(typeof(window.TestAgent) === 'undefined'){
if (typeof(window.TestAgent) === 'undefined') {
window.TestAgent = {};
}
var Sandbox = window.TestAgent.Sandbox = function(url){
var Sandbox = window.TestAgent.Sandbox = function Sandbox(url) {
this.url = url;

@@ -380,3 +380,2 @@ };

/**
* @property ready
* @type Boolean

@@ -391,3 +390,3 @@ *

*
* @return String
* @type String
*/

@@ -400,7 +399,7 @@ url: null,

*
* @return DOMElement
* @type DOMElement
*/
getElement: function(){
getElement: function getElement() {
var iframe;
if(!this._element){
if (!this._element) {
iframe = this._element = window.document.createElement('iframe');

@@ -412,3 +411,3 @@ iframe.src = this.url + '?time=' + String(Date.now());

run: function(callback){
run: function run(callback) {
//cleanup old sandboxes

@@ -422,3 +421,3 @@ this.destroy();

window.document.body.appendChild(element);
element.contentWindow.addEventListener('DOMContentLoaded', function(){
element.contentWindow.addEventListener('DOMContentLoaded', function() {
self.ready = true;

@@ -429,6 +428,6 @@ callback.call(this);

destroy: function(){
destroy: function destroy() {
var el;
if(!this.ready){
if (!this.ready) {
return false;

@@ -447,4 +446,4 @@ }

getWindow: function(){
if(!this.ready){
getWindow: function getWindow() {
if (!this.ready) {
return false;

@@ -459,15 +458,15 @@ }

}(this));
(function(window){
(function(window) {
'use strict';
if(typeof(window.TestAgent) === 'undefined'){
if (typeof(window.TestAgent) === 'undefined') {
window.TestAgent = {};
}
var Server = window.TestAgent.Config = function(options){
var Server = window.TestAgent.Config = function Config(options) {
var key;
for(key in options){
if(options.hasOwnProperty(key)){
for (key in options) {
if (options.hasOwnProperty(key)) {
this[key] = options[key];

@@ -483,4 +482,2 @@ }

*
*
* @property url
* @type String

@@ -493,5 +490,3 @@ */

*
*
* @type Boolean
* @property ready
*/

@@ -503,3 +498,2 @@ ready: false,

*
* @property resources
* @type Array

@@ -512,8 +506,8 @@ */

*
* @param Object xhr xhr object
* @param {Object} xhr xhr object.
*/
_parseResponse: function(xhr){
_parseResponse: function _parseResponse(xhr) {
var response;
if(xhr.responseText){
if (xhr.responseText) {
response = JSON.parse(xhr.responseText);

@@ -533,3 +527,3 @@ //only return files for now...

*/
load: function(callback){
load: function load(callback) {
var xhr = new XMLHttpRequest(),

@@ -540,5 +534,5 @@ self = this,

xhr.open('GET', this.url, true);
xhr.onreadystatechange = function(){
if(xhr.readyState === 4){
if(xhr.status === 200 || xhr.status === 0){
xhr.onreadystatechange = function onReadyStateChange() {
if (xhr.readyState === 4) {
if (xhr.status === 200 || xhr.status === 0) {
response = self._parseResponse(xhr);

@@ -551,3 +545,3 @@

} else {
throw new Error('Could not fetch tests from "' + self.url + '"');
throw new Error('Could not fetch tests from "' + self.url + '"');
}

@@ -568,11 +562,13 @@ } else {

//depends on TestAgent.Responder
(function(exports){
if(typeof(exports.TestAgent) === 'undefined'){
(function(exports) {
'use strict';
if (typeof(exports.TestAgent) === 'undefined') {
exports.TestAgent = {};
}
var Native, Responder;
var Native, Responder, TestAgent;
//Hack Arounds for node
if(typeof(window) === 'undefined'){
if (typeof(window) === 'undefined') {
Native = require('ws');

@@ -582,2 +578,3 @@ Responder = require('./responder').TestAgent.Responder;

TestAgent = exports.TestAgent;
Responder = Responder || TestAgent.Responder;

@@ -588,3 +585,2 @@ Native = (Native || WebSocket || MozWebSocket);

/**

@@ -599,14 +595,13 @@ * Creates a websocket client handles custom

*
* - retry (false by default)
* - retries (current number of retries)
* - retryLimit ( number of retries before error is thrown Infinity by default)
* - retryTimeout ( Time between retries 3000ms by default)
*
*
* @param {Object} options
* @param {Object} options retry options.
* @param {Boolean} option.retry (false by default).
* @param {Numeric} option.retryLimit \
* ( number of retries before error is thrown Infinity by default).
* @param {Numeric} option.retryTimeout \
* ( Time between retries 3000ms by default).
*/
var Client = exports.TestAgent.WebsocketClient = function(options){
var Client = TestAgent.WebsocketClient = function WebsocketClient(options) {
var key;
for(key in options){
if(options.hasOwnProperty(key)){
for (key in options) {
if (options.hasOwnProperty(key)) {
this[key] = options[key];

@@ -617,2 +612,4 @@ }

this.proxyEvents = ['open', 'close', 'message'];
this.on('close', this._incrementRetry.bind(this));

@@ -623,3 +620,3 @@ this.on('message', this._processMessage.bind(this));

Client.RetryError = function(){
Client.RetryError = function RetryError() {
Error.apply(this, arguments);

@@ -633,4 +630,2 @@ };

Client.prototype.proxyEvents = ['open', 'close', 'message'];
//Retry

@@ -642,7 +637,9 @@ Client.prototype.retry = false;

Client.prototype.start = function(){
Client.prototype.start = function start() {
var i, event;
if(this.retry && this.retries >= this.retryLimit){
throw new Client.RetryError('Retry limit has been reach retried ' + String(this.retries) + ' times');
if (this.retry && this.retries >= this.retryLimit) {
throw new Client.RetryError(
'Retry limit has been reach retried ' + String(this.retries) + ' times'
);
}

@@ -652,3 +649,3 @@

for(i = 0; i < this.proxyEvents.length; i++){
for (i = 0; i < this.proxyEvents.length; i++) {
event = this.proxyEvents[i];

@@ -664,11 +661,11 @@ this.socket.addEventListener(event, this._proxyEvent.bind(this, event));

*
* @param {String} event
* @param {String} data
* @param {String} event event to send.
* @param {String} data object to send to the server.
*/
Client.prototype.send = function(event, data){
Client.prototype.send = function send(event, data) {
this.socket.send(this.stringify(event, data));
};
Client.prototype._incrementRetry = function(){
if(this.retry){
Client.prototype._incrementRetry = function _incrementRetry() {
if (this.retry) {
this.retries++;

@@ -679,4 +676,4 @@ setTimeout(this.start.bind(this), this.retryTimeout);

Client.prototype._processMessage = function(message){
if(message.data){
Client.prototype._processMessage = function _processMessage(message) {
if (message.data) {
message = message.data;

@@ -687,7 +684,7 @@ }

Client.prototype._clearRetries = function(){
Client.prototype._clearRetries = function _clearRetries() {
this.retries = 0;
};
Client.prototype._proxyEvent = function(){
Client.prototype._proxyEvent = function _proxyEvent() {
this.emit.apply(this, arguments);

@@ -697,29 +694,61 @@ };

}(
(typeof(window) === 'undefined')? module.exports : window
(typeof(window) === 'undefined') ? module.exports : window
));
(function(window){
if(typeof(window.TestAgent) === 'undefined'){
/*(The MIT License)
Copyright (c) 20011-2012 TJ Holowaychuk <tj@vision-media.ca>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
(function(window) {
'use strict';
if (typeof(window.TestAgent) === 'undefined') {
window.TestAgent = {};
}
if(typeof(window.TestAgent.Mocha) === 'undefined'){
if (typeof(window.TestAgent.Mocha) === 'undefined') {
window.TestAgent.Mocha = {};
}
Base.slow = 75;
//Credit: mocha - https://github.com/visionmedia/mocha/blob/master/lib/reporters/base.js#L194
//Credit: mocha -
//https://github.com/visionmedia/mocha/blob/master/lib/reporters/base.js#L194
function Base(runner) {
var self = this
, stats = this.stats = { suites: 0, tests: 0, passes: 0, pending: 0, failures: 0 }
, failures = this.failures = [];
var self = this,
stats,
failures = this.failures = [];
stats = this.stats = {
suites: 0, tests: 0, passes: 0, pending: 0, failures: 0
};
if (!runner) return;
this.runner = runner;
runner.on('start', function(){
runner.on('start', function onStart() {
stats.start = new Date;
});
runner.on('suite', function(suite){
runner.on('suite', function onSuite(suite) {
stats.suites = stats.suites || 0;

@@ -729,3 +758,3 @@ suite.root || stats.suites++;

runner.on('test end', function(test){
runner.on('test end', function onTestEnd(test) {
stats.tests = stats.tests || 0;

@@ -735,11 +764,11 @@ stats.tests++;

runner.on('pass', function(test){
runner.on('pass', function onPass(test) {
stats.passes = stats.passes || 0;
var medium = Base.slow / 2;
test.speed = test.duration > Base.slow
? 'slow'
: test.duration > medium
? 'medium'
: 'fast';
//reformatted for gjslint
test.speed =
(test.duration > Base.slow) ?
'slow' : test.duration > medium ?
'medium' : 'fast';

@@ -749,3 +778,3 @@ stats.passes++;

runner.on('fail', function(test, err){
runner.on('fail', function onFail(test, err) {
stats.failures = stats.failures || 0;

@@ -757,3 +786,3 @@ stats.failures++;

runner.on('end', function(){
runner.on('end', function onEnd() {
stats.end = new Date;

@@ -763,3 +792,3 @@ stats.duration = new Date - stats.start;

runner.on('pending', function(){
runner.on('pending', function onPending() {
stats.pending++;

@@ -772,9 +801,10 @@ });

}(this));
(function(window){
(function(window) {
'use strict';
if(typeof(window.TestAgent) === 'undefined'){
if (typeof(window.TestAgent) === 'undefined') {
window.TestAgent = {};
}
if(typeof(window.TestAgent.Mocha) === 'undefined'){
if (typeof(window.TestAgent.Mocha) === 'undefined') {
window.TestAgent.Mocha = {};

@@ -788,3 +818,3 @@ }

MochaReporter.console = window.console;
MochaReporter.send = function(){};
MochaReporter.send = function mochaReporterSend() {};

@@ -803,3 +833,4 @@ //TODO -- Buffer console.log calls

MochaReporter.console.log = function(){
MochaReporter.console.log = function consoleLogShim() {
var args = Array.prototype.slice.call(arguments);
//real console log

@@ -810,7 +841,7 @@ log.apply(this, arguments);

var stack, messages = Array.prototype.slice.call(arguments).map(function(item){
if(!item){
var stack, messages = args.map(function(item) {
if (!item) {
return item;
}
return (item.toString)? item.toString() : item;
return (item.toString) ? item.toString() : item;
});

@@ -820,3 +851,3 @@

throw new Error();
} catch (e){
} catch (e) {
stack = e.stack;

@@ -826,3 +857,3 @@ }

//re-orgnaize the stack to exlude the above
stack = stack.split("\n").map(function(e){
stack = stack.split('\n').map(function(e) {
return e.trim().replace(/^at /, '');

@@ -832,39 +863,53 @@ });

stack.splice(0, 1);
stack = stack.join("\n");
stack = stack.join('\n');
//this is temp
MochaReporter.send(JSON.stringify(['log', {messages: messages, stack: stack}]));
MochaReporter.send(
JSON.stringify(['log', {messages: messages, stack: stack}])
);
};
runner.on('suite', function(suite){
runner.on('suite', function onSuite(suite) {
indentation++;
MochaReporter.send(JSON.stringify(['suite', jsonExport(suite, { indentation: indentation }) ]));
MochaReporter.send(
JSON.stringify(
['suite', jsonExport(suite, { indentation: indentation })]
)
);
});
runner.on('suite end', function(suite){
MochaReporter.send(JSON.stringify(['suite end', jsonExport(suite, { indentation: indentation }) ]));
runner.on('suite end', function onSuiteEnd(suite) {
MochaReporter.send(
JSON.stringify(
['suite end', jsonExport(suite, { indentation: indentation })]
)
);
indentation--;
});
runner.on('test', function(test){
MochaReporter.send(JSON.stringify(['test', jsonExport(test) ]));
runner.on('test', function onTest(test) {
MochaReporter.send(JSON.stringify(['test', jsonExport(test)]));
});
runner.on('test end', function(test){
MochaReporter.send(JSON.stringify(['test end', jsonExport(test) ]));
runner.on('test end', function onTestEnd(test) {
MochaReporter.send(JSON.stringify(['test end', jsonExport(test)]));
});
runner.on('start', function(){
MochaReporter.send( JSON.stringify(['start', { total: total }]) );
runner.on('start', function onStart() {
MochaReporter.send(JSON.stringify(['start', { total: total }]));
});
runner.on('pass', function(test){
runner.on('pass', function onPass(test) {
MochaReporter.send(JSON.stringify(['pass', jsonExport(test)]));
});
runner.on('fail', function(test, err){
MochaReporter.send(JSON.stringify(['fail', jsonExport(test, {err: jsonErrorExport(err) })]));
runner.on('fail', function onFail(test, err) {
MochaReporter.send(
JSON.stringify(
['fail', jsonExport(test, {err: jsonErrorExport(err) })]
)
);
});
runner.on('end', function(){
runner.on('end', function onEnd() {
MochaReporter.send(JSON.stringify(['end', self.stats]));

@@ -883,3 +928,3 @@ });

function jsonErrorExport(err){
function jsonErrorExport(err) {
var result = {};

@@ -900,8 +945,8 @@

exportKeys.forEach(function(key){
exportKeys.forEach(function(key) {
var value;
if(key in object){
if (key in object) {
value = object[key];
if(typeof(value) === 'function'){
if (typeof(value) === 'function') {
result[key] = object[key]();

@@ -914,5 +959,5 @@ } else {

if(typeof(additional) !== 'undefined'){
for(key in additional){
if(additional.hasOwnProperty(key)){
if (typeof(additional) !== 'undefined') {
for (key in additional) {
if (additional.hasOwnProperty(key)) {
result[key] = additional[key];

@@ -930,28 +975,34 @@ }

(function(window){
(function(window) {
'use strict';
if(typeof(window.TestAgent) === 'undefined'){
if (typeof(window.TestAgent) === 'undefined') {
window.TestAgent = {};
}
TestAgent.BrowserWorker = function(options){
TestAgent.BrowserWorker = function BrowserWorker(options) {
var self = this,
dep = this.deps;
if(typeof(options) === 'undefined'){
if (typeof(options) === 'undefined') {
options = {};
}
this.deps.Server.call(
this,
options.server || this.defaults.server
);
function option(name) {
if (name in options) {
return options[name];
}
this.sandbox = new this.deps.Sandbox(
options.sandbox || this.defaults.sandbox
);
if (name in self.defaults) {
return self.defaults[name];
}
this.loader = new this.deps.Loader(
options.loader || this.defaults.loader
);
return undefined;
}
this.deps.Server.call(this, option('server'));
this.sandbox = new dep.Sandbox(option('sandbox'));
this.loader = new dep.Loader(option('loader'));
this._testsProcessor = [];

@@ -963,3 +1014,3 @@ this.testRunner = options.testRunner;

TestAgent.BrowserWorker.prototype = Object.create(
TestAgent.WebsocketClient.prototype
TestAgent.WebsocketClient.prototype
);

@@ -987,10 +1038,10 @@

*
* @param {Function} callback
* @param {Function} callback executed when sandbox is created.
*/
proto.createSandbox = function(callback){
proto.createSandbox = function createSandbox(callback) {
var self = this;
this.sandbox.run(function(){
this.sandbox.run(function onSandboxRun() {
self.loader.targetWindow = this;
if(callback){
if(!('require' in this)){
if (callback) {
if (!('require' in this)) {
this.require = self.loader.require.bind(self.loader);

@@ -1004,3 +1055,3 @@ }

proto._emitTestComplete = function(){
proto._emitTestComplete = function _emitTestComplete() {
var args = Array.prototype.slice.call(arguments);

@@ -1019,6 +1070,6 @@ args.unshift('run tests complete');

*
* @param {Function} callback
* @chainable
* @param {Function} callback reducer function.
* @return {Object} self.
*/
proto.addTestsProcessor = function(callback){
proto.addTestsProcessor = function addTestsProcessor(callback) {
this._testsProcessor.push(callback);

@@ -1032,5 +1083,5 @@ };

*
* @param {Array} tests
* @param {Array} tests list of tests to process.
*/
proto._processTests = function(tests){
proto._processTests = function _processTests(tests) {
var result = tests,

@@ -1041,3 +1092,3 @@ reducers = this._testsProcessor,

for(; i < length; i++){
for (; i < length; i++) {
result = reducers[i](result);

@@ -1052,13 +1103,13 @@ }

*
* @param {Array} tests
* @param {Array} tests list of tests to execute.
*/
proto.runTests = function(tests){
proto.runTests = function runTests(tests) {
var self = this,
done = this._emitTestComplete.bind(this);
if(!this.testRunner){
throw new Error("Worker must be provided a .testRunner method");
if (!this.testRunner) {
throw new Error('Worker must be provided a .testRunner method');
}
this.createSandbox(function(){
this.createSandbox(function createSandbox() {
self.testRunner(self, self._processTests(tests), done);

@@ -1072,3 +1123,3 @@ });

* Enhancement = function(options){}
* Enhancement.prototype.enhance = function(server){
* Enhancement.prototype.enhance = function enhance(server){
* //do stuff

@@ -1081,7 +1132,7 @@ * }

*
* @param {Object} enhancement
* @param {Object} options
* @chainable
* @param {Object} enhancement enhancement class.
* @param {Object} options options for class.
* @return {Object} self.
*/
proto.use = function(enhancement, options){
proto.use = function use(enhancement, options) {
new enhancement(options).enhance(this);

@@ -1093,12 +1144,14 @@

}(this));
(function(window){
function MochaDriver (options) {
(function(window) {
'use strict';
function MochaDriver(options) {
var key;
if(typeof(options) === 'undefined'){
if (typeof(options) === 'undefined') {
options = {};
}
for(key in options){
if(options.hasOwnProperty(key)){
for (key in options) {
if (options.hasOwnProperty(key)) {
this[key] = options[key];

@@ -1109,7 +1162,7 @@ }

MochaDriver.createMutliReporter = function(){
MochaDriver.createMutliReporter = function createMultiReporter() {
var reporters = Array.prototype.slice.call(arguments);
return function(runner){
reporters.forEach(function(Report){
return function(runner) {
reporters.forEach(function(Report) {
new Report(runner);

@@ -1125,3 +1178,3 @@ });

enhance: function(worker){
enhance: function enhance(worker) {
this.worker = worker;

@@ -1132,7 +1185,7 @@ worker.testRunner = this._testRunner.bind(this);

_onRunTests: function(data){
_onRunTests: function _onRunTests(data) {
this.worker.runTests(data.tests || []);
},
getReporter: function(box){
getReporter: function getReporter(box) {
var stream = TestAgent.Mocha.JsonStreamReporter,

@@ -1143,3 +1196,3 @@ self = this;

stream.send = function(line){
stream.send = function send(line) {
self.worker.send('test data', line);

@@ -1154,11 +1207,11 @@ };

_testRunner: function(worker, tests, done){
_testRunner: function _testRunner(worker, tests, done) {
var box = worker.sandbox.getWindow(),
self = this;
worker.loader.done(function(){
worker.loader.done(function onDone() {
box.mocha.run(done);
});
box.require(this.mochaUrl, function(){
box.require(this.mochaUrl, function onRequireMocha() {
//setup mocha

@@ -1173,3 +1226,3 @@ box.mocha.setup({

tests.forEach(function(test){
tests.forEach(function(test) {
box.require(test);

@@ -1184,10 +1237,10 @@ });

}(this));
(function(window){
(function(window) {
'use strict';
var Worker = window.TestAgent.BrowserWorker;
Worker.Config = function(options){
if(typeof(options) === 'undefined'){
Worker.Config = function Config(options) {
if (typeof(options) === 'undefined') {
options = {};

@@ -1200,10 +1253,10 @@ }

Worker.Config.prototype = {
enhance: function(worker){
enhance: function enhance(worker) {
worker.config = this._config.bind(this, worker, this.config);
},
_config: function(worker, config, callback){
config.load(function(data){
_config: function _config(worker, config, callback) {
config.load(function(data) {
worker.emit('config', data);
if(callback){
if (callback) {
callback(data);

@@ -1217,7 +1270,9 @@ }

}(this));
(function(window){
(function(window) {
'use strict';
var FORMAT_REGEX = /%([0-9])?s/g;
var FORMAT_REGEX = /%([0-9])?s/g,
Worker = window.TestAgent.BrowserWorker;
function format(){
function format() {
var i = 0,

@@ -1230,3 +1285,3 @@ str,

result = str.replace(FORMAT_REGEX, function(match, pos){
result = str.replace(FORMAT_REGEX, function(match, pos) {
var index = parseInt(pos || i++, 10);

@@ -1239,3 +1294,3 @@ return args[index];

function fragment(){
function fragment() {
var string = format.apply(this, arguments),

@@ -1248,6 +1303,6 @@ element = document.createElement('div');

var TestUi = window.TestAgent.BrowserWorker.TestUi = function(options){
var TestUi = Worker.TestUi = function TestUi(options) {
var selector;
if(typeof(options) === 'undefined'){
if (typeof(options) === 'undefined') {
options = {};

@@ -1269,3 +1324,3 @@ }

enhance: function(worker){
enhance: function enhance(worker) {
this.worker = worker;

@@ -1275,3 +1330,3 @@ this.worker.on('config', this.onConfig.bind(this));

onConfig: function(data){
onConfig: function onConfig(data) {
//purge elements

@@ -1284,3 +1339,3 @@ var elements = this.element.getElementsByTagName('*'),

for(; i < elements.length; i++){
for (; i < elements.length; i++) {
element = elements[i];

@@ -1292,3 +1347,3 @@ element.parentNode.removeChild(element);

data.tests.forEach(function(test){
data.tests.forEach(function(test) {
parent.appendChild(fragment(

@@ -1310,3 +1365,3 @@ templates.testItem,

initDomEvents: function(){
initDomEvents: function initDomEvents() {
var ul = this.element.querySelector('ul'),

@@ -1317,8 +1372,8 @@ button = this.element.querySelector('button'),

ul.addEventListener('click', function(e){
ul.addEventListener('click', function(e) {
var target = e.target,
url = target.getAttribute('data-url');
if(url){
if(self.queue[url]){
if (url) {
if (self.queue[url]) {
target.className = target.className.replace(activeClass, '');

@@ -1333,7 +1388,7 @@ delete self.queue[url];

button.addEventListener('click', function(){
button.addEventListener('click', function onTestClick() {
var tests = [], key;
for(key in self.queue){
if(self.queue.hasOwnProperty(key)){
for (key in self.queue) {
if (self.queue.hasOwnProperty(key)) {
tests.push(key);

@@ -1340,0 +1395,0 @@ }

@@ -12,3 +12,3 @@ (function(window){

worker.use(TestAgent.BrowserWorker.MochaDriver, {
mochaUrl: '/vendor/mocha/mocha.js',
mochaUrl: '/mocha/mocha.js',
testHelperUrl: '/test/helper.js'

@@ -15,0 +15,0 @@ });

@@ -1,3 +0,5 @@

(function(exports){
if(typeof(exports.TestAgent) === 'undefined'){
(function(exports) {
'use strict';
if (typeof(exports.TestAgent) === 'undefined') {
exports.TestAgent = {};

@@ -9,8 +11,8 @@ }

*
* @param {Object} list of events to add onto responder
* @param {Object} list of events to add onto responder.
*/
var Responder = exports.TestAgent.Responder = function(events){
var Responder = exports.TestAgent.Responder = function Responder(events) {
this.events = {};
if(typeof(events) !== 'undefined'){
if (typeof(events) !== 'undefined') {
this.addEventListener(events);

@@ -24,7 +26,7 @@ }

*
* @param {String} command command name
* @param {Object} data object to be sent over the wire
* @return {String} json object
* @param {String} command command name.
* @param {Object} data object to be sent over the wire.
* @return {String} json object.
*/
Responder.stringify = function(command, data){
Responder.stringify = function stringify(command, data) {
return JSON.stringify([command, data]);

@@ -36,10 +38,10 @@ };

*
* @param {String} json json string to translate
* @return {Object} object where .data is json data and .command is command name.
* @param {String} json json string to translate.
* @return {Object} ex: { event: 'test', data: {} }.
*/
Responder.parse = function(json){
Responder.parse = function parse(json) {
var data;
try {
data = (json.forEach)? json : JSON.parse(json);
} catch(e){
data = (json.forEach) ? json : JSON.parse(json);
} catch (e) {
throw new Error("Could not parse json: '" + json + '"');

@@ -58,3 +60,2 @@ }

*
* @property events
* @type Object

@@ -67,7 +68,9 @@ */

*
* @param {String} json
* @param {Object} params... option number of params to pass to emit
* @return {Object} result of WebSocketCommon.parse
* @param {String|Object} json data object to respond to.
* @param {String} json.event event to emit.
* @param {Object} json.data data to emit with event.
* @param {Object} [params] option number of params to pass to emit.
* @return {Object} result of WebSocketCommon.parse.
*/
respond: function(json){
respond: function respond(json) {
var event = Responder.parse(json),

@@ -90,11 +93,11 @@ args = Array.prototype.slice.call(arguments).slice(1);

*
* @param {String} type event name
* @param {String} callback
* @param {String} type event name.
* @param {String} callback event callback.
*/
addEventListener: function(type, callback){
addEventListener: function addEventListener(type, callback) {
var event;
if(typeof(callback) === 'undefined' && typeof(type) === 'object'){
for(event in type){
if(type.hasOwnProperty(event)){
if (typeof(callback) === 'undefined' && typeof(type) === 'object') {
for (event in type) {
if (type.hasOwnProperty(event)) {
this.addEventListener(event, type[event]);

@@ -107,3 +110,3 @@ }

if(!(type in this.events)){
if (!(type in this.events)) {
this.events[type] = [];

@@ -123,6 +126,6 @@ }

*
* @param {String} eventName
* @param {Arg...}
* @param {String} eventName name of the event to emit.
* @param {Object} [arguments] additional arguments to pass.
*/
emit: function(){
emit: function emit() {
var args = Array.prototype.slice.call(arguments),

@@ -133,6 +136,6 @@ event = args.shift(),

if(event in this.events){
if (event in this.events) {
eventList = this.events[event];
eventList.forEach(function(callback){
eventList.forEach(function(callback) {
callback.apply(self, args);

@@ -149,6 +152,6 @@ });

*
* @param {String} event
* @param {String} event event type to remove.
*/
removeAllEventListeners: function(name){
if(name in this.events){
removeAllEventListeners: function removeAllEventListeners(name) {
if (name in this.events) {
//reuse array

@@ -166,9 +169,9 @@ this.events[name].length = 0;

*
* @param {String} eventName event name
* @param {Function} callback
* @param {String} eventName event name.
* @param {Function} callback same instance of event handler.
*/
removeEventListener: function(name, callback){
removeEventListener: function removeEventListener(name, callback) {
var i, length, events;
if(!(name in this.events)){
if (!(name in this.events)) {
return false;

@@ -179,4 +182,4 @@ }

for(i = 0, length = events.length; i < length; i++){
if(events[i] && events[i] === callback){
for (i = 0, length = events.length; i < length; i++) {
if (events[i] && events[i] === callback) {
events.splice(i, 1);

@@ -195,14 +198,14 @@ return true;

}(
(typeof(window) === 'undefined')? module.exports : window
(typeof(window) === 'undefined') ? module.exports : window
));
(function(window){
(function(window) {
'use strict';
if(typeof(window.TestAgent) === 'undefined'){
if (typeof(window.TestAgent) === 'undefined') {
window.TestAgent = {};
}
var Loader = window.TestAgent.Loader = function(options){
var Loader = window.TestAgent.Loader = function Loader(options) {
var key;

@@ -214,8 +217,8 @@

if(typeof(options) === 'undefined'){
if (typeof(options) === 'undefined') {
options = {};
}
for(key in options){
if(options.hasOwnProperty(key)){
for (key in options) {
if (options.hasOwnProperty(key)) {
this[key] = options[key];

@@ -232,3 +235,2 @@ }

* @type String
* @property prefix
*/

@@ -241,3 +243,2 @@ prefix: '',

* @type Boolean
* @property bustCache
*/

@@ -250,3 +251,2 @@ bustCache: true,

* @private
* @property targetWindow
* @type Window

@@ -259,3 +259,2 @@ */

*
* @property _cached
* @type Object

@@ -266,7 +265,7 @@ * @private

get targetWindow(){
get targetWindow() {
return this._targetWindow;
},
set targetWindow(value){
set targetWindow(value) {
this._targetWindow = value;

@@ -279,8 +278,8 @@ this._cached = {};

*/
_decrementPending: function(){
if(this.pending > 0){
_decrementPending: function _decrementPending() {
if (this.pending > 0) {
this.pending--;
}
if(this.pending <= 0){
if (this.pending <= 0) {
this._fireCallbacks();

@@ -290,5 +289,5 @@ }

_fireCallbacks: function(){
_fireCallbacks: function _fireCallbacks() {
var callback;
while((callback = this.doneCallbacks.shift())){
while ((callback = this.doneCallbacks.shift())) {
callback();

@@ -299,8 +298,8 @@ }

/**
* Adds a done callback
* Adds a done callback.
* You may call this function multiple times.
*
*
* @param {Function} callback
* @param {Function} callback called after all scripts are loaded.
*/
done: function(callback){
done: function done(callback) {
this.doneCallbacks.push(callback);

@@ -315,6 +314,6 @@ return this;

*
* @param {String} url
* @param {String} callback
* @param {String} url location to load script from.
* @param {String} callback callback when script loading is complete.
*/
require: function(url, callback){
require: function require(url, callback) {
var prefix = this.prefix,

@@ -326,3 +325,3 @@ suffix = '',

if(url in this._cached){
if (url in this._cached) {
//url is cached we are good

@@ -332,4 +331,5 @@ return;

if(this.bustCache){
suffix = '?time=' + String(Date.now()) + '&rand=' + String(Math.random() * 1000);
if (this.bustCache) {
suffix = '?time=' + String(Date.now()) +
'&rand=' + String(Math.random() * 1000);
}

@@ -346,4 +346,4 @@

element.type = 'text/javascript';
element.onload = function(){
if(callback){
element.onload = function scriptOnLoad() {
if (callback) {
callback();

@@ -362,11 +362,11 @@ }

}(this));
(function(window){
(function(window) {
'use strict';
if(typeof(window.TestAgent) === 'undefined'){
if (typeof(window.TestAgent) === 'undefined') {
window.TestAgent = {};
}
var Sandbox = window.TestAgent.Sandbox = function(url){
var Sandbox = window.TestAgent.Sandbox = function Sandbox(url) {
this.url = url;

@@ -380,3 +380,2 @@ };

/**
* @property ready
* @type Boolean

@@ -391,3 +390,3 @@ *

*
* @return String
* @type String
*/

@@ -400,7 +399,7 @@ url: null,

*
* @return DOMElement
* @type DOMElement
*/
getElement: function(){
getElement: function getElement() {
var iframe;
if(!this._element){
if (!this._element) {
iframe = this._element = window.document.createElement('iframe');

@@ -412,3 +411,3 @@ iframe.src = this.url + '?time=' + String(Date.now());

run: function(callback){
run: function run(callback) {
//cleanup old sandboxes

@@ -422,3 +421,3 @@ this.destroy();

window.document.body.appendChild(element);
element.contentWindow.addEventListener('DOMContentLoaded', function(){
element.contentWindow.addEventListener('DOMContentLoaded', function() {
self.ready = true;

@@ -429,6 +428,6 @@ callback.call(this);

destroy: function(){
destroy: function destroy() {
var el;
if(!this.ready){
if (!this.ready) {
return false;

@@ -447,4 +446,4 @@ }

getWindow: function(){
if(!this.ready){
getWindow: function getWindow() {
if (!this.ready) {
return false;

@@ -459,15 +458,15 @@ }

}(this));
(function(window){
(function(window) {
'use strict';
if(typeof(window.TestAgent) === 'undefined'){
if (typeof(window.TestAgent) === 'undefined') {
window.TestAgent = {};
}
var Server = window.TestAgent.Config = function(options){
var Server = window.TestAgent.Config = function Config(options) {
var key;
for(key in options){
if(options.hasOwnProperty(key)){
for (key in options) {
if (options.hasOwnProperty(key)) {
this[key] = options[key];

@@ -483,4 +482,2 @@ }

*
*
* @property url
* @type String

@@ -493,5 +490,3 @@ */

*
*
* @type Boolean
* @property ready
*/

@@ -503,3 +498,2 @@ ready: false,

*
* @property resources
* @type Array

@@ -512,8 +506,8 @@ */

*
* @param Object xhr xhr object
* @param {Object} xhr xhr object.
*/
_parseResponse: function(xhr){
_parseResponse: function _parseResponse(xhr) {
var response;
if(xhr.responseText){
if (xhr.responseText) {
response = JSON.parse(xhr.responseText);

@@ -533,3 +527,3 @@ //only return files for now...

*/
load: function(callback){
load: function load(callback) {
var xhr = new XMLHttpRequest(),

@@ -540,5 +534,5 @@ self = this,

xhr.open('GET', this.url, true);
xhr.onreadystatechange = function(){
if(xhr.readyState === 4){
if(xhr.status === 200 || xhr.status === 0){
xhr.onreadystatechange = function onReadyStateChange() {
if (xhr.readyState === 4) {
if (xhr.status === 200 || xhr.status === 0) {
response = self._parseResponse(xhr);

@@ -551,3 +545,3 @@

} else {
throw new Error('Could not fetch tests from "' + self.url + '"');
throw new Error('Could not fetch tests from "' + self.url + '"');
}

@@ -568,11 +562,13 @@ } else {

//depends on TestAgent.Responder
(function(exports){
if(typeof(exports.TestAgent) === 'undefined'){
(function(exports) {
'use strict';
if (typeof(exports.TestAgent) === 'undefined') {
exports.TestAgent = {};
}
var Native, Responder;
var Native, Responder, TestAgent;
//Hack Arounds for node
if(typeof(window) === 'undefined'){
if (typeof(window) === 'undefined') {
Native = require('ws');

@@ -582,2 +578,3 @@ Responder = require('./responder').TestAgent.Responder;

TestAgent = exports.TestAgent;
Responder = Responder || TestAgent.Responder;

@@ -588,3 +585,2 @@ Native = (Native || WebSocket || MozWebSocket);

/**

@@ -599,14 +595,13 @@ * Creates a websocket client handles custom

*
* - retry (false by default)
* - retries (current number of retries)
* - retryLimit ( number of retries before error is thrown Infinity by default)
* - retryTimeout ( Time between retries 3000ms by default)
*
*
* @param {Object} options
* @param {Object} options retry options.
* @param {Boolean} option.retry (false by default).
* @param {Numeric} option.retryLimit \
* ( number of retries before error is thrown Infinity by default).
* @param {Numeric} option.retryTimeout \
* ( Time between retries 3000ms by default).
*/
var Client = exports.TestAgent.WebsocketClient = function(options){
var Client = TestAgent.WebsocketClient = function WebsocketClient(options) {
var key;
for(key in options){
if(options.hasOwnProperty(key)){
for (key in options) {
if (options.hasOwnProperty(key)) {
this[key] = options[key];

@@ -617,2 +612,4 @@ }

this.proxyEvents = ['open', 'close', 'message'];
this.on('close', this._incrementRetry.bind(this));

@@ -623,3 +620,3 @@ this.on('message', this._processMessage.bind(this));

Client.RetryError = function(){
Client.RetryError = function RetryError() {
Error.apply(this, arguments);

@@ -633,4 +630,2 @@ };

Client.prototype.proxyEvents = ['open', 'close', 'message'];
//Retry

@@ -642,7 +637,9 @@ Client.prototype.retry = false;

Client.prototype.start = function(){
Client.prototype.start = function start() {
var i, event;
if(this.retry && this.retries >= this.retryLimit){
throw new Client.RetryError('Retry limit has been reach retried ' + String(this.retries) + ' times');
if (this.retry && this.retries >= this.retryLimit) {
throw new Client.RetryError(
'Retry limit has been reach retried ' + String(this.retries) + ' times'
);
}

@@ -652,3 +649,3 @@

for(i = 0; i < this.proxyEvents.length; i++){
for (i = 0; i < this.proxyEvents.length; i++) {
event = this.proxyEvents[i];

@@ -664,11 +661,11 @@ this.socket.addEventListener(event, this._proxyEvent.bind(this, event));

*
* @param {String} event
* @param {String} data
* @param {String} event event to send.
* @param {String} data object to send to the server.
*/
Client.prototype.send = function(event, data){
Client.prototype.send = function send(event, data) {
this.socket.send(this.stringify(event, data));
};
Client.prototype._incrementRetry = function(){
if(this.retry){
Client.prototype._incrementRetry = function _incrementRetry() {
if (this.retry) {
this.retries++;

@@ -679,4 +676,4 @@ setTimeout(this.start.bind(this), this.retryTimeout);

Client.prototype._processMessage = function(message){
if(message.data){
Client.prototype._processMessage = function _processMessage(message) {
if (message.data) {
message = message.data;

@@ -687,7 +684,7 @@ }

Client.prototype._clearRetries = function(){
Client.prototype._clearRetries = function _clearRetries() {
this.retries = 0;
};
Client.prototype._proxyEvent = function(){
Client.prototype._proxyEvent = function _proxyEvent() {
this.emit.apply(this, arguments);

@@ -697,29 +694,61 @@ };

}(
(typeof(window) === 'undefined')? module.exports : window
(typeof(window) === 'undefined') ? module.exports : window
));
(function(window){
if(typeof(window.TestAgent) === 'undefined'){
/*(The MIT License)
Copyright (c) 20011-2012 TJ Holowaychuk <tj@vision-media.ca>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
(function(window) {
'use strict';
if (typeof(window.TestAgent) === 'undefined') {
window.TestAgent = {};
}
if(typeof(window.TestAgent.Mocha) === 'undefined'){
if (typeof(window.TestAgent.Mocha) === 'undefined') {
window.TestAgent.Mocha = {};
}
Base.slow = 75;
//Credit: mocha - https://github.com/visionmedia/mocha/blob/master/lib/reporters/base.js#L194
//Credit: mocha -
//https://github.com/visionmedia/mocha/blob/master/lib/reporters/base.js#L194
function Base(runner) {
var self = this
, stats = this.stats = { suites: 0, tests: 0, passes: 0, pending: 0, failures: 0 }
, failures = this.failures = [];
var self = this,
stats,
failures = this.failures = [];
stats = this.stats = {
suites: 0, tests: 0, passes: 0, pending: 0, failures: 0
};
if (!runner) return;
this.runner = runner;
runner.on('start', function(){
runner.on('start', function onStart() {
stats.start = new Date;
});
runner.on('suite', function(suite){
runner.on('suite', function onSuite(suite) {
stats.suites = stats.suites || 0;

@@ -729,3 +758,3 @@ suite.root || stats.suites++;

runner.on('test end', function(test){
runner.on('test end', function onTestEnd(test) {
stats.tests = stats.tests || 0;

@@ -735,11 +764,11 @@ stats.tests++;

runner.on('pass', function(test){
runner.on('pass', function onPass(test) {
stats.passes = stats.passes || 0;
var medium = Base.slow / 2;
test.speed = test.duration > Base.slow
? 'slow'
: test.duration > medium
? 'medium'
: 'fast';
//reformatted for gjslint
test.speed =
(test.duration > Base.slow) ?
'slow' : test.duration > medium ?
'medium' : 'fast';

@@ -749,3 +778,3 @@ stats.passes++;

runner.on('fail', function(test, err){
runner.on('fail', function onFail(test, err) {
stats.failures = stats.failures || 0;

@@ -757,3 +786,3 @@ stats.failures++;

runner.on('end', function(){
runner.on('end', function onEnd() {
stats.end = new Date;

@@ -763,3 +792,3 @@ stats.duration = new Date - stats.start;

runner.on('pending', function(){
runner.on('pending', function onPending() {
stats.pending++;

@@ -772,9 +801,10 @@ });

}(this));
(function(window){
(function(window) {
'use strict';
if(typeof(window.TestAgent) === 'undefined'){
if (typeof(window.TestAgent) === 'undefined') {
window.TestAgent = {};
}
if(typeof(window.TestAgent.Mocha) === 'undefined'){
if (typeof(window.TestAgent.Mocha) === 'undefined') {
window.TestAgent.Mocha = {};

@@ -788,3 +818,3 @@ }

MochaReporter.console = window.console;
MochaReporter.send = function(){};
MochaReporter.send = function mochaReporterSend() {};

@@ -803,3 +833,4 @@ //TODO -- Buffer console.log calls

MochaReporter.console.log = function(){
MochaReporter.console.log = function consoleLogShim() {
var args = Array.prototype.slice.call(arguments);
//real console log

@@ -810,7 +841,7 @@ log.apply(this, arguments);

var stack, messages = Array.prototype.slice.call(arguments).map(function(item){
if(!item){
var stack, messages = args.map(function(item) {
if (!item) {
return item;
}
return (item.toString)? item.toString() : item;
return (item.toString) ? item.toString() : item;
});

@@ -820,3 +851,3 @@

throw new Error();
} catch (e){
} catch (e) {
stack = e.stack;

@@ -826,3 +857,3 @@ }

//re-orgnaize the stack to exlude the above
stack = stack.split("\n").map(function(e){
stack = stack.split('\n').map(function(e) {
return e.trim().replace(/^at /, '');

@@ -832,39 +863,53 @@ });

stack.splice(0, 1);
stack = stack.join("\n");
stack = stack.join('\n');
//this is temp
MochaReporter.send(JSON.stringify(['log', {messages: messages, stack: stack}]));
MochaReporter.send(
JSON.stringify(['log', {messages: messages, stack: stack}])
);
};
runner.on('suite', function(suite){
runner.on('suite', function onSuite(suite) {
indentation++;
MochaReporter.send(JSON.stringify(['suite', jsonExport(suite, { indentation: indentation }) ]));
MochaReporter.send(
JSON.stringify(
['suite', jsonExport(suite, { indentation: indentation })]
)
);
});
runner.on('suite end', function(suite){
MochaReporter.send(JSON.stringify(['suite end', jsonExport(suite, { indentation: indentation }) ]));
runner.on('suite end', function onSuiteEnd(suite) {
MochaReporter.send(
JSON.stringify(
['suite end', jsonExport(suite, { indentation: indentation })]
)
);
indentation--;
});
runner.on('test', function(test){
MochaReporter.send(JSON.stringify(['test', jsonExport(test) ]));
runner.on('test', function onTest(test) {
MochaReporter.send(JSON.stringify(['test', jsonExport(test)]));
});
runner.on('test end', function(test){
MochaReporter.send(JSON.stringify(['test end', jsonExport(test) ]));
runner.on('test end', function onTestEnd(test) {
MochaReporter.send(JSON.stringify(['test end', jsonExport(test)]));
});
runner.on('start', function(){
MochaReporter.send( JSON.stringify(['start', { total: total }]) );
runner.on('start', function onStart() {
MochaReporter.send(JSON.stringify(['start', { total: total }]));
});
runner.on('pass', function(test){
runner.on('pass', function onPass(test) {
MochaReporter.send(JSON.stringify(['pass', jsonExport(test)]));
});
runner.on('fail', function(test, err){
MochaReporter.send(JSON.stringify(['fail', jsonExport(test, {err: jsonErrorExport(err) })]));
runner.on('fail', function onFail(test, err) {
MochaReporter.send(
JSON.stringify(
['fail', jsonExport(test, {err: jsonErrorExport(err) })]
)
);
});
runner.on('end', function(){
runner.on('end', function onEnd() {
MochaReporter.send(JSON.stringify(['end', self.stats]));

@@ -883,3 +928,3 @@ });

function jsonErrorExport(err){
function jsonErrorExport(err) {
var result = {};

@@ -900,8 +945,8 @@

exportKeys.forEach(function(key){
exportKeys.forEach(function(key) {
var value;
if(key in object){
if (key in object) {
value = object[key];
if(typeof(value) === 'function'){
if (typeof(value) === 'function') {
result[key] = object[key]();

@@ -914,5 +959,5 @@ } else {

if(typeof(additional) !== 'undefined'){
for(key in additional){
if(additional.hasOwnProperty(key)){
if (typeof(additional) !== 'undefined') {
for (key in additional) {
if (additional.hasOwnProperty(key)) {
result[key] = additional[key];

@@ -930,28 +975,34 @@ }

(function(window){
(function(window) {
'use strict';
if(typeof(window.TestAgent) === 'undefined'){
if (typeof(window.TestAgent) === 'undefined') {
window.TestAgent = {};
}
TestAgent.BrowserWorker = function(options){
TestAgent.BrowserWorker = function BrowserWorker(options) {
var self = this,
dep = this.deps;
if(typeof(options) === 'undefined'){
if (typeof(options) === 'undefined') {
options = {};
}
this.deps.Server.call(
this,
options.server || this.defaults.server
);
function option(name) {
if (name in options) {
return options[name];
}
this.sandbox = new this.deps.Sandbox(
options.sandbox || this.defaults.sandbox
);
if (name in self.defaults) {
return self.defaults[name];
}
this.loader = new this.deps.Loader(
options.loader || this.defaults.loader
);
return undefined;
}
this.deps.Server.call(this, option('server'));
this.sandbox = new dep.Sandbox(option('sandbox'));
this.loader = new dep.Loader(option('loader'));
this._testsProcessor = [];

@@ -963,3 +1014,3 @@ this.testRunner = options.testRunner;

TestAgent.BrowserWorker.prototype = Object.create(
TestAgent.WebsocketClient.prototype
TestAgent.WebsocketClient.prototype
);

@@ -987,10 +1038,10 @@

*
* @param {Function} callback
* @param {Function} callback executed when sandbox is created.
*/
proto.createSandbox = function(callback){
proto.createSandbox = function createSandbox(callback) {
var self = this;
this.sandbox.run(function(){
this.sandbox.run(function onSandboxRun() {
self.loader.targetWindow = this;
if(callback){
if(!('require' in this)){
if (callback) {
if (!('require' in this)) {
this.require = self.loader.require.bind(self.loader);

@@ -1004,3 +1055,3 @@ }

proto._emitTestComplete = function(){
proto._emitTestComplete = function _emitTestComplete() {
var args = Array.prototype.slice.call(arguments);

@@ -1019,6 +1070,6 @@ args.unshift('run tests complete');

*
* @param {Function} callback
* @chainable
* @param {Function} callback reducer function.
* @return {Object} self.
*/
proto.addTestsProcessor = function(callback){
proto.addTestsProcessor = function addTestsProcessor(callback) {
this._testsProcessor.push(callback);

@@ -1032,5 +1083,5 @@ };

*
* @param {Array} tests
* @param {Array} tests list of tests to process.
*/
proto._processTests = function(tests){
proto._processTests = function _processTests(tests) {
var result = tests,

@@ -1041,3 +1092,3 @@ reducers = this._testsProcessor,

for(; i < length; i++){
for (; i < length; i++) {
result = reducers[i](result);

@@ -1052,13 +1103,13 @@ }

*
* @param {Array} tests
* @param {Array} tests list of tests to execute.
*/
proto.runTests = function(tests){
proto.runTests = function runTests(tests) {
var self = this,
done = this._emitTestComplete.bind(this);
if(!this.testRunner){
throw new Error("Worker must be provided a .testRunner method");
if (!this.testRunner) {
throw new Error('Worker must be provided a .testRunner method');
}
this.createSandbox(function(){
this.createSandbox(function createSandbox() {
self.testRunner(self, self._processTests(tests), done);

@@ -1072,3 +1123,3 @@ });

* Enhancement = function(options){}
* Enhancement.prototype.enhance = function(server){
* Enhancement.prototype.enhance = function enhance(server){
* //do stuff

@@ -1081,7 +1132,7 @@ * }

*
* @param {Object} enhancement
* @param {Object} options
* @chainable
* @param {Object} enhancement enhancement class.
* @param {Object} options options for class.
* @return {Object} self.
*/
proto.use = function(enhancement, options){
proto.use = function use(enhancement, options) {
new enhancement(options).enhance(this);

@@ -1093,12 +1144,14 @@

}(this));
(function(window){
function MochaDriver (options) {
(function(window) {
'use strict';
function MochaDriver(options) {
var key;
if(typeof(options) === 'undefined'){
if (typeof(options) === 'undefined') {
options = {};
}
for(key in options){
if(options.hasOwnProperty(key)){
for (key in options) {
if (options.hasOwnProperty(key)) {
this[key] = options[key];

@@ -1109,7 +1162,7 @@ }

MochaDriver.createMutliReporter = function(){
MochaDriver.createMutliReporter = function createMultiReporter() {
var reporters = Array.prototype.slice.call(arguments);
return function(runner){
reporters.forEach(function(Report){
return function(runner) {
reporters.forEach(function(Report) {
new Report(runner);

@@ -1125,3 +1178,3 @@ });

enhance: function(worker){
enhance: function enhance(worker) {
this.worker = worker;

@@ -1132,7 +1185,7 @@ worker.testRunner = this._testRunner.bind(this);

_onRunTests: function(data){
_onRunTests: function _onRunTests(data) {
this.worker.runTests(data.tests || []);
},
getReporter: function(box){
getReporter: function getReporter(box) {
var stream = TestAgent.Mocha.JsonStreamReporter,

@@ -1143,3 +1196,3 @@ self = this;

stream.send = function(line){
stream.send = function send(line) {
self.worker.send('test data', line);

@@ -1154,11 +1207,11 @@ };

_testRunner: function(worker, tests, done){
_testRunner: function _testRunner(worker, tests, done) {
var box = worker.sandbox.getWindow(),
self = this;
worker.loader.done(function(){
worker.loader.done(function onDone() {
box.mocha.run(done);
});
box.require(this.mochaUrl, function(){
box.require(this.mochaUrl, function onRequireMocha() {
//setup mocha

@@ -1173,3 +1226,3 @@ box.mocha.setup({

tests.forEach(function(test){
tests.forEach(function(test) {
box.require(test);

@@ -1184,10 +1237,10 @@ });

}(this));
(function(window){
(function(window) {
'use strict';
var Worker = window.TestAgent.BrowserWorker;
Worker.Config = function(options){
if(typeof(options) === 'undefined'){
Worker.Config = function Config(options) {
if (typeof(options) === 'undefined') {
options = {};

@@ -1200,10 +1253,10 @@ }

Worker.Config.prototype = {
enhance: function(worker){
enhance: function enhance(worker) {
worker.config = this._config.bind(this, worker, this.config);
},
_config: function(worker, config, callback){
config.load(function(data){
_config: function _config(worker, config, callback) {
config.load(function(data) {
worker.emit('config', data);
if(callback){
if (callback) {
callback(data);

@@ -1217,7 +1270,9 @@ }

}(this));
(function(window){
(function(window) {
'use strict';
var FORMAT_REGEX = /%([0-9])?s/g;
var FORMAT_REGEX = /%([0-9])?s/g,
Worker = window.TestAgent.BrowserWorker;
function format(){
function format() {
var i = 0,

@@ -1230,3 +1285,3 @@ str,

result = str.replace(FORMAT_REGEX, function(match, pos){
result = str.replace(FORMAT_REGEX, function(match, pos) {
var index = parseInt(pos || i++, 10);

@@ -1239,3 +1294,3 @@ return args[index];

function fragment(){
function fragment() {
var string = format.apply(this, arguments),

@@ -1248,6 +1303,6 @@ element = document.createElement('div');

var TestUi = window.TestAgent.BrowserWorker.TestUi = function(options){
var TestUi = Worker.TestUi = function TestUi(options) {
var selector;
if(typeof(options) === 'undefined'){
if (typeof(options) === 'undefined') {
options = {};

@@ -1269,3 +1324,3 @@ }

enhance: function(worker){
enhance: function enhance(worker) {
this.worker = worker;

@@ -1275,3 +1330,3 @@ this.worker.on('config', this.onConfig.bind(this));

onConfig: function(data){
onConfig: function onConfig(data) {
//purge elements

@@ -1284,3 +1339,3 @@ var elements = this.element.getElementsByTagName('*'),

for(; i < elements.length; i++){
for (; i < elements.length; i++) {
element = elements[i];

@@ -1292,3 +1347,3 @@ element.parentNode.removeChild(element);

data.tests.forEach(function(test){
data.tests.forEach(function(test) {
parent.appendChild(fragment(

@@ -1310,3 +1365,3 @@ templates.testItem,

initDomEvents: function(){
initDomEvents: function initDomEvents() {
var ul = this.element.querySelector('ul'),

@@ -1317,8 +1372,8 @@ button = this.element.querySelector('button'),

ul.addEventListener('click', function(e){
ul.addEventListener('click', function(e) {
var target = e.target,
url = target.getAttribute('data-url');
if(url){
if(self.queue[url]){
if (url) {
if (self.queue[url]) {
target.className = target.className.replace(activeClass, '');

@@ -1333,7 +1388,7 @@ delete self.queue[url];

button.addEventListener('click', function(){
button.addEventListener('click', function onTestClick() {
var tests = [], key;
for(key in self.queue){
if(self.queue.hasOwnProperty(key)){
for (key in self.queue) {
if (self.queue.hasOwnProperty(key)) {
tests.push(key);

@@ -1340,0 +1395,0 @@ }

@@ -1,3 +0,5 @@

(function(exports){
if(typeof(exports.TestAgent) === 'undefined'){
(function(exports) {
'use strict';
if (typeof(exports.TestAgent) === 'undefined') {
exports.TestAgent = {};

@@ -9,8 +11,8 @@ }

*
* @param {Object} list of events to add onto responder
* @param {Object} list of events to add onto responder.
*/
var Responder = exports.TestAgent.Responder = function(events){
var Responder = exports.TestAgent.Responder = function Responder(events) {
this.events = {};
if(typeof(events) !== 'undefined'){
if (typeof(events) !== 'undefined') {
this.addEventListener(events);

@@ -24,7 +26,7 @@ }

*
* @param {String} command command name
* @param {Object} data object to be sent over the wire
* @return {String} json object
* @param {String} command command name.
* @param {Object} data object to be sent over the wire.
* @return {String} json object.
*/
Responder.stringify = function(command, data){
Responder.stringify = function stringify(command, data) {
return JSON.stringify([command, data]);

@@ -36,10 +38,10 @@ };

*
* @param {String} json json string to translate
* @return {Object} object where .data is json data and .command is command name.
* @param {String} json json string to translate.
* @return {Object} ex: { event: 'test', data: {} }.
*/
Responder.parse = function(json){
Responder.parse = function parse(json) {
var data;
try {
data = (json.forEach)? json : JSON.parse(json);
} catch(e){
data = (json.forEach) ? json : JSON.parse(json);
} catch (e) {
throw new Error("Could not parse json: '" + json + '"');

@@ -58,3 +60,2 @@ }

*
* @property events
* @type Object

@@ -67,7 +68,9 @@ */

*
* @param {String} json
* @param {Object} params... option number of params to pass to emit
* @return {Object} result of WebSocketCommon.parse
* @param {String|Object} json data object to respond to.
* @param {String} json.event event to emit.
* @param {Object} json.data data to emit with event.
* @param {Object} [params] option number of params to pass to emit.
* @return {Object} result of WebSocketCommon.parse.
*/
respond: function(json){
respond: function respond(json) {
var event = Responder.parse(json),

@@ -90,11 +93,11 @@ args = Array.prototype.slice.call(arguments).slice(1);

*
* @param {String} type event name
* @param {String} callback
* @param {String} type event name.
* @param {String} callback event callback.
*/
addEventListener: function(type, callback){
addEventListener: function addEventListener(type, callback) {
var event;
if(typeof(callback) === 'undefined' && typeof(type) === 'object'){
for(event in type){
if(type.hasOwnProperty(event)){
if (typeof(callback) === 'undefined' && typeof(type) === 'object') {
for (event in type) {
if (type.hasOwnProperty(event)) {
this.addEventListener(event, type[event]);

@@ -107,3 +110,3 @@ }

if(!(type in this.events)){
if (!(type in this.events)) {
this.events[type] = [];

@@ -123,6 +126,6 @@ }

*
* @param {String} eventName
* @param {Arg...}
* @param {String} eventName name of the event to emit.
* @param {Object} [arguments] additional arguments to pass.
*/
emit: function(){
emit: function emit() {
var args = Array.prototype.slice.call(arguments),

@@ -133,6 +136,6 @@ event = args.shift(),

if(event in this.events){
if (event in this.events) {
eventList = this.events[event];
eventList.forEach(function(callback){
eventList.forEach(function(callback) {
callback.apply(self, args);

@@ -149,6 +152,6 @@ });

*
* @param {String} event
* @param {String} event event type to remove.
*/
removeAllEventListeners: function(name){
if(name in this.events){
removeAllEventListeners: function removeAllEventListeners(name) {
if (name in this.events) {
//reuse array

@@ -166,9 +169,9 @@ this.events[name].length = 0;

*
* @param {String} eventName event name
* @param {Function} callback
* @param {String} eventName event name.
* @param {Function} callback same instance of event handler.
*/
removeEventListener: function(name, callback){
removeEventListener: function removeEventListener(name, callback) {
var i, length, events;
if(!(name in this.events)){
if (!(name in this.events)) {
return false;

@@ -179,4 +182,4 @@ }

for(i = 0, length = events.length; i < length; i++){
if(events[i] && events[i] === callback){
for (i = 0, length = events.length; i < length; i++) {
if (events[i] && events[i] === callback) {
events.splice(i, 1);

@@ -195,14 +198,14 @@ return true;

}(
(typeof(window) === 'undefined')? module.exports : window
(typeof(window) === 'undefined') ? module.exports : window
));
(function(window){
(function(window) {
'use strict';
if(typeof(window.TestAgent) === 'undefined'){
if (typeof(window.TestAgent) === 'undefined') {
window.TestAgent = {};
}
var Loader = window.TestAgent.Loader = function(options){
var Loader = window.TestAgent.Loader = function Loader(options) {
var key;

@@ -214,8 +217,8 @@

if(typeof(options) === 'undefined'){
if (typeof(options) === 'undefined') {
options = {};
}
for(key in options){
if(options.hasOwnProperty(key)){
for (key in options) {
if (options.hasOwnProperty(key)) {
this[key] = options[key];

@@ -232,3 +235,2 @@ }

* @type String
* @property prefix
*/

@@ -241,3 +243,2 @@ prefix: '',

* @type Boolean
* @property bustCache
*/

@@ -250,3 +251,2 @@ bustCache: true,

* @private
* @property targetWindow
* @type Window

@@ -259,3 +259,2 @@ */

*
* @property _cached
* @type Object

@@ -266,7 +265,7 @@ * @private

get targetWindow(){
get targetWindow() {
return this._targetWindow;
},
set targetWindow(value){
set targetWindow(value) {
this._targetWindow = value;

@@ -279,8 +278,8 @@ this._cached = {};

*/
_decrementPending: function(){
if(this.pending > 0){
_decrementPending: function _decrementPending() {
if (this.pending > 0) {
this.pending--;
}
if(this.pending <= 0){
if (this.pending <= 0) {
this._fireCallbacks();

@@ -290,5 +289,5 @@ }

_fireCallbacks: function(){
_fireCallbacks: function _fireCallbacks() {
var callback;
while((callback = this.doneCallbacks.shift())){
while ((callback = this.doneCallbacks.shift())) {
callback();

@@ -299,8 +298,8 @@ }

/**
* Adds a done callback
* Adds a done callback.
* You may call this function multiple times.
*
*
* @param {Function} callback
* @param {Function} callback called after all scripts are loaded.
*/
done: function(callback){
done: function done(callback) {
this.doneCallbacks.push(callback);

@@ -315,6 +314,6 @@ return this;

*
* @param {String} url
* @param {String} callback
* @param {String} url location to load script from.
* @param {String} callback callback when script loading is complete.
*/
require: function(url, callback){
require: function require(url, callback) {
var prefix = this.prefix,

@@ -326,3 +325,3 @@ suffix = '',

if(url in this._cached){
if (url in this._cached) {
//url is cached we are good

@@ -332,4 +331,5 @@ return;

if(this.bustCache){
suffix = '?time=' + String(Date.now()) + '&rand=' + String(Math.random() * 1000);
if (this.bustCache) {
suffix = '?time=' + String(Date.now()) +
'&rand=' + String(Math.random() * 1000);
}

@@ -346,4 +346,4 @@

element.type = 'text/javascript';
element.onload = function(){
if(callback){
element.onload = function scriptOnLoad() {
if (callback) {
callback();

@@ -362,11 +362,11 @@ }

}(this));
(function(window){
(function(window) {
'use strict';
if(typeof(window.TestAgent) === 'undefined'){
if (typeof(window.TestAgent) === 'undefined') {
window.TestAgent = {};
}
var Sandbox = window.TestAgent.Sandbox = function(url){
var Sandbox = window.TestAgent.Sandbox = function Sandbox(url) {
this.url = url;

@@ -380,3 +380,2 @@ };

/**
* @property ready
* @type Boolean

@@ -391,3 +390,3 @@ *

*
* @return String
* @type String
*/

@@ -400,7 +399,7 @@ url: null,

*
* @return DOMElement
* @type DOMElement
*/
getElement: function(){
getElement: function getElement() {
var iframe;
if(!this._element){
if (!this._element) {
iframe = this._element = window.document.createElement('iframe');

@@ -412,3 +411,3 @@ iframe.src = this.url + '?time=' + String(Date.now());

run: function(callback){
run: function run(callback) {
//cleanup old sandboxes

@@ -422,3 +421,3 @@ this.destroy();

window.document.body.appendChild(element);
element.contentWindow.addEventListener('DOMContentLoaded', function(){
element.contentWindow.addEventListener('DOMContentLoaded', function() {
self.ready = true;

@@ -429,6 +428,6 @@ callback.call(this);

destroy: function(){
destroy: function destroy() {
var el;
if(!this.ready){
if (!this.ready) {
return false;

@@ -447,4 +446,4 @@ }

getWindow: function(){
if(!this.ready){
getWindow: function getWindow() {
if (!this.ready) {
return false;

@@ -459,15 +458,15 @@ }

}(this));
(function(window){
(function(window) {
'use strict';
if(typeof(window.TestAgent) === 'undefined'){
if (typeof(window.TestAgent) === 'undefined') {
window.TestAgent = {};
}
var Server = window.TestAgent.Config = function(options){
var Server = window.TestAgent.Config = function Config(options) {
var key;
for(key in options){
if(options.hasOwnProperty(key)){
for (key in options) {
if (options.hasOwnProperty(key)) {
this[key] = options[key];

@@ -483,4 +482,2 @@ }

*
*
* @property url
* @type String

@@ -493,5 +490,3 @@ */

*
*
* @type Boolean
* @property ready
*/

@@ -503,3 +498,2 @@ ready: false,

*
* @property resources
* @type Array

@@ -512,8 +506,8 @@ */

*
* @param Object xhr xhr object
* @param {Object} xhr xhr object.
*/
_parseResponse: function(xhr){
_parseResponse: function _parseResponse(xhr) {
var response;
if(xhr.responseText){
if (xhr.responseText) {
response = JSON.parse(xhr.responseText);

@@ -533,3 +527,3 @@ //only return files for now...

*/
load: function(callback){
load: function load(callback) {
var xhr = new XMLHttpRequest(),

@@ -540,5 +534,5 @@ self = this,

xhr.open('GET', this.url, true);
xhr.onreadystatechange = function(){
if(xhr.readyState === 4){
if(xhr.status === 200 || xhr.status === 0){
xhr.onreadystatechange = function onReadyStateChange() {
if (xhr.readyState === 4) {
if (xhr.status === 200 || xhr.status === 0) {
response = self._parseResponse(xhr);

@@ -551,3 +545,3 @@

} else {
throw new Error('Could not fetch tests from "' + self.url + '"');
throw new Error('Could not fetch tests from "' + self.url + '"');
}

@@ -568,11 +562,13 @@ } else {

//depends on TestAgent.Responder
(function(exports){
if(typeof(exports.TestAgent) === 'undefined'){
(function(exports) {
'use strict';
if (typeof(exports.TestAgent) === 'undefined') {
exports.TestAgent = {};
}
var Native, Responder;
var Native, Responder, TestAgent;
//Hack Arounds for node
if(typeof(window) === 'undefined'){
if (typeof(window) === 'undefined') {
Native = require('ws');

@@ -582,2 +578,3 @@ Responder = require('./responder').TestAgent.Responder;

TestAgent = exports.TestAgent;
Responder = Responder || TestAgent.Responder;

@@ -588,3 +585,2 @@ Native = (Native || WebSocket || MozWebSocket);

/**

@@ -599,14 +595,13 @@ * Creates a websocket client handles custom

*
* - retry (false by default)
* - retries (current number of retries)
* - retryLimit ( number of retries before error is thrown Infinity by default)
* - retryTimeout ( Time between retries 3000ms by default)
*
*
* @param {Object} options
* @param {Object} options retry options.
* @param {Boolean} option.retry (false by default).
* @param {Numeric} option.retryLimit \
* ( number of retries before error is thrown Infinity by default).
* @param {Numeric} option.retryTimeout \
* ( Time between retries 3000ms by default).
*/
var Client = exports.TestAgent.WebsocketClient = function(options){
var Client = TestAgent.WebsocketClient = function WebsocketClient(options) {
var key;
for(key in options){
if(options.hasOwnProperty(key)){
for (key in options) {
if (options.hasOwnProperty(key)) {
this[key] = options[key];

@@ -617,2 +612,4 @@ }

this.proxyEvents = ['open', 'close', 'message'];
this.on('close', this._incrementRetry.bind(this));

@@ -623,3 +620,3 @@ this.on('message', this._processMessage.bind(this));

Client.RetryError = function(){
Client.RetryError = function RetryError() {
Error.apply(this, arguments);

@@ -633,4 +630,2 @@ };

Client.prototype.proxyEvents = ['open', 'close', 'message'];
//Retry

@@ -642,7 +637,9 @@ Client.prototype.retry = false;

Client.prototype.start = function(){
Client.prototype.start = function start() {
var i, event;
if(this.retry && this.retries >= this.retryLimit){
throw new Client.RetryError('Retry limit has been reach retried ' + String(this.retries) + ' times');
if (this.retry && this.retries >= this.retryLimit) {
throw new Client.RetryError(
'Retry limit has been reach retried ' + String(this.retries) + ' times'
);
}

@@ -652,3 +649,3 @@

for(i = 0; i < this.proxyEvents.length; i++){
for (i = 0; i < this.proxyEvents.length; i++) {
event = this.proxyEvents[i];

@@ -664,11 +661,11 @@ this.socket.addEventListener(event, this._proxyEvent.bind(this, event));

*
* @param {String} event
* @param {String} data
* @param {String} event event to send.
* @param {String} data object to send to the server.
*/
Client.prototype.send = function(event, data){
Client.prototype.send = function send(event, data) {
this.socket.send(this.stringify(event, data));
};
Client.prototype._incrementRetry = function(){
if(this.retry){
Client.prototype._incrementRetry = function _incrementRetry() {
if (this.retry) {
this.retries++;

@@ -679,4 +676,4 @@ setTimeout(this.start.bind(this), this.retryTimeout);

Client.prototype._processMessage = function(message){
if(message.data){
Client.prototype._processMessage = function _processMessage(message) {
if (message.data) {
message = message.data;

@@ -687,7 +684,7 @@ }

Client.prototype._clearRetries = function(){
Client.prototype._clearRetries = function _clearRetries() {
this.retries = 0;
};
Client.prototype._proxyEvent = function(){
Client.prototype._proxyEvent = function _proxyEvent() {
this.emit.apply(this, arguments);

@@ -697,29 +694,61 @@ };

}(
(typeof(window) === 'undefined')? module.exports : window
(typeof(window) === 'undefined') ? module.exports : window
));
(function(window){
if(typeof(window.TestAgent) === 'undefined'){
/*(The MIT License)
Copyright (c) 20011-2012 TJ Holowaychuk <tj@vision-media.ca>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
(function(window) {
'use strict';
if (typeof(window.TestAgent) === 'undefined') {
window.TestAgent = {};
}
if(typeof(window.TestAgent.Mocha) === 'undefined'){
if (typeof(window.TestAgent.Mocha) === 'undefined') {
window.TestAgent.Mocha = {};
}
Base.slow = 75;
//Credit: mocha - https://github.com/visionmedia/mocha/blob/master/lib/reporters/base.js#L194
//Credit: mocha -
//https://github.com/visionmedia/mocha/blob/master/lib/reporters/base.js#L194
function Base(runner) {
var self = this
, stats = this.stats = { suites: 0, tests: 0, passes: 0, pending: 0, failures: 0 }
, failures = this.failures = [];
var self = this,
stats,
failures = this.failures = [];
stats = this.stats = {
suites: 0, tests: 0, passes: 0, pending: 0, failures: 0
};
if (!runner) return;
this.runner = runner;
runner.on('start', function(){
runner.on('start', function onStart() {
stats.start = new Date;
});
runner.on('suite', function(suite){
runner.on('suite', function onSuite(suite) {
stats.suites = stats.suites || 0;

@@ -729,3 +758,3 @@ suite.root || stats.suites++;

runner.on('test end', function(test){
runner.on('test end', function onTestEnd(test) {
stats.tests = stats.tests || 0;

@@ -735,11 +764,11 @@ stats.tests++;

runner.on('pass', function(test){
runner.on('pass', function onPass(test) {
stats.passes = stats.passes || 0;
var medium = Base.slow / 2;
test.speed = test.duration > Base.slow
? 'slow'
: test.duration > medium
? 'medium'
: 'fast';
//reformatted for gjslint
test.speed =
(test.duration > Base.slow) ?
'slow' : test.duration > medium ?
'medium' : 'fast';

@@ -749,3 +778,3 @@ stats.passes++;

runner.on('fail', function(test, err){
runner.on('fail', function onFail(test, err) {
stats.failures = stats.failures || 0;

@@ -757,3 +786,3 @@ stats.failures++;

runner.on('end', function(){
runner.on('end', function onEnd() {
stats.end = new Date;

@@ -763,3 +792,3 @@ stats.duration = new Date - stats.start;

runner.on('pending', function(){
runner.on('pending', function onPending() {
stats.pending++;

@@ -772,9 +801,10 @@ });

}(this));
(function(window){
(function(window) {
'use strict';
if(typeof(window.TestAgent) === 'undefined'){
if (typeof(window.TestAgent) === 'undefined') {
window.TestAgent = {};
}
if(typeof(window.TestAgent.Mocha) === 'undefined'){
if (typeof(window.TestAgent.Mocha) === 'undefined') {
window.TestAgent.Mocha = {};

@@ -788,3 +818,3 @@ }

MochaReporter.console = window.console;
MochaReporter.send = function(){};
MochaReporter.send = function mochaReporterSend() {};

@@ -803,3 +833,4 @@ //TODO -- Buffer console.log calls

MochaReporter.console.log = function(){
MochaReporter.console.log = function consoleLogShim() {
var args = Array.prototype.slice.call(arguments);
//real console log

@@ -810,7 +841,7 @@ log.apply(this, arguments);

var stack, messages = Array.prototype.slice.call(arguments).map(function(item){
if(!item){
var stack, messages = args.map(function(item) {
if (!item) {
return item;
}
return (item.toString)? item.toString() : item;
return (item.toString) ? item.toString() : item;
});

@@ -820,3 +851,3 @@

throw new Error();
} catch (e){
} catch (e) {
stack = e.stack;

@@ -826,3 +857,3 @@ }

//re-orgnaize the stack to exlude the above
stack = stack.split("\n").map(function(e){
stack = stack.split('\n').map(function(e) {
return e.trim().replace(/^at /, '');

@@ -832,39 +863,53 @@ });

stack.splice(0, 1);
stack = stack.join("\n");
stack = stack.join('\n');
//this is temp
MochaReporter.send(JSON.stringify(['log', {messages: messages, stack: stack}]));
MochaReporter.send(
JSON.stringify(['log', {messages: messages, stack: stack}])
);
};
runner.on('suite', function(suite){
runner.on('suite', function onSuite(suite) {
indentation++;
MochaReporter.send(JSON.stringify(['suite', jsonExport(suite, { indentation: indentation }) ]));
MochaReporter.send(
JSON.stringify(
['suite', jsonExport(suite, { indentation: indentation })]
)
);
});
runner.on('suite end', function(suite){
MochaReporter.send(JSON.stringify(['suite end', jsonExport(suite, { indentation: indentation }) ]));
runner.on('suite end', function onSuiteEnd(suite) {
MochaReporter.send(
JSON.stringify(
['suite end', jsonExport(suite, { indentation: indentation })]
)
);
indentation--;
});
runner.on('test', function(test){
MochaReporter.send(JSON.stringify(['test', jsonExport(test) ]));
runner.on('test', function onTest(test) {
MochaReporter.send(JSON.stringify(['test', jsonExport(test)]));
});
runner.on('test end', function(test){
MochaReporter.send(JSON.stringify(['test end', jsonExport(test) ]));
runner.on('test end', function onTestEnd(test) {
MochaReporter.send(JSON.stringify(['test end', jsonExport(test)]));
});
runner.on('start', function(){
MochaReporter.send( JSON.stringify(['start', { total: total }]) );
runner.on('start', function onStart() {
MochaReporter.send(JSON.stringify(['start', { total: total }]));
});
runner.on('pass', function(test){
runner.on('pass', function onPass(test) {
MochaReporter.send(JSON.stringify(['pass', jsonExport(test)]));
});
runner.on('fail', function(test, err){
MochaReporter.send(JSON.stringify(['fail', jsonExport(test, {err: jsonErrorExport(err) })]));
runner.on('fail', function onFail(test, err) {
MochaReporter.send(
JSON.stringify(
['fail', jsonExport(test, {err: jsonErrorExport(err) })]
)
);
});
runner.on('end', function(){
runner.on('end', function onEnd() {
MochaReporter.send(JSON.stringify(['end', self.stats]));

@@ -883,3 +928,3 @@ });

function jsonErrorExport(err){
function jsonErrorExport(err) {
var result = {};

@@ -900,8 +945,8 @@

exportKeys.forEach(function(key){
exportKeys.forEach(function(key) {
var value;
if(key in object){
if (key in object) {
value = object[key];
if(typeof(value) === 'function'){
if (typeof(value) === 'function') {
result[key] = object[key]();

@@ -914,5 +959,5 @@ } else {

if(typeof(additional) !== 'undefined'){
for(key in additional){
if(additional.hasOwnProperty(key)){
if (typeof(additional) !== 'undefined') {
for (key in additional) {
if (additional.hasOwnProperty(key)) {
result[key] = additional[key];

@@ -930,28 +975,34 @@ }

(function(window){
(function(window) {
'use strict';
if(typeof(window.TestAgent) === 'undefined'){
if (typeof(window.TestAgent) === 'undefined') {
window.TestAgent = {};
}
TestAgent.BrowserWorker = function(options){
TestAgent.BrowserWorker = function BrowserWorker(options) {
var self = this,
dep = this.deps;
if(typeof(options) === 'undefined'){
if (typeof(options) === 'undefined') {
options = {};
}
this.deps.Server.call(
this,
options.server || this.defaults.server
);
function option(name) {
if (name in options) {
return options[name];
}
this.sandbox = new this.deps.Sandbox(
options.sandbox || this.defaults.sandbox
);
if (name in self.defaults) {
return self.defaults[name];
}
this.loader = new this.deps.Loader(
options.loader || this.defaults.loader
);
return undefined;
}
this.deps.Server.call(this, option('server'));
this.sandbox = new dep.Sandbox(option('sandbox'));
this.loader = new dep.Loader(option('loader'));
this._testsProcessor = [];

@@ -963,3 +1014,3 @@ this.testRunner = options.testRunner;

TestAgent.BrowserWorker.prototype = Object.create(
TestAgent.WebsocketClient.prototype
TestAgent.WebsocketClient.prototype
);

@@ -987,10 +1038,10 @@

*
* @param {Function} callback
* @param {Function} callback executed when sandbox is created.
*/
proto.createSandbox = function(callback){
proto.createSandbox = function createSandbox(callback) {
var self = this;
this.sandbox.run(function(){
this.sandbox.run(function onSandboxRun() {
self.loader.targetWindow = this;
if(callback){
if(!('require' in this)){
if (callback) {
if (!('require' in this)) {
this.require = self.loader.require.bind(self.loader);

@@ -1004,3 +1055,3 @@ }

proto._emitTestComplete = function(){
proto._emitTestComplete = function _emitTestComplete() {
var args = Array.prototype.slice.call(arguments);

@@ -1019,6 +1070,6 @@ args.unshift('run tests complete');

*
* @param {Function} callback
* @chainable
* @param {Function} callback reducer function.
* @return {Object} self.
*/
proto.addTestsProcessor = function(callback){
proto.addTestsProcessor = function addTestsProcessor(callback) {
this._testsProcessor.push(callback);

@@ -1032,5 +1083,5 @@ };

*
* @param {Array} tests
* @param {Array} tests list of tests to process.
*/
proto._processTests = function(tests){
proto._processTests = function _processTests(tests) {
var result = tests,

@@ -1041,3 +1092,3 @@ reducers = this._testsProcessor,

for(; i < length; i++){
for (; i < length; i++) {
result = reducers[i](result);

@@ -1052,13 +1103,13 @@ }

*
* @param {Array} tests
* @param {Array} tests list of tests to execute.
*/
proto.runTests = function(tests){
proto.runTests = function runTests(tests) {
var self = this,
done = this._emitTestComplete.bind(this);
if(!this.testRunner){
throw new Error("Worker must be provided a .testRunner method");
if (!this.testRunner) {
throw new Error('Worker must be provided a .testRunner method');
}
this.createSandbox(function(){
this.createSandbox(function createSandbox() {
self.testRunner(self, self._processTests(tests), done);

@@ -1072,3 +1123,3 @@ });

* Enhancement = function(options){}
* Enhancement.prototype.enhance = function(server){
* Enhancement.prototype.enhance = function enhance(server){
* //do stuff

@@ -1081,7 +1132,7 @@ * }

*
* @param {Object} enhancement
* @param {Object} options
* @chainable
* @param {Object} enhancement enhancement class.
* @param {Object} options options for class.
* @return {Object} self.
*/
proto.use = function(enhancement, options){
proto.use = function use(enhancement, options) {
new enhancement(options).enhance(this);

@@ -1093,12 +1144,14 @@

}(this));
(function(window){
function MochaDriver (options) {
(function(window) {
'use strict';
function MochaDriver(options) {
var key;
if(typeof(options) === 'undefined'){
if (typeof(options) === 'undefined') {
options = {};
}
for(key in options){
if(options.hasOwnProperty(key)){
for (key in options) {
if (options.hasOwnProperty(key)) {
this[key] = options[key];

@@ -1109,7 +1162,7 @@ }

MochaDriver.createMutliReporter = function(){
MochaDriver.createMutliReporter = function createMultiReporter() {
var reporters = Array.prototype.slice.call(arguments);
return function(runner){
reporters.forEach(function(Report){
return function(runner) {
reporters.forEach(function(Report) {
new Report(runner);

@@ -1125,3 +1178,3 @@ });

enhance: function(worker){
enhance: function enhance(worker) {
this.worker = worker;

@@ -1132,7 +1185,7 @@ worker.testRunner = this._testRunner.bind(this);

_onRunTests: function(data){
_onRunTests: function _onRunTests(data) {
this.worker.runTests(data.tests || []);
},
getReporter: function(box){
getReporter: function getReporter(box) {
var stream = TestAgent.Mocha.JsonStreamReporter,

@@ -1143,3 +1196,3 @@ self = this;

stream.send = function(line){
stream.send = function send(line) {
self.worker.send('test data', line);

@@ -1154,11 +1207,11 @@ };

_testRunner: function(worker, tests, done){
_testRunner: function _testRunner(worker, tests, done) {
var box = worker.sandbox.getWindow(),
self = this;
worker.loader.done(function(){
worker.loader.done(function onDone() {
box.mocha.run(done);
});
box.require(this.mochaUrl, function(){
box.require(this.mochaUrl, function onRequireMocha() {
//setup mocha

@@ -1173,3 +1226,3 @@ box.mocha.setup({

tests.forEach(function(test){
tests.forEach(function(test) {
box.require(test);

@@ -1184,10 +1237,10 @@ });

}(this));
(function(window){
(function(window) {
'use strict';
var Worker = window.TestAgent.BrowserWorker;
Worker.Config = function(options){
if(typeof(options) === 'undefined'){
Worker.Config = function Config(options) {
if (typeof(options) === 'undefined') {
options = {};

@@ -1200,10 +1253,10 @@ }

Worker.Config.prototype = {
enhance: function(worker){
enhance: function enhance(worker) {
worker.config = this._config.bind(this, worker, this.config);
},
_config: function(worker, config, callback){
config.load(function(data){
_config: function _config(worker, config, callback) {
config.load(function(data) {
worker.emit('config', data);
if(callback){
if (callback) {
callback(data);

@@ -1217,7 +1270,9 @@ }

}(this));
(function(window){
(function(window) {
'use strict';
var FORMAT_REGEX = /%([0-9])?s/g;
var FORMAT_REGEX = /%([0-9])?s/g,
Worker = window.TestAgent.BrowserWorker;
function format(){
function format() {
var i = 0,

@@ -1230,3 +1285,3 @@ str,

result = str.replace(FORMAT_REGEX, function(match, pos){
result = str.replace(FORMAT_REGEX, function(match, pos) {
var index = parseInt(pos || i++, 10);

@@ -1239,3 +1294,3 @@ return args[index];

function fragment(){
function fragment() {
var string = format.apply(this, arguments),

@@ -1248,6 +1303,6 @@ element = document.createElement('div');

var TestUi = window.TestAgent.BrowserWorker.TestUi = function(options){
var TestUi = Worker.TestUi = function TestUi(options) {
var selector;
if(typeof(options) === 'undefined'){
if (typeof(options) === 'undefined') {
options = {};

@@ -1269,3 +1324,3 @@ }

enhance: function(worker){
enhance: function enhance(worker) {
this.worker = worker;

@@ -1275,3 +1330,3 @@ this.worker.on('config', this.onConfig.bind(this));

onConfig: function(data){
onConfig: function onConfig(data) {
//purge elements

@@ -1284,3 +1339,3 @@ var elements = this.element.getElementsByTagName('*'),

for(; i < elements.length; i++){
for (; i < elements.length; i++) {
element = elements[i];

@@ -1292,3 +1347,3 @@ element.parentNode.removeChild(element);

data.tests.forEach(function(test){
data.tests.forEach(function(test) {
parent.appendChild(fragment(

@@ -1310,3 +1365,3 @@ templates.testItem,

initDomEvents: function(){
initDomEvents: function initDomEvents() {
var ul = this.element.querySelector('ul'),

@@ -1317,8 +1372,8 @@ button = this.element.querySelector('button'),

ul.addEventListener('click', function(e){
ul.addEventListener('click', function(e) {
var target = e.target,
url = target.getAttribute('data-url');
if(url){
if(self.queue[url]){
if (url) {
if (self.queue[url]) {
target.className = target.className.replace(activeClass, '');

@@ -1333,7 +1388,7 @@ delete self.queue[url];

button.addEventListener('click', function(){
button.addEventListener('click', function onTestClick() {
var tests = [], key;
for(key in self.queue){
if(self.queue.hasOwnProperty(key)){
for (key in self.queue) {
if (self.queue.hasOwnProperty(key)) {
tests.push(key);

@@ -1340,0 +1395,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc