New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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.3.1 to 0.4.0

lib/test-agent/browser-worker/multi-domain-driver.js

15

HISTORY.md

@@ -0,1 +1,16 @@

# 0.4.0
- Ported all node/mocha/ scripts to test-agent/mocha/ they will now
run in both the browser and server
- Removed support for syntax error handling.
It has some bugs which made it unstable.
New test data based error handling will be introducted in v0.5
- Adding support for running tests across different domains via
iframes. This will eventually lead to multi worker support between
browsers.
- Fixed issue where websocket retry would not close the previous
socket cleanly causing events to occasionally fire twice.
# 0.3.1

@@ -2,0 +17,0 @@ - Add missing WebsocketClient.close method

3

lib/node/bin/test.js

@@ -62,3 +62,3 @@ var Client = require('../../node/client'),

client.mirrorServerEvents(['error', 'test data'], true);
client.mirrorServerEvents(['add test env', 'error', 'test data'], true);
client.send('queue tests', {files: files});

@@ -71,2 +71,3 @@ });

client.on('test runner end', function(runner){

@@ -73,0 +74,0 @@ var reporter = runner.getMochaReporter();

@@ -1,3 +0,2 @@

var TestAgent = require('../test-agent/websocket-client').TestAgent,
WSClient = TestAgent.WebsocketClient;
var WSClient = require('../test-agent/websocket-client');

@@ -4,0 +3,0 @@ /**

module.exports = exports = {
Reporter: require(__dirname + '/reporter'),
RunnerStreamProxy: require(__dirname + '/runner-stream-proxy')
Reporter: require('../../test-agent/mocha/reporter'),
RunnerStreamProxy: require('../../test-agent/mocha/runner-stream-proxy'),
ConcurrentReportingEvents: require(
'../../test-agent/mocha/concurrent-reporting-events'
)
};
module.exports = exports = {
Broadcast: require(__dirname + '/broadcast'),
MochaTestEvents: require(__dirname + '/mocha-test-events'),
Responder: require(__dirname + '/responder'),
Watcher: require(__dirname + '/watcher'),
RunnerGrowl: require(__dirname + '/runner-growl'),
QueueTests: require(__dirname + '/queue-tests'),
EventMirror: require(__dirname + '/event-mirror'),
Suite: require(__dirname + '/suite')
Broadcast: require('./broadcast'),
MochaTestEvents: require('../../test-agent/common/mocha-test-events'),
Responder: require('./responder'),
Watcher: require('./watcher'),
RunnerGrowl: require('./runner-growl'),
QueueTests: require('./queue-tests'),
EventMirror: require('./event-mirror'),
Suite: require('./suite')
};

@@ -20,3 +20,3 @@ /**

enhance: function enhance(server) {
server.on('test runner', this.reportOnTests.bind(this, server));
server.on('test runner end', this.reportOnTests.bind(this, server));
server.on('error', this.reportOnError.bind(this, server));

@@ -49,16 +49,14 @@ },

runner = proxy.runner,
reporter = proxy.reporter;
reporter = proxy.reporter,
stats = reporter.stats;
runner.on('end', function onEnd() {
var stats = reporter.stats;
if (stats.failures) {
var msg = stats.failures + ' of ' + runner.total + ' tests failed';
notify(msg, { title: 'Failed', image: images.fail });
} else {
notify(stats.passes + ' tests passed in ' + stats.duration + 'ms', {
title: 'Passed',
image: images.pass
});
}
});
if (stats.failures) {
var msg = stats.failures + ' of ' + runner.total + ' tests failed';
notify(msg, { title: 'Failed', image: images.fail });
} else {
notify(stats.passes + ' tests passed in ' + stats.duration + 'ms', {
title: 'Passed',
image: images.pass
});
}
}

@@ -65,0 +63,0 @@

var ws = require('websocket.io'),
fs = require('fs'),
fsPath = require('path'),
Responder = require(__dirname + '/../test-agent/responder').TestAgent.Responder,
Responder = require(__dirname + '/../test-agent/responder'),
vm = require('vm');

@@ -6,0 +6,0 @@

@@ -12,23 +12,11 @@ (function(window) {

TestAgent.Responder.call(this);
if (typeof(options) === 'undefined') {
options = {};
}
this.sandbox = new dep.Sandbox(options.sandbox);
this.loader = new dep.Loader(options.loader);
this.env = options.env || null;
function option(name) {
if (name in options) {
return options[name];
}
if (name in self.defaults) {
return self.defaults[name];
}
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 = [];

@@ -38,2 +26,10 @@ this.testRunner = options.testRunner;

this.sandbox.on('error', this.emit.bind(this, 'sandbox error'));
this.on('set env', function(env) {
self.env = env;
});
this.on('run tests', function(data) {
self.runTests(data.tests || []);
});
};

@@ -43,3 +39,3 @@

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

@@ -50,3 +46,2 @@

proto.deps = {
Server: TestAgent.WebsocketClient,
Sandbox: TestAgent.Sandbox,

@@ -57,9 +52,2 @@ Loader: TestAgent.Loader,

proto.defaults = {
server: {
retry: true,
url: 'ws://' + document.location.host.split(':')[0] + ':8789'
}
};
/**

@@ -90,2 +78,7 @@ * Create a new sandbox instance and set

this.emit.apply(this, args);
if (this.send) {
this.send.apply(this, args);
}
};

@@ -168,2 +161,10 @@

/**
* Emits 'start worker' event as a hook
* for other plugins.
*/
proto.start = function start() {
this.emit('worker start');
};
}(this));

@@ -36,9 +36,4 @@ (function(window) {

worker.testRunner = this._testRunner.bind(this);
worker.on('run tests', this._onRunTests.bind(this));
},
_onRunTests: function _onRunTests(data) {
this.worker.runTests(data.tests || []);
},
getReporter: function getReporter(box) {

@@ -54,2 +49,6 @@ var stream = TestAgent.Mocha.JsonStreamReporter,

if (this.worker.env) {
TestAgent.Mocha.JsonStreamReporter.testAgentEnvId = this.worker.env;
}
return MochaDriver.createMutliReporter(

@@ -56,0 +55,0 @@ TestAgent.Mocha.JsonStreamReporter,

@@ -93,3 +93,11 @@ (function(window) {

runner.on('start', function onStart() {
MochaReporter.send(JSON.stringify(['start', { total: total }]));
var obj = {
total: total
};
if (MochaReporter.testAgentEnvId) {
obj.testAgentEnvId = MochaReporter.testAgentEnvId;
}
MochaReporter.send(JSON.stringify(['start', obj]));
});

@@ -110,2 +118,6 @@

runner.on('end', function onEnd() {
if (MochaReporter.testAgentEnvId) {
self.stats.testAgentEnvId = MochaReporter.testAgentEnvId;
}
MochaReporter.send(JSON.stringify(['end', self.stats]));

@@ -129,2 +141,7 @@ });

var value;
if(object.fn) {
result.fn = object.fn.toString();
}
if (key in object) {

@@ -148,2 +165,7 @@ value = object[key];

}
if (MochaReporter.testAgentEnvId) {
result.testAgentEnvId = MochaReporter.testAgentEnvId;
}
return result;

@@ -150,0 +172,0 @@ }

@@ -19,3 +19,3 @@ (function(exports) {

if (!this.has(object))
this.length += 1;
this.length += 1;

@@ -22,0 +22,0 @@ this._items[details.key] = details.value;

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

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

@@ -13,4 +17,4 @@

*/
var Responder = exports.TestAgent.Responder = function Responder(events) {
this.events = {};
function Responder(events) {
this._$events = {};

@@ -60,3 +64,3 @@ if (typeof(events) !== 'undefined') {

*/
events: null,
_$events: null,

@@ -106,7 +110,7 @@ /**

if (!(type in this.events)) {
this.events[type] = [];
if (!(type in this._$events)) {
this._$events[type] = [];
}
this.events[type].push(callback);
this._$events[type].push(callback);

@@ -127,4 +131,4 @@ return this;

function onceCb() {
self.removeEventListener(type, onceCb);
callback.apply(this, arguments);
self.removeEventListener(type, onceCb);
}

@@ -152,4 +156,4 @@

if (event in this.events) {
eventList = this.events[event];
if (event in this._$events) {
eventList = this._$events[event];

@@ -171,5 +175,5 @@ eventList.forEach(function(callback) {

removeAllEventListeners: function removeAllEventListeners(name) {
if (name in this.events) {
if (name in this._$events) {
//reuse array
this.events[name].length = 0;
this._$events[name].length = 0;
}

@@ -191,7 +195,7 @@

if (!(name in this.events)) {
if (!(name in this._$events)) {
return false;
}
events = this.events[name];
events = this._$events[name];

@@ -212,5 +216,9 @@ for (i = 0, length = events.length; i < length; i++) {

}(
(typeof(window) === 'undefined') ? module.exports : window
));
if (isNode) {
module.exports = Responder;
} else {
window.TestAgent.Responder = Responder;
}
}());
//depends on TestAgent.Responder
(function(exports) {
(function() {
'use strict';
if (typeof(exports.TestAgent) === 'undefined') {
exports.TestAgent = {};
}
var isNode = typeof(window) === 'undefined',
Native,
Responder;
var Native, Responder, TestAgent;
if (!isNode) {
if (typeof(window.TestAgent) === 'undefined') {
window.TestAgent = {};
}
//Hack Arounds for node
if (typeof(window) === 'undefined') {
Native = (Native || WebSocket || MozWebSocket);
Responder = TestAgent.Responder;
} else {
Native = require('ws');
Responder = require('./responder').TestAgent.Responder;
Responder = require('./responder');
}
TestAgent = exports.TestAgent;
Responder = Responder || TestAgent.Responder;
Native = (Native || WebSocket || MozWebSocket);
//end

@@ -39,3 +39,3 @@

*/
var Client = TestAgent.WebsocketClient = function WebsocketClient(options) {
function Client(options) {
var key;

@@ -50,2 +50,3 @@ for (key in options) {

this.proxyEvents = ['open', 'close', 'message'];
this._proxiedEvents = {};

@@ -73,3 +74,3 @@ this.on('close', this._incrementRetry.bind(this));

Client.prototype.start = function start() {
var i, event;
var i, event, fn;

@@ -82,2 +83,6 @@ if (this.retry && this.retries >= this.retryLimit) {

if (this.socket) {
this.close();
}
this.socket = new this.Native(this.url);

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

event = this.proxyEvents[i];
this.socket.addEventListener(event, this._proxyEvent.bind(this, event));
fn = this._proxiedEvents[event] = this._proxyEvent.bind(this, event);
this.socket.addEventListener(event, fn, false);
}

@@ -108,2 +114,8 @@

Client.prototype.close = function close(event, data) {
var event;
for (event in this._proxiedEvents) {
this.socket.removeEventListener(event, this._proxiedEvents[event], false);
}
this.socket.close();

@@ -134,4 +146,8 @@ };

}(
(typeof(window) === 'undefined') ? module.exports : window
));
if (isNode) {
module.exports = Client;
} else {
window.TestAgent.WebsocketClient = Client;
}
}());
{
"name": "test-agent",
"version": "0.3.1",
"version": "0.4.0",
"author": "James Lal",

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

@@ -8,4 +8,8 @@ {

"/test/test-agent/browser-worker/mocha-driver-test.js",
"/test/test-agent/browser-worker/multi-domain-driver-test.js",
"/test/test-agent/browser-worker/post-message-test.js",
"/test/test-agent/browser-worker/test-ui-test.js",
"/test/test-agent/browser-worker/websocket-test.js",
"/test/test-agent/browser-worker-test.js",
"/test/test-agent/common/mocha-test-events-test.js",
"/test/test-agent/config-test.js",

@@ -15,2 +19,5 @@ "/test/test-agent/export-error-test.js",

"/test/test-agent/loader-test.js",
"/test/test-agent/mocha/concurrent-reporting-events-test.js",
"/test/test-agent/mocha/reporter-test.js",
"/test/test-agent/mocha/runner-stream-proxy-test.js",
"/test/test-agent/pool-base-test.js",

@@ -17,0 +24,0 @@ "/test/test-agent/responder-test.js",

@@ -5,6 +5,6 @@ (function(window) {

worker = new TestAgent.BrowserWorker({
sandbox: '/test-agent/sandbox.html'
});
worker = new TestAgent.BrowserWorker();
worker.use(TestAgent.BrowserWorker.Websocket);
worker.use(TestAgent.BrowserWorker.Config, {

@@ -14,5 +14,13 @@ url: '/test-agent/config.json'

worker.use(TestAgent.BrowserWorker.MochaDriver, {
mochaUrl: '/mocha/mocha.js',
testHelperUrl: '/test/helper.js'
worker.use(TestAgent.BrowserWorker.MultiDomainDriver, {
groupTestsByDomain: function(test) {
var result = {
domain: './proxy.html',
test: test,
env: 'TA'
};
return result;
}
});

@@ -23,4 +31,11 @@

worker.use(TestAgent.Common.MochaTestEvents, {
defaultMochaReporter: 'HTML'
});
worker.on({
'run tests': function() {
},
'sandbox': function() {

@@ -27,0 +42,0 @@ worker.loader.require('/vendor/expect.js');

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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